WCF - 绑定错误
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.
这是我尝试启动 WCF 服务时收到的错误。我已经阅读了这里关于绑定错误的每一篇文章,但它们都有点不同,我无法弄清楚。这是我的 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>
如果这有影响的话,我将在 Windows 服务中托管我的 WCF 服务。我的最终目标是使用 winforms 应用程序来使用 WCF 服务。当我在 VS 中仅运行 WCF 服务时,它可以工作,但是当我将配置添加到 Windows 服务 app.config 并尝试用它启动 WCF 服务时,我收到错误。任何帮助都会很棒。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该异常通知您端点行为与您的绑定 (wsHttpBinding) 不兼容。
删除>从端点行为或使用 WebHttpBinding 而不是 wsHttpBinding。
如果要为使用 HTTP 请求而不是 SOAP 消息的 Web 服务配置端点,请使用 WebHttpBinding。 WebHttpBehavior () 与 WebHttpBinding(或兼容的)一起使用时启用此编程模型。
这就是问题所在。此行为与您选择的绑定 (wsHttpBinding) 不兼容。
您还应该命名端点配置:
并使用该名称将其链接到服务的端点:
这可确保您的服务端点使用 WebHttp 端点行为 (webHttp) 指定的行为。现在您还没有命名它,因此 mex 端点也会获得此行为。这是不需要的。只需将 mexHttpBinding 用于 mex 端点,但不要将其链接到与服务相同的行为。
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:
And use the name to link it to the service's 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.