C# – Why does the WCF service give the message ‘does not have a Binding with the None MessageVersion’

cwcf

I have created a working WCF service. I now want to add some security to it to filter Ip Addresses. I have followed the example that microsoft publish in the samples to try and add a IDispatchMessageInspector that will raise a call AfterReceiveRequest and then throw an error if the ip address is not from the allowed list.

After looking at the code; they have configured it using 'wsHttpBinding', however I want to use 'webHttpBinding' or 'basicHttpBinding'. But when I set it up I get the error:

The endpoint at 'http://upload/api/Api.svc/soap' does not have a
Binding with the None MessageVersion.
'System.ServiceModel.Description.WebHttpBehavior' is only intended for
use with WebHttpBinding or similar bindings.

My configuration is:

<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>

So what im wondering is how I can set up my message inspector without using WebHttpBinding. Is this even possible?

I want to use SOAP 'basicHttpBinding' not wsHttpBinding (and all of the WS*) associated overheads….

Best Answer

This is simply happening because you have configured a single endpointBehavior for both the SOAP and REST endpoints but the SOAP endpoint can't have the webHttp behavior. You need to split these apart so that they are:

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

and then your endpoints should be:

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