1

我有一个安全的 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 子元素,但没有子元素。

编辑

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

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手动吗?

任何帮助,将不胜感激!在此先感谢,丹尼尔

4

3 回答 3

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”。就我而言,它有效(顺便说一下,我在解决此问题时将您的问题作为基础,所以感谢您指出正确的方法:))

于 2011-04-21T08:08:54.620 回答
0

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

于 2011-04-06T05:55:30.283 回答
0

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

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-04-08T16:21:41.930 回答