c# - Handling JSONP response in windows application -


i have asp.net web api 2 project that's been set return jsonp (using asp.net web api contrib repo github (https://github.com/webapicontrib)), looks fine , dandy in web application when consuming api via jquery.

however, there's windows application needs access same data, i'm quite @ loss on how process response in c# class.

i have code, worked nicely (using json.net) when api returned plain json:

    public list<dropitem> getavailabledomains()     {         string jsondata = null;          using (webclient wc = new webclient())         {             jsondata = wc.downloadstring("http://foo.bar/api/core/getavailabledomains");         }          return jsonconvert.deserializeobject<list<dropitem>>(jsondata);     } 

however, using jsonp doesn't recognize response data due overhead stuff callback functions etc in response.

is there way of handling this?

this did trick

    public static void registerformatters(mediatypeformattercollection formatters)     {         var jsonp = new jsonpmediatypeformatter(formatters.jsonformatter);         jsonp.mediatypemappings.add(new querystringmapping("type", "jsonp", "application/json"));          globalconfiguration.configuration.formatters.add(jsonp);         globalconfiguration.configuration.formatters.jsonformatter.mediatypemappings.add(new querystringmapping("type", "json", "application/json"));     } 

Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -