WCF服务上的多个绑定

WCF服务上的多个绑定,wcf,wcf-binding,wcf-rest,Wcf,Wcf Binding,Wcf Rest,我想在IIS 7.5中托管一个WCF 4.0服务,并能够使用basicHttpBinding和webHttpBinding进行RESTful绑定 我需要能够像这样访问它: (其余) 也像这样: (基本HTTP) 到目前为止,我的Web.config中有以下内容: <?xml version="1.0" encoding="UTF-8"?> <configuration> <system.serviceModel> <behaviors>

我想在IIS 7.5中托管一个WCF 4.0服务,并能够使用
basicHttpBinding
webHttpBinding
进行RESTful绑定

我需要能够像这样访问它:

(其余)

也像这样:

(基本HTTP)

到目前为止,我的Web.config中有以下内容:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.serviceModel>
    <behaviors>
      <endpointBehaviors>
        <behavior name="json">
          <webHttp defaultOutgoingResponseFormat="Json" helpEnabled="true" />
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <services>
      <service name="SAIF.Services.WCF.Services.CustomerContactService">
        <endpoint address="CustomerContact" behaviorConfiguration="json" binding="webHttpBinding" contract="SAIF.Services.WCF.Contracts.ICustomerContactService" />
        <endpoint address="CustomerContact.svc" binding="basicHttpBinding" contract="SAIF.Services.WCF.Contracts.ICustomerContactService" />
      </service>
      <service name="SAIF.Services.WCF.Services.OnlineLoginService">
        <endpoint address="OnlineLogin" binding="basicHttpBinding" contract="SAIF.Services.WCF.Contracts.IOnlineLoginService" />
      </service>
    </services>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true">
      <serviceActivations>
        <add relativeAddress="CustomerContact.svc" service="SAIF.Services.WCF.Services.CustomerContactService" />
      </serviceActivations>
    </serviceHostingEnvironment>
  </system.serviceModel>
</configuration>
我用以下内容装饰了服务:

我的服务界面是用
UriTemplates

似乎无法通过RESTful和SOAP访问它们

谢谢!
Sam

只需使用OperationContract和WebGet属性来修饰您的方法。现在将以下内容添加到servers web.config中的system.serviceModel元素中

    <standardEndpoints>
          <webHttpEndpoint>
            <!-- 
                Configure the WCF REST service base address via the global.asax.cs file and the default endpoint 
                via the attributes on the <standardEndpoint> element below
            -->
            <standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true">
              <readerQuotas maxStringContentLength="5242880" maxArrayLength="16384" maxBytesPerRead="4096" />
            </standardEndpoint>
          </webHttpEndpoint>
        </standardEndpoints>
现在,完成上述操作后,您应该能够通过SOAP和REST访问相同的服务,URL如下所示:

肥皂-->

休息-->


现在在IE中浏览到您的服务,当您浏览到.svc文件时,您应该会看到SOAP服务器,当您浏览到rest URL时,您应该会看到浏览器中出现的包含json格式响应的文件的xml。

为什么它必须是相同的基本URL?为什么不
http://server/wcf/restservice/method/parameters
http://server/wcf/soapservice/service.svc
?@JohnSaunders-我们将提供20-25个WCF服务,因此我考虑采用这种命名约定,以便于维护,但我想可能会有点不同。我的建议是允许使用“soapservice”和“restservice”是IIS中独立的应用程序。“restservice”将是到路由的restful URL映射的开始。您使用的是哪个.NET版本?是.NET 4.0吗
    <standardEndpoints>
          <webHttpEndpoint>
            <!-- 
                Configure the WCF REST service base address via the global.asax.cs file and the default endpoint 
                via the attributes on the <standardEndpoint> element below
            -->
            <standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true">
              <readerQuotas maxStringContentLength="5242880" maxArrayLength="16384" maxBytesPerRead="4096" />
            </standardEndpoint>
          </webHttpEndpoint>
        </standardEndpoints>
Routing.RouteTable.Routes.Add(New ServiceRoute("CustomerContactService", New WebServiceHostFactory, typeof(SAIF.Services.WCF.Services.CustomerContactService)));