【问题标题】:WCF - netTcpBinding and securityWCF - netTcpBinding 和安全性
【发布时间】:2014-04-16 09:42:07
【问题描述】:

我有一个使用 NetTcpBinding 实现的 WCF 服务。它可以通过互联网消费。虽然它不在我的域中运行,但我无法使用 Windows 凭据。我现在正在寻找一种方法来保护服务。

没有安全性的方法可以正常工作。但是对于实时系统而言,安全性是必需的。因此,我阅读了很多内容,展示了如何配置 wsHttpBindings 之类的 http://msdn.microsoft.com/en-us/library/ms729789.aspx。但这并没有说明如何配置 NetTcpBinding。

我现在知道默认情况下 NetTcpBinding 是安全的(请参阅 http://www.codemag.com/article/0611051)。但它在适合我的配置中仍然安全吗?

服务:

<netTcpBinding>
    <binding name="tcpBinding"
         maxBufferSize="67108864"
         maxReceivedMessageSize="67108864"
         maxBufferPoolSize="67108864"
         transferMode="Buffered"
         closeTimeout="00:02:00"
         openTimeout="00:02:00"
         receiveTimeout="00:20:00"
         sendTimeout="00:02:00"
         maxConnections="100">
      <security mode="None">
      </security>
      <readerQuotas maxArrayLength="67108864"
              maxBytesPerRead="67108864"
              maxStringContentLength="67108864"/>
      <reliableSession enabled="true" inactivityTimeout="24:00:00"/>
    </binding>
  </netTcpBinding>

客户:

    <binding name="NetTcpBinding_IMessageSending">
      <reliableSession inactivityTimeout="00:20:00" enabled="true" />
      <security mode="None"></security>
    </binding>

我也知道我可以使用证书以某种方式保护服务。但实际上这对我不起作用。我为服务配置了这样的行为:

    <behavior name="tcpBehavior">
      <serviceMetadata httpGetEnabled="false" httpGetUrl=""/>
      <serviceDebug includeExceptionDetailInFaults="true"/>
      <serviceThrottling maxConcurrentCalls="100" maxConcurrentSessions="100"/>
      <serviceCredentials>
        <serviceCertificate findValue="GeoTrust SSL CA - G2" storeLocation="LocalMachine" storeName="My" x509FindType="FindBySubjectName" />
      </serviceCredentials>
    </behavior>

绑定看起来像这样:

<binding name="tcpBinding"
         maxBufferSize="67108864"
         maxReceivedMessageSize="67108864"
         maxBufferPoolSize="67108864"
         transferMode="Buffered"
         closeTimeout="00:02:00"
         openTimeout="00:02:00"
         receiveTimeout="00:20:00"
         sendTimeout="00:02:00"
         maxConnections="100">
      <security mode="Transport" />          
      <readerQuotas maxArrayLength="67108864"
              maxBytesPerRead="67108864"
              maxStringContentLength="67108864"/>
      <reliableSession enabled="true" inactivityTimeout="24:00:00"/>
    </binding>

和这样的端点:

  <service name="MessageSendingService" behaviorConfiguration="tcpBehavior" >        
    <endpoint address="" binding="netTcpBinding" bindingConfiguration="tcpBinding"
      contract="IMessageSending" />
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
  </service>

实际上,我真的不知道如何配置客户端来使用它。
我的(不工作的)客户端配置:

<binding name="NetTcpBinding_IMessageSending">
      <reliableSession inactivityTimeout="00:20:00" enabled="true" />
      <security mode="Transport">            
      </security>          
 </binding>

还是我的配置有错误?

事实上,服务请求失败并出现 SecurityNegotiationException。有谁可以告诉我如何配置具有匿名客户端的传输或消息安全的 NetTcpBinding 服务?

提前致谢。

【问题讨论】:

    标签: .net web-services wcf security nettcpbinding


    【解决方案1】:

    请看this SO question。使用了消息安全性并且未启用可靠会话(我不知道它是否是默认设置,但配置不包含设置)但也许您可以从示例中进行一些操作。

    【讨论】:

    • 如果我理解正确的服务和客户端总是必须使用相同的证书?有没有办法配置客户端,所以我不必使用客户端证书?
    • 您可以设置&lt;message clientCredentialType="None"/&gt;。这样客户端将不会使用任何证书,并且将使用匿名身份验证。请注意,使用的安全性是消息,而不是传输。
    • 我试过了,但没有任何影响。您是否在不在同一个域中的不同机器上测试了您的配置?
    • 不,我没有。我使用了引用的示例。在同一个控制台应用程序中有客户端和服务器。我会在另一台电脑上试试。
    • 好的,我已经测试了域中的计算机(WCF 客户端)和 VM(WCF 服务)之间的示例。有效。我必须允许该服务通过防火墙,但(可能是因为我是 VM 上的管理员)窗口自动询问我是否要允许这个。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-14
    • 2013-01-19
    • 2010-10-27
    • 2011-02-01
    • 1970-01-01
    • 2011-06-27
    相关资源
    最近更新 更多