适用于双工和非双工的 WCF 合同

发布于 2025-01-03 04:54:54 字数 4224 浏览 1 评论 0原文

我正在尝试托管支持 wshttpbinding 和 wsDualHttpBinding 的 WCF 服务。原因是对于桌面客户端,我需要双工合同,而对于网络客户端,我不需要。

我尝试创建一个双工合约,它工作完美,现在我尝试向我的 WCF 添加没有回调的新合约,我定义新接口,添加 [ServiceContract] 和实现新接口合约的新类,但我不知道如何定义 web.config 来让我在同一个 WCF 中获得绑定/合同。

这是我尝试做的:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.serviceModel>
    <bindings>
      <wsDualHttpBinding>
        <binding name="WSDualHttpBinding_IBridgeWCFService" closeTimeout="01:01:00" openTimeout="01:01:00" receiveTimeout="01:10:00" sendTimeout="01:01:00" bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="2147483646" maxReceivedMessageSize="2147483646" messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true">
          <readerQuotas maxDepth="256" maxStringContentLength="2147483646" maxArrayLength="2147483646" maxBytesPerRead="2147483646" maxNameTableCharCount="2147483646" />
          <reliableSession ordered="true" inactivityTimeout="01:10:00" />
          <security mode="Message">
            <message clientCredentialType="Windows" negotiateServiceCredential="true" algorithmSuite="Default" />
          </security>
        </binding>
      </wsDualHttpBinding>
      <wsHttpBinding>
        <binding name="WSHttpBinding_IWebBridgeWCFService" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="2147483646" maxReceivedMessageSize="2147483646" messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
          <readerQuotas maxDepth="32" maxStringContentLength="2147483646" maxArrayLength="2147483646" maxBytesPerRead="2147483646" maxNameTableCharCount="2147483646"/>
          <reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false"/>
          <security mode="Message">
            <!--<transport clientCredentialType="Windows" proxyCredentialType="None" realm=""/>
            <message clientCredentialType="Windows" negotiateServiceCredential="true" algorithmSuite="Default"/>-->
          </security>
        </binding>
      </wsHttpBinding>
    </bindings>
    <services>
      <service behaviorConfiguration="BridgeNameSpace.Service1Behavior" name="BridgeNameSpace.BridgeWCFService">
        <endpoint address="" binding="wsDualHttpBinding" bindingConfiguration="WSDualHttpBinding_IBridgeWCFService" contract="BridgeNameSpace.IBridgeWCFService">
          <identity>
            <servicePrincipalName value="BridgeWCFService" />
            <dns value="win-j7da0dqoajj" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />

        <endpoint address="" binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IWebBridgeWCFService" contract="BridgeNameSpace.IWebBridgeWCFService">
          <identity>
            <dns value="localhost"/>
          </identity>
        </endpoint>

      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="BridgeNameSpace.Service1Behavior">
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="true" />
          <dataContractSerializer maxItemsInObjectGraph="2147483647" />
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
  <system.web>
    <compilation debug="true" />
  </system.web>
</configuration>

I am trying to host a WCF service that supports wshttpbinding and wsDualHttpBinding. The reason is for desktop clients I need duplex contract and for web clients I don't.

I tried to create a contract for duplex and it work perfect, Now I tried to add new contract to my WCF which have no call back, I define new interface, add the [ServiceContract], and new class who implement the new interface contract, but I don't know how to define the web.config to let me get both binding/contract in same WCF.

here what I tried to do:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.serviceModel>
    <bindings>
      <wsDualHttpBinding>
        <binding name="WSDualHttpBinding_IBridgeWCFService" closeTimeout="01:01:00" openTimeout="01:01:00" receiveTimeout="01:10:00" sendTimeout="01:01:00" bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="2147483646" maxReceivedMessageSize="2147483646" messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true">
          <readerQuotas maxDepth="256" maxStringContentLength="2147483646" maxArrayLength="2147483646" maxBytesPerRead="2147483646" maxNameTableCharCount="2147483646" />
          <reliableSession ordered="true" inactivityTimeout="01:10:00" />
          <security mode="Message">
            <message clientCredentialType="Windows" negotiateServiceCredential="true" algorithmSuite="Default" />
          </security>
        </binding>
      </wsDualHttpBinding>
      <wsHttpBinding>
        <binding name="WSHttpBinding_IWebBridgeWCFService" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="2147483646" maxReceivedMessageSize="2147483646" messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
          <readerQuotas maxDepth="32" maxStringContentLength="2147483646" maxArrayLength="2147483646" maxBytesPerRead="2147483646" maxNameTableCharCount="2147483646"/>
          <reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false"/>
          <security mode="Message">
            <!--<transport clientCredentialType="Windows" proxyCredentialType="None" realm=""/>
            <message clientCredentialType="Windows" negotiateServiceCredential="true" algorithmSuite="Default"/>-->
          </security>
        </binding>
      </wsHttpBinding>
    </bindings>
    <services>
      <service behaviorConfiguration="BridgeNameSpace.Service1Behavior" name="BridgeNameSpace.BridgeWCFService">
        <endpoint address="" binding="wsDualHttpBinding" bindingConfiguration="WSDualHttpBinding_IBridgeWCFService" contract="BridgeNameSpace.IBridgeWCFService">
          <identity>
            <servicePrincipalName value="BridgeWCFService" />
            <dns value="win-j7da0dqoajj" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />

        <endpoint address="" binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IWebBridgeWCFService" contract="BridgeNameSpace.IWebBridgeWCFService">
          <identity>
            <dns value="localhost"/>
          </identity>
        </endpoint>

      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="BridgeNameSpace.Service1Behavior">
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="true" />
          <dataContractSerializer maxItemsInObjectGraph="2147483647" />
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
  <system.web>
    <compilation debug="true" />
  </system.web>
</configuration>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文