如何以推荐的方式启用WCF SOAP和REST。 [英] How to enable both WCF SOAP and REST in recommanded way.?

查看:65
本文介绍了如何以推荐的方式启用WCF SOAP和REST。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨朋友们,



如何以推荐的方式启用WCF SOAP和REST。?

如果你有经验的人在那些chalenging区域

请回复我的想法,并提供我链接,如果你有。





祝福!!

Ramesh

Hi Friends,

How to enable both WCF SOAP and REST in recommanded way.?
If you people who have a experience on those chalenging areas
please revert back to me with your thoughts and provide me link if you have.


Best Wishes!!
Ramesh

推荐答案

您可以在两个不同的端点公开服务。 SOAP可以使用支持SOAP的绑定,例如basicHttpBinding,RESTful可以使用webHttpBinding。我假设您的REST服务将使用JSON,在这种情况下,您需要使用以下行为配置配置两个端点

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
<endpointBehaviors>
  <behavior name="jsonBehavior">
    <enableWebScript/>
  </behavior>
</endpointBehaviors>



您的方案中的端点配置示例是


An example of endpoint configuration in your scenario is

<services>
  <service name="TestService">
    <endpoint address="soap" binding="basicHttpBinding" contract="ITestService"/>
    <endpoint address="json" binding="webHttpBinding"  behaviorConfiguration="jsonBehavior" contract="ITestService"/>
  </service>
</services>



因此,该服务将在

http://www.example.com/soap

http://www.example.com/json



将[WebGet]应用于操作合同以使其成为RESTful。例如


So, the service will be available at
http://www.example.com/soap
http://www.example.com/json

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

public interface ITestService
{
   [OperationContract]
   [WebGet]
   string HelloWorld(string text)
}



注意,如果REST服务不在JSON中,则操作的参数不能包含复杂类型。


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


这篇关于如何以推荐的方式启用WCF SOAP和REST。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆