Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does my WCF service give the message 'does not have a Binding with the None MessageVersion'?

Tags:

c#

wcf

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

like image 810
Exitos Avatar asked Sep 28 '11 15:09

Exitos


People also ask

What is default binding in WCF?

When hosting WCF service in IIS (using WCF Service application project template) with default .svc file (without changing its service host factory) the default binding is basicHttpBinding .

Which binding is used in WCF to support REST based service?

Web binding It is designed to expose WCF services as HTTP requests using HTTP-GET and HTTP-POST. It is used with REST based services that may provide output in XML or JSON format.


2 Answers

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" /> 
like image 141
Phil Degenhardt Avatar answered Oct 16 '22 17:10

Phil Degenhardt


For me, this was because I had a 'webHttp' defined as a behaviour for a SOAP config. Only its absence resolved it..

like image 38
Jon H Avatar answered Oct 16 '22 18:10

Jon H