加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

如何配置具有两个端点的WCF服务,以便为每个端点使用不同的Listen

发布时间:2020-12-13 22:38:31 所属栏目:Windows 来源:网络整理
导读:我有一个WCF服务,它使用webHttpBinding公开一个端点,并被 WPF和ASP.NET应用程序使用.一切都很好. 我现在正试图从Windows Phone(WP7)中使用该服务.但是,由于.NET Framework尚未完全赶上WP7,因此System.ServiceModel.Web命名空间不可用,结果是webHttpBinding在
我有一个WCF服务,它使用webHttpBinding公开一个端点,并被 WPF和ASP.NET应用程序使用.一切都很好.

我现在正试图从Windows Phone(WP7)中使用该服务.但是,由于.NET Framework尚未完全赶上WP7,因此System.ServiceModel.Web命名空间不可用,结果是webHttpBinding在WP7中不起作用.

现在,在我的服务上,如果我将webHttpBinding切换为basicHttpBinding,则电话应用程序可以正常工作.

我不想重写我的WPF和ASP.NET应用程序来使用basicHttpBinding.

我知道WCF能够支持多个绑定,我试图配置和运行该服务,以便它为webHttpBinding和basicHttpBinding公开端点.该服务似乎启动良好.但是,WPF& ASP.NET应用程序无法访问它.当我尝试在WP7应用程序中创建服务引用时,我收到以下消息:

A binding instance has already been associated to listen URI
‘http://localhost:1726/GeneralService.svc’. If two endpoints want to
share the same ListenUri,they must also share the same binding object
instance. The two conflicting endpoints were either specified in
AddServiceEndpoint() calls,in a config file,or a combination of
AddServiceEndpoint() and config.

我和一位同事玩过baseAddress,address和listenUri属性的各种更改,但没有任何运气.我们现在正处于试验和错误的阶段,这并不是非常有效.

<system.serviceModel>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
    <bindings>
        <basicHttpBinding>
            <binding name="generalBasic" />
        </basicHttpBinding>
        <webHttpBinding>
            <binding name="general" maxReceivedMessageSize="2147483647">
                <readerQuotas maxStringContentLength="2147483647" maxArrayLength="2147483647" />
                <security mode="None">
                    <transport clientCredentialType="None" />
                </security>
            </binding>
        </webHttpBinding>
    </bindings>
    <behaviors>
        <serviceBehaviors>
            <behavior>
                <serviceMetadata httpGetEnabled="true"/>
                <serviceDebug includeExceptionDetailInFaults="false" />
            </behavior>
        </serviceBehaviors>
        <endpointBehaviors>
            <behavior name="web">
                <webHttp />
            </behavior>
        </endpointBehaviors>
    </behaviors>
    <services>
        <service name="MyProject.GeneralService">
            <endpoint address="mex" 
                binding="mexHttpBinding"
                contract="IMetadataExchange" />
            <endpoint address="" 
                binding="basicHttpBinding" 
                bindingConfiguration="generalBasic"
                contract="MyProject.Contracts.IGeneralService" />
            <endpoint behaviorConfiguration="web" 
                binding="webHttpBinding"
                bindingConfiguration="general" 
                contract="MyProject.Contracts.IGeneralService" />
            <host>
                <baseAddresses>
                    <add baseAddress="http://localhost:1726/" />
                </baseAddresses>
            </host>
        </service>
    </services>
</system.serviceModel>

解决方法

只需使用基本或webhttp端点的值指定address属性即可区分其地址.例如:

<endpoint behaviorConfiguration="web" address="rest" binding="webHttpBinding" bindingConfiguration="general" contract="MyProject.Contracts.IGeneralService" />

应该解决你的问题

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读