tags:

views:

3024

answers:

2

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.

+2  A: 

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.

Brian
Program.X
change the address of the second endpoint (e.g. <enpoint address="other" ...> and then have the client hit blahAddress/other
Brian
Thanks for your help.I realised that Visual Studio had created a <customBinding> which was incorrect. I should havehad a <basicHttp> binding. I'll accept your answer and write a proper response. This comment format is wholly un-useful for that!
Program.X
A: 

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");
  }
Program.X