다음을 통해 공유


The webHttpBinding Magic (another Spotify WCF Client)

One of the most common programming tasks today is to manage a series of WebRequests, mostly HttpRequests.

In .Net we have been using the system.net.httpwebrequest.aspx  class and friends like system.net.webclient.aspx to manage the URL I/O.

If you need a “C# parameter to queryString converter” you have to build your own, and so on…

Lastly I’ve playing with the WCF webHttpBinding way to build REST clients in .NET 4.0, here is the result:

I need to call the Spotify Metadata API: https://ws.spotify.com/search/1/track?q=foo&page=2[ /search/track/ doc ] and parse a response like

image

So I create a basic XmlSerializer classes to handle the XML response, and the interface with WebGet decorated methods

image

image

 

And that’s it, well just one point, how to set the base url for the operation:

 

image  

 

 

so the interface implementation becomes like:

 

image

 

And now you can call the SearchTrack as:

image

have fun !!