tags:

views:

31

answers:

2

I'm wondering if I can use WCF so that the client can set the appropriate binding by just changing the URL. Some examples:

URL: http://yourhost.com/orders.json?op=getall
Description: get all orders as JSON.

URL: http://yourhost.com/orders.xml?op=getall
Description: get all orders as XML.

URL: http://yourhost.com/orders.soap?op=getall
Description: get all orders as SOAP that's WSI compliant.

URL: http://yourhost.com/orders.soap?wsdl=yes
Description: shows the WSDL of the SOAP service.

This strategy is somewhat similar to what Twitter had used in it's API.

Is this possible with WCF?

A: 

You can expose WCF services as REST, SOAP or JSON endpoints.

Here's a few links I found doing a quick google search.

JSON LINK

REST LINK

SOAP is the default for WCF.

You can supply different addresses in your endpoint for each, if that is what you are trying to accomplish.

Just use put something like:

<endpoint address="JSON" ...
<endpoint address="REST" ...

and it they can be accessed as http://yourdomion/yourservice/JSON or /REST

To get your wsdl for the SOAP service, just access the service URL?wsdl (assuming you have metadata gethttpEnabled or a Mex endpoint available).

There is no WSDL for REST or JSON, to access your proxy for JSON put a /js on the end of your JSON url, example http://yourdomain/yourservice/JSON/js

This link explains more about exposing a REST services functionality via WSDL, if you wanted to.

Hope this helps,

CkH
+1  A: 

Rather than have the user specify it via the URL, have them specify: - the request via the content-type header - the response via the accept header.

Wcf 4 will automatically serialize/deserialize as requested.

http://msdn.microsoft.com/en-us/library/ee476510.aspx

Now, you just have one URL that they interact with, and let Wcf handle the rest based on the incoming headers.

You would need a separate endpoint for the SOAP stuff, though.

Jay Allard