【问题标题】:Can I use wsHttpBinding along with webHttpBinding in WCF service?我可以在 WCF 服务中使用 wsHttpBinding 和 webHttpBinding 吗?
【发布时间】:2012-12-28 05:31:28
【问题描述】:

我有一个自定义的用户名密码 WCF 服务,需要由 Windows 客户端(Winforms 应用程序)以及 Web 客户端(html/aspx 页面)调用。我在 web.config 中有两个端点声明,但为了使其正常工作,我必须对其中一个进行注释,因此,只有与该未注释端点关联的客户端类型才能访问该服务。如果我取消评论,并评论另一个,其他客户可以访问它。我无法同时保留它们,因此我无法使用这两种类型的客户端访问它。

<service behaviorConfiguration="Behavior1" name="BeST.Service.Service">
    <endpoint address="" binding="webHttpBinding" contract="BeST.Service.IService" behaviorConfiguration="EndpBehavior"></endpoint>
    <endpoint address="" binding="wsHttpBinding" bindingConfiguration="Binding1"
     contract="BeST.Service.IService" />
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost/" />
      </baseAddresses>
    </host>
  </service>

正如代码所示,如​​果我想让这个服务为两个客户端工作,或者如果有其他方法可以完成,我需要使用两个端点(两个端点之上),请帮助!

【问题讨论】:

    标签: wcf web-config wcf-binding


    【解决方案1】:

    问题是您为两个端点提供了相同的地址。尝试为您的一个端点提供另一个相对地址,它应该可以工作。

    <service behaviorConfiguration="Behavior1" name="BeST.Service.Service">
      <endpoint address="web" binding="webHttpBinding" contract="BeST.Service.IService" behaviorConfiguration="EndpBehavior"></endpoint>
      <endpoint address="" binding="wsHttpBinding" bindingConfiguration="Binding1"
        contract="BeST.Service.IService" />
      <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      <host>
        <baseAddresses>
          <add baseAddress="http://localhost/" />
        </baseAddresses>
      </host>
    </service>
    

    【讨论】:

    • 谢谢,我发现这个“地址”是问题所在,但如果我将其更改为某个值,我无法弄清楚如何使用它。现在可以了!
    猜你喜欢
    • 2012-07-30
    • 2012-10-02
    • 1970-01-01
    • 2011-06-04
    • 2017-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-08
    相关资源
    最近更新 更多