【问题标题】:Developing a .NET client that consumes a secure METRO 2.1 web service开发使用安全 METRO 2.1 Web 服务的 .NET 客户端
【发布时间】:2011-04-03 12:20:22
【问题描述】:

我有一个安全的 METRO 2.1 Web 服务,我想开发一个可以使用它的 .NET (3.5) 客户端。如果 WS 不安全,我已经成功了,但是一旦我得到了

安全机制是Username Authentication with Symmetric Key,它使用Development Defaults

如何在 .NET 中设置安全性?我一直在阅读 METRO 指南,但我只发现了示例的断开链接,并且指南没有让我通过。我用svcutil成功生成了一个代理类,但是不知道怎么用。

svcutil 警告:

警告 1 自定义工具警告:已为端点导入安全策略。安全策略包含无法在 Windows Communication Foundation 配置中表示的要求。在生成的配置文件中查找有关 SecurityBindingElement 参数的注释。使用代码创建正确的绑定元素。配置文件中的绑定配置不安全。

警告 2 自定义工具警告:wsam:Addressing 元素需要 wsp:Policy 子元素,但没有子元素。

编辑

我已经非常接近解决这个问题(我认为)。我使用keytool.exe 导出了默认的 GlassFish 证书:

keytool -exportcert -alias xws-security-server -storepass changeit -keystore keystore.jks -file server.cer 
keytool -printcert -file server.cer //This line shows it's content

我在客户端使用server.cer 证书:

KDTreeWSClient wsClient = new KDTreeWSClient();
X509Certificate2 server_cert = new X509Certificate2("FullPathToCertificate/server.cer", "changeit");
wsClient.ClientCredentials.ServiceCertificate.DefaultCertificate = server_cert;
wsClient.ClientCredentials.UserName.UserName = "wsitUser"; //Default GF username
wsClient.ClientCredentials.UserName.Password = "changeit"; //Default GF password

问题这会导致 MessageSecurityException,因为端点的预期 DNS 身份是 localhost,但端点有 xwssecurityserver。我可以手动设置为localhost/xwssecurityserver吗?

任何帮助将不胜感激! 提前致谢, 丹尼尔

【问题讨论】:

标签: java .net wcf jax-ws java-metro-framework


【解决方案1】:

尝试在客户端应用程序的配置文件中设置 DNS 身份,如下所述

      <endpoint address="http://localhost:8080/SecureCalculatorApp/CalculatorWSService"
          binding="customBinding" bindingConfiguration="CalculatorWSPortBinding1"
          contract="ServiceReference3.CalculatorWS" name="CalculatorWSPort1">
        <identity>
          <dns value="{YOUR ALIAS}" />
        </identity>
      </endpoint>

作为 dns 值设置“xwssecurityserver”。就我而言,它有效(顺便说一下,我在解决此问题时将您的问题作为基础,所以感谢您指出正确的方法:))

【讨论】:

  • 谢谢!您的答案似乎更好,因为我的方法在之后导致服务器证书验证出现了一些问题。
【解决方案2】:

我实际上并不认为这是您的问题,但它可能有助于解决您遇到的一些工具警告。第二条消息看起来有点眼熟。我们有一个 SOAP 1.1 客户端与一个暴露了自定义错误异常的 Java WS 通信。当 Java 服务出现故障时,它会将堆栈跟踪添加到故障中,并且我们的 .NET 客户端崩溃了,因为它不支持多个子元素,只有 SOAP 1.2 服务支持。在与我们的 Java 开发团队交谈后,他们发现 Tomcat 中有一个调试设置(或者在 Java 中,我不记得是哪个)允许您将其关闭,因此不包含堆栈跟踪。之后故障被正确传播。抱歉不能提供更多帮助,但它可能会有所帮助。

【讨论】:

    【解决方案3】:

    这是我配置客户端的方式:

    Uri uri = new Uri("http://localhost:8080/JavaWSJMX/KDTreeWSService");
    X509Certificate2 server_cert = new X509Certificate2("C:/../server.cer", "changeit"); //Second param is the certificate's password
    AddressHeader[] ah = new AddressHeader[0];
    EndpointAddress ea = new EndpointAddress(uri, EndpointIdentity.CreateX509CertificateIdentity(server_cert), ah);
    KDTreeWSClient wsClient = new KDTreeWSClient("KDTreeWSPort", ea);
    

    其中KDTreeWSPortendpointConfigurationName,您可以从.config 获得:

    <client>
      <endpoint address="http://localhost:8080/JavaWSJMX/KDTreeWSService"
        binding="customBinding" bindingConfiguration="KDTreeWSPortBinding"
        contract="KDTreeWS" name="KDTreeWSPort" />
    </client>
    

    在这之后你必须设置ClientCredentials:

    //The server uses this certificate
    wsClient.ClientCredentials.ServiceCertificate.DefaultCertificate = server_cert;
    //These are the default credentials on GlassFish v3.1
    wsClient.ClientCredentials.UserName.UserName = "wsitUser";
    wsClient.ClientCredentials.UserName.Password = "changeit";
    

    您应该可以调用您的 METRO 网络服务了!我使用的是 svcutil 生成的代理类,所以我没有创建ServiceReference

    【讨论】:

      猜你喜欢
      • 2011-08-14
      • 2011-09-10
      • 2011-03-26
      • 1970-01-01
      • 2010-09-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多