Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/298.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服务设置为REST&;这边用肥皂?_C#_Wcf_Rest_Soap - Fatal编程技术网

C# 是否可以将WCF服务设置为REST&;这边用肥皂?

C# 是否可以将WCF服务设置为REST&;这边用肥皂?,c#,wcf,rest,soap,C#,Wcf,Rest,Soap,我试着在一个屋檐下把肥皂和休息结合起来,做一些修改。但我不知道这是否可能。下面是我的代码,它过去只在REST时工作,但由于我尝试将额外的web服务添加为SOAP(使用配置),所以它不工作。不知道如何配置它 我有以下接口: [ServiceContract] public interface IVLSContentServiceREST { [OperationContract] [WebGet] string EchoWithGet(string s); [Op

我试着在一个屋檐下把肥皂和休息结合起来,做一些修改。但我不知道这是否可能。下面是我的代码,它过去只在REST时工作,但由于我尝试将额外的web服务添加为SOAP(使用配置),所以它不工作。不知道如何配置它

我有以下接口:

[ServiceContract]
public interface IVLSContentServiceREST
{
    [OperationContract]
    [WebGet]
    string EchoWithGet(string s);

    [OperationContract]
    [WebInvoke]
    string EchoWithPost(string s);

}

[ServiceContract]
public interface IVLSContentServiceSOAP
{
    [OperationContract]
    [WebGet]
    string EchoWithGet(string s);

    [OperationContract]
    [WebInvoke]
    string EchoWithPost(string s);
}
然后我有一个名为VLSContentService.svc的文件,其中包含:

<%@ ServiceHost Language="C#" Debug="true" Service="VLSContentService" CodeBehind="VLSContentService.svc.cs" %>
以及配置:

<?xml version="1.0"?>
<configuration>

    <system.web>
        <compilation debug="true" targetFramework="4.0" />
    </system.web>

  <system.serviceModel>

    <!---Add the service-->
    <services>
      <service behaviorConfiguration="VLSContentServiceBehaviour" name="VLSContentService">
        <endpoint address="rest" behaviorConfiguration="VLSContentServiceEndpointBehaviour" binding="webHttpBinding" contract="IVLSContentServiceREST"/>
        <endpoint address="soap" behaviorConfiguration="VLSContentServiceEndpointBehaviour" binding="basicHttpBinding" contract="IVLSContentServiceSOAP"/>
      </service>
    </services>

    <!---Add the behaviours-->
    <behaviors>
      <serviceBehaviors>
        <behavior name="VLSContentServiceBehaviour">
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
      </serviceBehaviors>


      <!---Add the behaviours-->
      <endpointBehaviors>
        <behavior name="VLSContentServiceEndpointBehaviour">
          <webHttp/>
        </behavior>
      </endpointBehaviors>
    </behaviors>

  </system.serviceModel>
</configuration>

您不需要两个版本的契约,只需使用不同的绑定在两个端点承载相同的契约即可

 <services>
  <service behaviorConfiguration="VLSContentServiceBehaviour" name="VLSContentService">
    <endpoint address="rest" behaviorConfiguration="VLSContentServiceEndpointBehaviour" binding="webHttpBinding" contract="IVLSContentService"/>
    <endpoint address="soap" behaviorConfiguration="VLSContentServiceEndpointBehaviour" binding="basicHttpBinding" contract="IVLSContentService"/>
  </service>
</services>

您不需要两个版本的契约,只需使用不同的绑定在两个端点承载相同的契约即可

 <services>
  <service behaviorConfiguration="VLSContentServiceBehaviour" name="VLSContentService">
    <endpoint address="rest" behaviorConfiguration="VLSContentServiceEndpointBehaviour" binding="webHttpBinding" contract="IVLSContentService"/>
    <endpoint address="soap" behaviorConfiguration="VLSContentServiceEndpointBehaviour" binding="basicHttpBinding" contract="IVLSContentService"/>
  </service>
</services>


是的,这是可能的,我就是这样做的。我稍后会发布我的解决方案。是的,这是可能的,我就是这样做的。我稍后会发布我的解决方案。