2011-04-03 27 views
1

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

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

如何设置安全的.NET?我一直在阅读METRO指南,但是我只发现指向这些例子的链接不完整,指南并未让我知道。我成功地生成了代理类svcutil,但我不知道如何使用它。

SvcUtil工具警告:

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

警告2自定义工具警告:wsam:寻址元素需要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吗?

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

+0

这里是一个链接似乎讨论类似的情况:http:///forums.asp.net/t/1277956.aspx – 2011-04-06 19:04:38

回答

1

尝试为波纹管

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

描述正如“xwssecurityserver” DNS值设置DNS身份在客户端应用程序的配置文件。在我的情况下,它的工作原理(顺便说一句,我用你的问题作为解决这个问题的基础,所以感谢您指出正确的方式:))

+0

谢谢!您的答案似乎更好,因为之后我的方法会导致服务器证书验证出现一些问题。 – 2011-05-02 19:04:44

0

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

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"; 

而你笑你可以打电话给你的麦德龙网站服务!我使用的svcutil生成的代理类,所以我没有做一个ServiceReference