【问题标题】:How do I make use of the NetTcpRelaySecurity element in an app.config file?如何使用 app.config 文件中的 NetTcpRelaySecurity 元素?
【发布时间】:2012-04-18 15:04:45
【问题描述】:

我正在尝试使用 Azure 服务总线中继向公司网络之外的用户公开 WCF 服务。

我已经在一定程度上成功了,但是为了证明通信正常,我不得不删除所有在 WCF 服务上实现的自定义用户名和密码验证。

我已经在谷歌上搜索和阅读了一段时间,并相信 NetTcpRelaySecurity 模式是我需要进行更改的地方 - 从传输到 TransportWithMessageCredential(因为这是客户端和服务在网络中使用的)

那么,如何在配置文件中更改此设置?到目前为止,我找不到任何例子。

另外,我这样做的方式是否正确?我可以通过服务总线将用户名和密码客户端凭据从外部客户端应用程序传递到 WCF 服务吗?

【问题讨论】:

    标签: c# wcf azure servicebus


    【解决方案1】:

    您说得对,那里没有太多示例配置。您可以尝试以下配置。

    NetTcpRelayBindingConstructor NetTcpRelayBinding 构造函数(EndToEndSecurityMode、RelayClientAuthenticationType)

    EndToEndSecurityMode 有以下枚举。

     Member name    Description
     None       Security is disabled.
     Transport  Security is provided using a transport security, typically SSL.
     Message        Security is provided using SOAP message security.
     TransportWithMessageCredential     A secure transport (for example, HTTPS) provides integrity, confidentiality, and authentication while SOAP message security provides client authentication.
    

    RelayClientAuthentication 有以下枚举。

        Member name         Description
        RelayAccessToken    If specified by a listener, the client is required to provide a security token. 
        None                If specified by a listener, the client will not be required to provide a security token. This represents an opt-out mechanism with which listeners can waive the Access Control protection on the endpoint.
    

    我见过的最接近的配置示例是 -
    http://msdn.microsoft.com/en-us/library/windowsazure/microsoft.servicebus.nettcprelaybinding.aspx

    <bindings>
        <!-- Application Binding -->
        <netTcpRelayBinding>
          <binding name="customBinding">
            <!-- Turn off client authentication -->
            <security relayClientAuthenticationType="None" />
        </netTcpRelayBinding>
      </bindings>
    

    这是一个您可以使用的示例:

    <bindings>
        <!-- Application Binding -->
        <netTcpRelayBinding>
          <binding name="customBinding">
            <!-- Turn off client authentication -->
            <security endToEndSecurityMode=”TransportWithMessageCredential”  relayClientAuthenticationType="None" />
        </netTcpRelayBinding>
      </bindings>
    

    但是,您必须确保在 machine.config 或应用程序配置文件中添加服务总线绑定扩展元素才能使用它。如果没有,无论如何 Visual Studio 都会为您抛出错误。

    从客户端到服务的端到端安全性不是特定于服务总线的,而只是标准的 WCF。 SB 唯一需要的是下面的 relayClientAuthenticationType。

    <security mode=""  relayClientAuthenticationType="RelayAccessToken">
    

    nettcprelaybinding 的安全设置应该与 nettcpbinding 类似。您可以使用 nettcpbinding 示例作为起点。

    【讨论】:

    • 感谢您的回复。我已经尝试了您的示例,但遇到了一个错误,提示“endToEndSecurityMode”是一个无法识别的属性。我有服务总线绑定扩展元素,这些元素是在添加对 Microsoft.ServiceBus 的引用时自动生成的,因此 netTcpRelayBinding 不会导致错误,但也许我需要添加其他元素?
    猜你喜欢
    • 2011-09-22
    • 1970-01-01
    • 2010-12-14
    • 1970-01-01
    • 2013-09-24
    • 2012-10-26
    • 2015-07-29
    • 1970-01-01
    • 2011-05-15
    相关资源
    最近更新 更多