您的位置:首页 > 其它

应用WSDK - 实践Web Services的数字签名(下)

2002-12-10 09:07 357 查看
应用WSDK - 实践Web Services的数字签名<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

 

小气的神

2002-12-05

 

Article Type: In-Depth 

难度等级:8.2/9       

版本:1.36
 
 生成客户端部分

1.      创建一个WinForm的Windows Application

 
2.      创建用户界面
 




<?xml:namespace prefix = v ns = "urn:schemas-microsoft-com:vml" />
3.      加入Web Services的引用。

 

cd/tmp
wsdl /l:cs /out:SignSOAPWebServices.cs /n:SignSOAPSvc /urlkey:SecurityURL http://localhost/Myproject/WSDK/SignSOAPUsingName/SignSOAPusingName.asmx?WSDK
 
然后点击Add Exit Item->选择Tmp目录->加入SignSOAPWebServices.cs 文件确定。
 

4.      修改SignSOAPWebServices.cs 文件

 

加入Microsoft.WebServices.DLL 引用和下面的代码
using Microsoft.Web.Services.Security ;
using Microsoft.Web.Services;
 

并将 System.Web.Services.Protocols.SoapHttpClientProtocol 替换为
 Microsoft.Web.Services.WebServicesClientProtocol
 

5.      在Form1中加入调用 Web Services的代码

 

private void btnCallWebservice_Click(object sender, System.EventArgs e)

{

     try

     {

         string username = Environment.UserName ;

         byte[] passwordBytes = System.Text.Encoding.UTF8.GetBytes( username ) ;

 

         Array.Reverse( passwordBytes ) ;

 

         string passwordEquivalent = Convert.ToBase64String( passwordBytes ) ;

 

         UsernameToken userToken = new UsernameToken( username, passwordEquivalent, PasswordOption.SendHashed ) ;

        

         SignSOAPSvc.SignSOAPWebServices  Svc = new SignSOAPSvc.SignSOAPWebServices() ;

        

         Svc.RequestSoapContext.Timestamp.Ttl = 60000 ;

        

         Svc.RequestSoapContext.Security.Tokens.Add( userToken ) ;

        

         Svc.RequestSoapContext.Security.Elements.Add( new Signature( userToken ) ) ;

        

         lblCallRet.Text = Svc.HelloWorld() ;

 

     }

     catch ( System.Web.Services.Protocols.SoapException soapex )

     {

         MessageBox.Show ( soapex.ToString() ) ;

     }

     catch ( Exception ex )

     {

         MessageBox.Show( ex.ToString() ) ;

     }

}
 

6.      编译并运行程序
 


 

 
分析结果

之后我们使用 SOAP Toolkit 3.0 的Trace Utility 进行观察可以发现下面的Dump

 



 

 



 
看得出我们整个的过程是这样的:
 



 

       综上所叙述,我们看到我们能够利用WSDK实现Web Services有关Security的实现,最重要的是WS-Security对于Web Services安全性方面提供了一个高层和最基本的定义。
 
“WS-Security is flexible and designed to be used as the basis for securing XML Web services through the combination of a wide variety of security models, including public key infrastructure (PKI), Kerberos, and Secure Sockets Layer (SSL). Correspondingly, many types of security tokens can be propagated, such as X.509 certificates and Kerberos tickets. Additionally, the specification provides support for propagating multiple security tokens across multiple trust domains using multiple signature formats and multiple encryption technologies.”
 

 
        好吧,我很愿意用这段话说明WS-Security也愿意用这段话作为本文的结束,看得出Web Services 安全性的问题非常复杂和有趣,我想还有许多许多新的内容在等着我们。

 

相关文件下载: [WSDKSignSOAPUsing.zip 26K]

 

特别:

本文原创,CSDN署名首发,所有文字和图片版权所有。未经授权请勿传播、转载或改编。

如果有问题或建议,请发电子邮件给new2001@msn.com

欢迎访问我的WebSite:www.dotNETTools.org

 

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息