Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/262.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何将WCF服务从SOAP转换为REST?_C#_Wcf_Rest_Soap - Fatal编程技术网

C# 如何将WCF服务从SOAP转换为REST?

C# 如何将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

我是WCF的新手,对此我有疑问

在阅读了一些文章之后,我发现在web.config文件中,如果我将端点绑定从basicHttpBinding更改为webHttpBinding,并将httpGetEnabled从true更改为false,那么它将使用REST


我的问题是,这是制作服务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");