IIS 7.5中具有REST / SOAP端点的WCF 4服务

问题描述

|| 您好,感谢您的阅读。 我正在尝试使服务托管在IIS 7.5中,该服务具有多个终结点。 我感觉问题出在我的web.config中,但是我将在这里发布我的服务代码。没有接口文件,因为我正在使用WCF 4的较新功能,所以也没有.svc文件。 据我了解,所有路由都使用RouteTable功能在Global.asax.cs中处理。 无论如何,进入代码/配置-
[ServiceContract]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
// NOTE: If the service is renamed,remember to update the global.asax.cs file
public class Service1
{
    // Todo: Implement the collection resource that will contain the SampleItem instances

    [WebGet(UriTemplate = \"HelloWorld\")]
    public string HelloWorld()
    {
        // Todo: Replace the current implementation to return a collection of SampleItem instances
        return \"Hello World!\";
    }
}
现在,我需要进行具有我认为的更改的配置(我不确定是否需要保留standardEndpoints块,但是无论是否保留它,我仍然会收到错误消息。-
<services>
  <service name=\"AiSynthDocSvc.Service1\" behaviorConfiguration=\"HttpGetMetadata\">
    <endpoint name=\"rest\"
              address=\"\"
              binding=\"webHttpBinding\"
              contract=\"AiSynthDocSvc.Service1\"
              behaviorConfiguration=\"REST\" />
    <endpoint name=\"soap\"
              address=\"soap\"
              binding=\"basicHttpBinding\"
              contract=\"AiSynthDocSvc.Service1\" />
    <endpoint name=\"mex\"
              address=\"mex\"
              binding=\"mexHttpBinding\"
              contract=\"IMetadataExchange\" />
  </service>
</services>    

<behaviors>
  <endpointBehaviors>
    <behavior name=\"REST\">
      <webHttp/>
    </behavior>
  </endpointBehaviors>
  <serviceBehaviors>
    <behavior name=\"HttpGetMetadata\">
      <serviceMetadata httpGetEnabled=\"true\" />
    </behavior>
  </serviceBehaviors>
</behaviors>

<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\"/>
  </webHttpEndpoint>
</standardEndpoints>
Global.asax.cs文件被保留。 再次,我很确定它与我的配置有关。当我尝试访问定义的任何端点时遇到的错误是-   \'\'处的端点没有带有None MessageVersion的绑定。 \'System.ServiceModel.Description.WebHttpBehavior \'仅用于WebHttpBinding或类似的绑定。 有人对此有任何想法吗? 谢谢, 扎卡里·卡特(Zachary Carter)     

解决方法

好吧,我试图复制您的东西-对我来说就像一个魅力:-) 我使用了您的服务班级-没有变化 我在
global.asax.cs
中使用了您的
RegisterRoutes
电话 当我从Visual Studio中启动Web应用程序时,我会在s4ѭ上看到Cassini(内置的Web服务器)-这可能对您有所警惕。 现在,我可以使用第二个浏览器窗口轻松地导航到那里,并且我确实对此URL得到了简单的响应:
http://localhost:3131/Service1/HelloWorld
+--------------------+ 
 from Cassini
                     +--------+
                   name (first param) in ServiceRoute registration
                              +-----------+
                               from your URI template on the WebGet attribute
相同的网址对您有用吗? 更新:这是我的配置-我可以使用REST在浏览器中连接到
http://localhost:3131/Service1/HelloWorld
,并且可以使用WCF测试客户端连接到
http://localhost:3131/Service1/soap
进行SOAP调用(我的
Service1
居住在
RestWebApp
命名空间中-因此我的服务和合同名称与您的名称有所不同-但除此之外,我相信它与您自己的配置相同):
  <system.serviceModel>
    <serviceHostingEnvironment     
        aspNetCompatibilityEnabled=\"true\" />
    <services>
      <service name=\"RestWebApp.Service1\" behaviorConfiguration=\"Meta\">
        <endpoint name=\"rest\" 
                  address=\"\"
                  binding=\"webHttpBinding\"
                  contract=\"RestWebApp.Service1\"
                  behaviorConfiguration=\"REST\" />
        <endpoint name=\"SOAP\"
            address=\"soap\"
            binding=\"basicHttpBinding\"
            contract=\"RestWebApp.Service1\" />
        <endpoint name=\"mex\"
            address=\"mex\"
            binding=\"mexHttpBinding\"
            contract=\"IMetadataExchange\" />
      </service>
    </services>
    <behaviors>
      <endpointBehaviors>
        <behavior name=\"REST\">
          <webHttp/>
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior name=\"Meta\">
          <serviceMetadata httpGetEnabled=\"true\" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <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\"/>
      </webHttpEndpoint>
    </standardEndpoints>
  </system.serviceModel>
    ,谢谢,这对我有很大帮助。 在我的情况下,问题是我配置了包含webHttp的默认行为。在给它起名字= \“ REST \”并设置我的webHttpBinding端点behaviourConfiguration = \“ REST \”之后,我没有更多的错误了。
<system.serviceModel>
<bindings>
  <customBinding>
    <binding name=\"CustomBinding_IMobileService\">
      <binaryMessageEncoding />
      <httpTransport />
    </binding>
  </customBinding>
</bindings>
<client>
  <endpoint address=\"http://localhost:6862/silverlight/services/MobileService.svc\"
    binding=\"customBinding\" bindingConfiguration=\"CustomBinding_IMobileService\"
    contract=\"AlchemyMobileService.IMobileService\" name=\"CustomBinding_IMobileService\" />
</client>
<services>
  <service name=\"MobileService.Alchemy\">
    <endpoint address=\"http://localhost:8732/mobileservice\" binding=\"webHttpBinding\" contract=\"MobileService.IAlchemy\" behaviorConfiguration=\"REST\">
    </endpoint>
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior>
      <serviceDebug includeExceptionDetailInFaults=\"True\" />
    </behavior>
  </serviceBehaviors>
  <endpointBehaviors>
    <behavior name=\"REST\">
      <webHttp />
    </behavior>
  </endpointBehaviors>
</behaviors>