绑定在“双模式"下不起作用(webHttpBinding 和 basicHttpBinding) [英] Binding not working in "dual mode" (webHttpBinding and basicHttpBinding)

查看:17
本文介绍了绑定在“双模式"下不起作用(webHttpBinding 和 basicHttpBinding)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 WCF 服务:

I have a WCF service:

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

使用我的网络项目中的 webHttpBinding 可以正常工作.

This works fine using webHttpBinding from my web project.

我还希望 WinForms 客户端可以使用此服务,因此添加了 basicHttpBinding 绑定.

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>

标记为 WinForms 的部分似乎不起作用.我得到一个例外:

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

终点在'http://localhost:56125/MIGTurbo2_WEB/api/wcf/SecurityBroker.svc'没有与 None 的绑定消息版本.'System.ServiceModel.Description.WebHttpBehavior'仅适用于WebHttpBinding 或类似的绑定.

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.

当我尝试使用 IE 手动浏览到 .svc 文件时.显然,WinForms 客户端不想知道.

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

谁能解释为什么它不起作用?看起来好像我不能有多个端点,或者第二个端点没有正确配置?Google 没有提供任何特别有用的东西.

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.

推荐答案

就像例外所说的,你的第二个端点有 (1) webHttpBehavior 和 (2) basicHttpBinding,而这些是不兼容的.我认为您可能只想从第二个端点中删除 webHttpBehavior.

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.

这篇关于绑定在“双模式"下不起作用(webHttpBinding 和 basicHttpBinding)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆