C# 如何将WCF服务从SOAP转换为REST?
我是WCF的新手,对此我有疑问 在阅读了一些文章之后,我发现在web.config文件中,如果我将端点绑定从basicHttpBinding更改为webHttpBinding,并将httpGetEnabled从true更改为false,那么它将使用RESTC# 如何将WCF服务从SOAP转换为REST?,c#,wcf,rest,soap,C#,Wcf,Rest,Soap,我是WCF的新手,对此我有疑问 在阅读了一些文章之后,我发现在web.config文件中,如果我将端点绑定从basicHttpBinding更改为webHttpBinding,并将httpGetEnabled从true更改为false,那么它将使用REST 我的问题是,这是制作服务SOAP或REST所需要更改的唯一两件事吗?或者我是否需要更改/添加任何其他内容 您可以在两个不同的端点中公开服务。SOAP可以使用支持SOAP的绑定,例如basicHttpBinding,RESTful可以使用web
我的问题是,这是制作服务SOAP或REST所需要更改的唯一两件事吗?或者我是否需要更改/添加任何其他内容 您可以在两个不同的端点中公开服务。
SOAP
可以使用支持SOAP
的绑定,例如basicHttpBinding
,REST
ful可以使用webHttpBinding
。我假设您的REST
服务将在JSON
中,在这种情况下,您需要使用以下行为配置配置两个端点
<endpointBehaviors>
<behavior name="jsonBehavior">
<enableWebScript/>
</behavior>
</endpointBehaviors>
添加服务引用后,SOAP服务的SOAP请求客户端终结点配置
<client>
<endpoint address="http://www.example.com/soap" binding="basicHttpBinding"
contract="ITestService" name="BasicHttpBinding_ITestService" />
</client>
那么httpgetenabled如何将其设置为true或false呢?我也需要改变这个,对吗?
public interface ITestService
{
[OperationContract]
[WebGet]
string HelloWorld(string text)
}
<client>
<endpoint address="http://www.example.com/soap" binding="basicHttpBinding"
contract="ITestService" name="BasicHttpBinding_ITestService" />
</client>
TestServiceClient client = new TestServiceClient();
client.GetAccount("A123");