Tutorial :Binding not working in “dual mode” (webHttpBinding and basicHttpBinding)



Question:

I have a WCF service:

<%@ ServiceHost Language="C#" Debug="true" Service="IWW.MIGTurbo2.WCF.Security.SecurityBroker" Factory="System.ServiceModel.Activation.WebScriptServiceHostFactory"   %>  

This works fine using webHttpBinding from my web project.

I also want this service to be usable by a WinForms client, so have added a basicHttpBinding binding.

My server config file is currently:

<system.serviceModel>  <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />  <behaviors>      <endpointBehaviors>          <behavior name="webScriptEnablingBehavior">              <enableWebScript />          </behavior>          <behavior name="webHttpEnablingBehaviour">              <webHttp />          </behavior>      </endpointBehaviors>      <serviceBehaviors>          <behavior name="webHttpEnablingBehaviour">              <serviceMetadata httpGetEnabled="true" />          </behavior>          <behavior name="webScriptEnablingBehavior">              <serviceMetadata httpGetEnabled="true" />              <serviceDebug includeExceptionDetailInFaults="true" />          </behavior>      </serviceBehaviors>  </behaviors>  <services>      <service name="IWW.MIGTurbo2.WCF.Security.SecurityBroker" behaviorConfiguration="webHttpEnablingBehaviour">          <endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />          <!-- This works for web-clients -->                      <endpoint address=""               binding="webHttpBinding"              bindingConfiguration="default"              contract="IWW.MIGTurbo2.WCF.Security.ISecurityBroker"                  behaviorConfiguration="webHttpEnablingBehaviour">          </endpoint>          <!-- This is for WinForms clients, but isn't working -->                  <endpoint address=""              binding="basicHttpBinding"              bindingConfiguration="default"              contract="IWW.MIGTurbo2.WCF.Security.ISecurityBroker"                  behaviorConfiguration="webHttpEnablingBehaviour">          </endpoint>      </service>  </services>  <client />  <bindings>      <webHttpBinding>          <binding name="default" ></binding>      </webHttpBinding>      <basicHttpBinding>           <binding name="default" allowCookies="true"></binding>      </basicHttpBinding>  </bindings>  

The section marked for WinForms doesn't appear to work. I get an exception:

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

When I try to browse to the .svc file manually using IE. Obviously, the WinForms client doesn't want to know.

Can anyone spread any light on why it isn't working? It almost looks as if I can't have more than one endpoint or the second endpoint isn't configured correctly? Google offers nothing that is particularly useful.


Solution:1

Like the exception says, your second endpoint has (1) webHttpBehavior and (2) basicHttpBinding, and these are incompatible. I think you may just want to remove the webHttpBehavior from the second endpoint.


Solution:2

The Answer:

(Brian got it the points, but this is what caused it in detail)

Visual Studio had created a "customBinding" element for me on the client side, which was less than helpful. So to get it working, I changed my client-side app.config to be:

    <system.serviceModel>      <bindings>          <basicHttpBinding>              <binding name="WebHttpBinding_ISecurityBroker" allowCookies="true" />          </basicHttpBinding>           </bindings>      <client>                   <endpoint binding="basicHttpBinding" bindingConfiguration="WebHttpBinding_ISecurityBroker"              contract="Client.API.WCF.ISecurityBroker" name="WebHttpBinding_ISecurityBroker" />      </client>  </system.serviceModel>  

and my server-side web.config to be:

<system.serviceModel>      <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />      <behaviors>          <endpointBehaviors>                <behavior name="webHttpEnablingBehaviour">                    <webHttp />              </behavior>          </endpointBehaviors>          <serviceBehaviors>                <behavior name="webHttpEnablingBehaviour">                  <serviceMetadata httpGetEnabled="true" />              </behavior>            </serviceBehaviors>      </behaviors>      <services>          <service            name="IWW.MIGTurbo2.WCF.Security.SecurityBroker" behaviorConfiguration="webHttpEnablingBehaviour">              <endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />                <endpoint address=""                   binding="webHttpBinding"                  bindingConfiguration="default"                  contract="IWW.MIGTurbo2.WCF.Security.ISecurityBroker"                  behaviorConfiguration="webHttpEnablingBehaviour">              </endpoint>              <endpoint address="other"                  binding="basicHttpBinding"                  bindingConfiguration="default"                  contract="IWW.MIGTurbo2.WCF.Security.ISecurityBroker">              </endpoint>          </service>        </services>      <client />      <bindings>          <webHttpBinding>              <binding name="default" ></binding>          </webHttpBinding>          <basicHttpBinding>               <binding name="default" allowCookies="true"></binding>          </basicHttpBinding>      </bindings>  </system.serviceModel>  

and I have the following code to connect within my client application (WinForms):

using (SecurityBrokerClient securityBrokerClient = new SecurityBrokerClient())          {              string securityBrokerUrl=url+"api/wcf/SecurityBroker.svc";              securityBrokerUrl += "/other";              securityBrokerClient.Endpoint.Address = new System.ServiceModel.EndpointAddress(securityBrokerUrl);              securityBrokerClient.Open();              securityBrokerClient.Login(username, password, "MIGTurbo2Admin");          }  


Solution:3

The first and foremost issue that i see in your config file is with Endpoints configuration.

<endpoint address="" binding="webHttpBinding"  bindingConfiguration="default"            contract="IWW.MIGTurbo2.WCF.Security.ISecurityBroker"            behaviorConfiguration="webHttpEnablingBehaviour">   </endpoint>                <!-- This is for WinForms clients, but isn't working -->     <endpoint address="" binding="basicHttpBinding" bindingConfiguration="default"              contract="IWW.MIGTurbo2.WCF.Security.ISecurityBroker"               behaviorConfiguration="webHttpEnablingBehaviour">   </endpoint>  

Here we are not specifying any address and listenuri in the tag . So we will have default values for these and also for the 2 endpoints we will have same address and same listenuri(ie default values).

So here comes the problem. 1. we cannot have different types of binding with same listenuri and same address. But in your case as you are specifying empty values for address, both the endpoints will have same values

Resolution: 1. specify different address for both the endpoints instead of leaving them as empty.

<endpoint address="Rest" binding="webHttpBinding"  bindingConfiguration="default"            contract="IWW.MIGTurbo2.WCF.Security.ISecurityBroker"            behaviorConfiguration="webHttpEnablingBehaviour">   </endpoint>                <!-- This is for WinForms clients, but isn't working -->     <endpoint address="WebForm" binding="basicHttpBinding" bindingConfiguration="default"              contract="IWW.MIGTurbo2.WCF.Security.ISecurityBroker"               behaviorConfiguration="webHttpEnablingBehaviour">   </endpoint>  

So even though we are using different bindings and same listenuri(if we don't specify listenuri it will be default) as the address(relative address) values differ it will be working fine.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »