开发者

WCF - Error with binding

开发者 https://www.devze.com 2023-04-05 23:42 出处:网络
The endpoint at \'http://localhost:8731/Design_Time_Addresses/WCF/WCFService/\' does not have a Binding with the None MessageVersion.\'System.ServiceModel.Description.WebHttpBehavior\' is only intende
The endpoint at 'http://localhost:8731/Design_Time_Addresses/WCF/WCFService/' does not have a Binding with the None MessageVersion.  'System.ServiceModel.Description.WebHttpBehavior' is only intended for use with WebHttpBinding or similar bindings.

This is the error I get when I try to the start my WCF service. I have read over every post here about binding errors, but they are all a little different and I can't figure it out. Here is my app.config:

<system.serviceModel>
    <services>
      <service name="WCF.WCFService">
        <endpoint address="" binding="wsHttpBinding" contract="WCF.IWCFService">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint
          address="mex"
          binding="mexHttpBinding"
          bindingConfiguration=""
          contract="IMetadataExchange"/>
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8731/Design_Time_Addresses/WCF/WCFService/" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="true"/>开发者_开发技巧
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior>
          <webHttp />
        </behavior>
      </endpointBehaviors>
    </behaviors>
  </system.serviceModel>

I am hosting my WCF service within a windows service if that makes a difference. MY End goal is to use a winforms application to consume the WCF service. When I run just the WCF service within VS, it works, but when I add the config to the windows service app.config and try to start the WCF service with it, I get the error. Any help would be great.


The exception informs you that your endpoint behavior is not compatible with your binding (wsHttpBinding).

Remove the <webHttp /> from the endpoint behaviour or use WebHttpBinding instead of wsHttpBinding.

Use the WebHttpBinding if you want to configure endpoints for web services that use HTTP requests instead of SOAP messages. The WebHttpBehavior (<webHttp />) enables this programming model when used together with WebHttpBinding (or a compatible one).

And that's the problem. This behavior is not compatbile with your chosen binding (wsHttpBinding).

You should also name your endpoint configuration:

<endpointBehaviors>
    <behavior name="WebHttp">
        <webHttp />
    </behavior>
</endpointBehaviors>

And use the name to link it to the service's endpoint:

<endpoint address="" binding="wsHttpBinding" contract="WCF.IWCFService" 
          behaviorConfiguration="WebHttp"/>
    <identity>
        <dns value="localhost" />
    </identity>
</endpoint>

This makes sure that your service's endpoint uses the behavior specified by the WebHttp endpoint behavior (webHttp). Right now you didn't name it, so the mex endpoint also gets this behavior. This is not needed. Just use mexHttpBinding for the mex endpoint, but do not link it to the same behavior as the service.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号