C# 为什么我的WCF服务会给出这样的信息';没有与None MessageVersion';的绑定;?

C# 为什么我的WCF服务会给出这样的信息';没有与None MessageVersion';的绑定;?,c#,wcf,C#,Wcf,我已经创建了一个工作的WCF服务。我现在想给它添加一些安全性来过滤Ip地址。我遵循了microsoft在示例中发布的示例,尝试添加IDispatchMessageInspector,该Inspector将在ReceiveRequest后引发调用,然后在ip地址不在允许列表中时抛出错误 在看了代码之后;他们使用“wsHttpBinding”对其进行了配置,但我想使用“webHttpBinding”或“basicHttpBinding”。但是当我设置它时,我得到了错误: 终点在'http://upl

我已经创建了一个工作的WCF服务。我现在想给它添加一些安全性来过滤Ip地址。我遵循了microsoft在示例中发布的示例,尝试添加IDispatchMessageInspector,该Inspector将在ReceiveRequest后引发调用,然后在ip地址不在允许列表中时抛出错误

在看了代码之后;他们使用“wsHttpBinding”对其进行了配置,但我想使用“webHttpBinding”或“basicHttpBinding”。但是当我设置它时,我得到了错误:

终点在'http://upload/api/Api.svc/soap"没有 与None MessageVersion绑定。 “System.ServiceModel.Description.WebHttpBehavior”仅适用于 与WebHttpBinding或类似绑定一起使用

我的配置是:

<system.serviceModel>


    <serviceHostingEnvironment multipleSiteBindingsEnabled="true">
    </serviceHostingEnvironment>
    <!--Set up the service-->
    <services>
      <service behaviorConfiguration="SOAPRESTDemoBehavior" name="HmlApi">
        <endpoint address="rest" binding="webHttpBinding" contract="VLSCore2.Interfaces.IHmlApi" behaviorConfiguration="SOAPRESTDemoEndpointBehavior" />
        <endpoint address="soap" binding="basicHttpBinding" contract="VLSCore2.Interfaces.IHmlApi" behaviorConfiguration="SOAPRESTDemoEndpointBehavior" />
      </service>
    </services>

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

      <!---Endpoint -->
      <endpointBehaviors>
        <behavior name="SOAPRESTDemoEndpointBehavior">
          <ipFilter/>
          <webHttp />
        </behavior>
      </endpointBehaviors>
    </behaviors>

    <extensions>
      <behaviorExtensions>
        <add name="ipFilter" type="VLSCore2.Api.IpFilterBehaviourExtensionElement, VLSCore2, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/>
      </behaviorExtensions>
    </extensions>

  </system.serviceModel>

因此,我想知道的是,如何在不使用WebHttpBinding的情况下设置消息检查器。这可能吗


我希望使用SOAP“basicHttpBinding”而不是wsHttpBinding(以及所有WS*)相关的开销……

这只是因为您为SOAP和REST端点配置了一个端点行为,但SOAP端点不能具有webHttp行为。您需要将它们分开,以便它们是:

  <endpointBehaviors>
    <behavior name="SOAPDemoEndpointBehavior">
      <ipFilter/>
    </behavior>
    <behavior name="RESTDemoEndpointBehavior">
      <ipFilter/>
      <webHttp />
    </behavior>
  </endpointBehaviors>

然后,您的端点应该是:

    <endpoint address="rest" binding="webHttpBinding" contract="VLSCore2.Interfaces.IHmlApi" behaviorConfiguration="RESTDemoEndpointBehavior" />
    <endpoint address="soap" binding="basicHttpBinding" contract="VLSCore2.Interfaces.IHmlApi" behaviorConfiguration="SOAPDemoEndpointBehavior" />


对我来说,这是因为我将“webHttp”定义为SOAP配置的行为。只有它的缺席才解决了这个问题。

非常感谢,这是一个很好的解决办法。公平地说,我认为现在为服务设置所有正确的端点非常重要!伙计,我已经挣扎了几个小时,我来到这里,注意到我没有更改绑定:))我正在使用basic从移动应用程序请求http。。。竖起大拇指+