天天看點

WCF 添加 RESTful 支援,适用于 IIS、Winform、cmd 宿主

You can expose the service in two different endpoints. the SOAP one can use the binding that support SOAP e.g. basicHttpBinding, the RESTful one can use the webHttpBinding. I assume your REST service will be in JSON, in that case, you need to configure the two endpoints with the following behaviour configuration

  An example of endpoint configuration in your scenario is

  

so, the service will be available at

<a href="http://www.example.com/soap">http://www.example.com/soap</a>

<a href="http://www.example.com/json">http://www.example.com/json</a>

Apply [WebGet] to the operation contract to make it RESTful. e.g.

Note, if the REST service is not in JSON, parameters of the operations can not contain complex type.

For plain old XML as return format, this is an example that would work both for SOAP and XML

  POX behavior for REST Plain Old XML

  Endpoints

Service will be available at

<a href="http://www.example.com/xml">http://www.example.com/xml</a>

REST request try it in browser,

<a href="http://www.example.com/xml/accounts/A123">http://www.example.com/xml/accounts/A123</a>

SOAP request client endpoint configuration for SOAP service after adding the service reference,

  in C#

  Another way of doing it is to expose two different service contract and each one with specific configuration. This may generate some duplicates at code level, however at the end of the day, you want to make it working.