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....
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 .
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.
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" />
For me, this was because I had a 'webHttp' defined as a behaviour for a SOAP config. Only its absence resolved it..
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With