0

我有一个使用 WCF Web 服务的应用程序。

我已将其配置为使用 https 绑定。它工作正常。我还想为它添加一个 HTTP 绑定。

我的要求是,如果我的客户端在我的域(或 VPN)上,我需要他们使用 HTTP 绑定。如果他们是外部客户端,我希望他们使用 HTTPS 绑定。我该怎么做呢?我对 WCF 很陌生,这是我第一次尝试它。

我已附上我的配置文件以供参考。我不知道在哪里添加 HTTP 绑定的端点。任何帮助都将不胜感激。

<system.serviceModel>
    <services>
      <service name="{service name}"
                behaviorConfiguration="httpsBehavior">
        <!--HTTPS END POINT-->
        <endpoint address=""
                  binding="basicHttpBinding"
                  bindingConfiguration="SecureHTTPBinding"
                  contract="{service contract}" />

    <!--METADATA ENDPOINT--> 
    <endpoint address="mex"
              binding="mexHttpsBinding"
              contract="IMetadataExchange" />
  </service>
</services>

<behaviors>
  <serviceBehaviors>
    <behavior name="httpsBehavior">
      <serviceMetadata httpsGetEnabled="true" httpsGetUrl="" />
      <serviceDebug includeExceptionDetailInFaults="false"/>
    </behavior>

    <behavior name="httpBehavior">
      <serviceMetadata httpGetEnabled="true"/>
      <serviceDebug includeExceptionDetailInFaults="false"/>
    </behavior>

  </serviceBehaviors>
</behaviors>

<bindings>
  <basicHttpBinding>
    <!--HTTPS BINDING-->
    <binding name="SecureHTTPBinding">
      <security mode="Transport">
        <transport clientCredentialType="None" />
      </security>
    </binding>

    <!--HTTP BINDING-->
    <binding name="BasicHttpBinding">
      <security mode="None" />
    </binding>

  </basicHttpBinding>
</bindings>

编辑:添加 netTCP 绑定

<system.serviceModel>
    <services>
      <service name="{Service Name}"
                behaviorConfiguration="httpsBehavior">
        <!--HTTPS END POINT-->
        <endpoint address="https://localhost/Service1.svc"
                  binding="basicHttpBinding"
                  bindingConfiguration="SecureHTTPBinding"
                  contract="{Service Contract}"  name="httpsEndPoint"/>

    <!--METADATA ENDPOINT--> 
    <endpoint address="mex"
              binding="mexHttpsBinding"
              contract="IMetadataExchange" />

    <!--HTTP END POINT-->
    <endpoint address="http://localhost/Service1.svc"
              binding="basicHttpBinding"
              bindingConfiguration="HttpBinding"
              contract="{Service Contract}" name="httpsEndPoint"/>

    <!--TCP METATADATA END POINT-->
    <endpoint address="mextcp" binding="mexTcpBinding" contract="IMetadataExchange"/>
    <host>
      <baseAddresses>
        <add baseAddress="net.tcp://localhost:808/Service1.svc" />
      </baseAddresses>
    </host>

    <!--TCP ENDPOIN-->
    <endpoint address="net.tcp://localhost:808/Service1.svc" binding="netTcpBinding" contract="{Service Contract}" name="netTCPEndPoint" />



  </service>
</services>

<behaviors>
  <serviceBehaviors>
    <behavior name="httpsBehavior">
      <serviceMetadata httpsGetEnabled="true" httpsGetUrl="" />
      <serviceDebug includeExceptionDetailInFaults="true"/>
    </behavior>

  </serviceBehaviors>
</behaviors>

<bindings>
  <basicHttpBinding>
    <!--HTTPS BINDING-->
    <binding name="SecureHTTPBinding" allowCookies="true"
             maxReceivedMessageSize="20000000"
             maxBufferSize="20000000"
             maxBufferPoolSize="20000000">
      <readerQuotas maxDepth="32"
             maxArrayLength="200000000"
             maxStringContentLength="200000000"/>

      <security mode="Transport">
        <transport clientCredentialType="None" />
      </security>
    </binding>

    <!--HTTP BINDING-->
    <binding name="HttpBinding" allowCookies="true"
             maxReceivedMessageSize="20000000"
             maxBufferSize="20000000"
             maxBufferPoolSize="20000000">
      <readerQuotas maxDepth="32"
             maxArrayLength="200000000"
             maxStringContentLength="200000000"/>
      <security mode="None" />
    </binding>

  </basicHttpBinding>

  <!--TCP BINDING-->
  <netTcpBinding>
    <binding transferMode="Buffered" />
  </netTcpBinding>

</bindings>

我知道代码中的数字可能存在 Dos 攻击,我会解决它。现在只是想让它工作。当我使用这个配置文件时,我遇到了错误,上面写着

找不到与端点 MetadataExchageTcpBinding 的方案 net.tcp 匹配的基地址。注册的基地址是 [http,https]

有人可以帮我为我的服务公开一个 net.tcp 绑定吗?任何帮助都会得到帮助

4

1 回答 1

1

用于netTcpBinding您的域客户端。默认情况下,您的网络防火墙几乎肯定会阻止原始 TCP 流量,同时允许 HTTP 流量,因此它自然会确保每个客户端都转到适当的端点。您很可能会在讨价还价中为域客户获得额外的性能提升。

如果您不想这样做(例如,您的 WCF 主机不支持它,或者您的 VPN 客户端有问题),那么只需为所有客户端公开一个 HTTPS 端点,无论位置如何。与首先进行跨网络调用的开销相比,SSL 的成本将微不足道。

背景:

  • netTcpBinding以紧凑的二进制格式传输数据,这比通过 HTTP 发送 XML 文本更有效。缺点是:它与非.NET 客户端不兼容,您必须在防火墙上打开特定端口才能让它通过。不过,这些问题都不会成为您的方案的问题。
  • 您可以在 WCF 服务中公开任意数量的终结点,只要它们都具有地址/绑定/合同的唯一不同组合。因此,您可以将 HTTPS 和 TCP 端点暴露给同一服务,因为它们将具有不同的地址和绑定。
于 2012-11-28T15:45:40.260 回答