Web Services Enhancements 3.0 Quick Start(四)

        主要是详细介绍使用WSE3.0建立使用安全的WebService
一、下载WSE3.0,并安装,特别要提的是选择安装的时候选择vs2005开发人员的模式  下载
二、一些理论的知识,可参考控制台关于安全证书的帮助,了解一些必要的基础知识
三、了解两个工具
certmgr.exe    http://msdn2.microsoft.com/zh-cn/library/bfsktky3.aspx
makecert.exe http://msdn2.microsoft.com/zh-cn/library/e78byta0.aspx
四、建立服务器和客户端的证书,在下载示例中(Setup.bat)注意应使用“Visual Studio 2005 命令提示”
五、建立一个WebService和一个客户端调用控制台程序
六、设置WebService配置文件
1、在WebService工程中右键选择WSE settings
2、选择“Enable this for Web Service Enhancement”和“Enable Microsoft Web Service EnhanCement Soap Protocol Factory”
3、选择Policy tab 选择 Enable Policy 并点击Add..
4、填写Policy名称,下一步
5、选择“Secure a service application” 在选择客户端访问方式中选择“Username”下一步
6、选择“Sign and Encrypt” 下一步
7、选择“Select Certificate..”
8、选择“WSEQuickStartServer”证书,下一步
9、完成
七、就能生成web.config和wse3policyCache.config
八、添加 Microsoft.Web.Services3.dll的引用,并在WebSerice类中添加[Policy("ServicePolicy")]
九、在App_Code中添加CustomUsernameTokenManager类,实现UsernameTokenManager接口

None.gif using  System;
None.gif
using  System.Xml;
None.gif
using  System.Security.Permissions;
None.gif
None.gif
using  Microsoft.Web.Services3.Security;
None.gif
using  Microsoft.Web.Services3.Security.Tokens;
ExpandedBlockStart.gifContractedBlock.gif
/**/ /// <summary>
InBlock.gif
/// UsernameTokenManager 的摘要说明
ExpandedBlockEnd.gif
/// </summary>

None.gif public   class  UsernameTokenManager : UsernameTokenManager
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    
public UsernameTokenManager()
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
ExpandedSubBlockEnd.gif    }

InBlock.gif    
public UsernameTokenManager(XmlNodeList nodes)
InBlock.gif        : 
base(nodes)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
ExpandedSubBlockEnd.gif    }

InBlock.gif    
protected override string AuthenticateToken(UsernameToken token)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif
InBlock.gif        
byte[] password = System.Text.Encoding.UTF8.GetBytes(token.Username);
InBlock.gif
InBlock.gif        Array.Reverse(password);
InBlock.gif
InBlock.gif        
return Convert.ToBase64String(password);
ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif

十、实现Web Service

None.gif using  System;
None.gif
using  System.Web;
None.gif
using  System.Web.Services;
None.gif
using  System.Web.Services.Protocols;
None.gif
None.gif
using  Microsoft.Web.Services3;
None.gif
None.gif[WebService(Namespace 
=   " http://tempuri.org/ " )]
None.gif[WebServiceBinding(ConformsTo 
=  WsiProfiles.BasicProfile1_1)]
None.gif[Policy(
" ServicePolicy " )]
None.gif
public   class  Service : System.Web.Services.WebService
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
ExpandedSubBlockStart.gifContractedSubBlock.gif    
public Service () dot.gif{
InBlock.gif
InBlock.gif        
//如果使用设计的组件,请取消注释以下行 
InBlock.gif        
//InitializeComponent(); 
ExpandedSubBlockEnd.gif
    }

InBlock.gif
InBlock.gif    [WebMethod]
ExpandedSubBlockStart.gifContractedSubBlock.gif    
public string HelloWorld() dot.gif{
InBlock.gif        
return "Hello World";
ExpandedSubBlockEnd.gif    }

InBlock.gif    
ExpandedBlockEnd.gif}

None.gif


十一、在客户项目中添加Microsoft.Web.Services3.dll的引用,并添加WebService引用
十二、其中查看Reference.cs中Service中是否继承 Microsoft.Web.Services3.WebServicesClientProtocol
1、选择客户项目右键选择WSE settings
2、选择Policy tab 选择 Enable Policy 并点击Add..
3、填写Policy名称,下一步
4、选择“Secure a client applition”并选择“Username”并下一步
5、选择“sign and Encrypt”下一步
6、选择“Select Certificate...”并选择"WSE2QuickStartServer"下一步并完成就能生成web.config和wse3policyCache.config
十三、在客户端中完成以下

None.gif using  System;
None.gif
using  System.Collections.Generic;
None.gif
using  System.Text;
None.gif
None.gif
using  Emp.localhost;
None.gif
None.gif
using  Microsoft.Web.Services3;
None.gif
using  Microsoft.Web.Services3.Design;
None.gif
using  Microsoft.Web.Services3.Security;
None.gif
using  Microsoft.Web.Services3.Security.X509;
None.gif
using  Microsoft.Web.Services3.Security.Tokens;
None.gif
None.gif
None.gif
namespace  Emp
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    [Policy(
"ClientPolicy")]                                                            //把“ClientPolicy”做为元数据定义
InBlock.gif
    class Program
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
static void Main(string[] args)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            ServiceWse sw 
= new ServiceWse();                                           //不是Service而是ServiceWse,
InBlock.gif
            UsernameToken token = null;                                                 //定义UsernameToken
InBlock.gif
            bool useCorrectPassword = true;                                             // change to false, and the call will fail
InBlock.gif
            string username = Environment.UserName;                                     //获取当前线程的用户 (你也可以自己定义)
InBlock.gif
            byte[] passwordBytes = System.Text.Encoding.UTF8.GetBytes(username);        //用户名的UTF8的格式 
InBlock.gif
            Array.Reverse(passwordBytes);
InBlock.gif
InBlock.gif            
if (useCorrectPassword)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
string passwordEquivalent = Convert.ToBase64String(passwordBytes);      //密码
InBlock.gif
                token = new UsernameToken(username, passwordEquivalent);                //设置用户名和密码
ExpandedSubBlockEnd.gif
            }

InBlock.gif            
else
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                token 
= new UsernameToken(username, "BadPassword");
ExpandedSubBlockEnd.gif            }

InBlock.gif
InBlock.gif            sw.SetClientCredential(token);                                             
//提交客户端的令牌
InBlock.gif
            sw.SetPolicy("ClientPolicy");                                              //设置客户端证书
InBlock.gif

InBlock.gif            Console.WriteLine(
"Calling {0}", sw.Url);
InBlock.gif            Console.WriteLine(sw.HelloWorld());
InBlock.gif            Console.WriteLine(
"Press [Enter] to continuedot.gif");
InBlock.gif            Console.ReadLine();
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif
十四、总结
主要讲述利用WSE3.0构建安全的WebService,可以看出WSE3.0主要是建立配置文件和加入元数据就能实现安全,使用WSE3.0以一种比较优美的模式来完成WebService的安全,达到业务逻辑和安全分开,可以对现有的或者新项目平滑的达到WebService的安全

源码下载 

转载于:https://www.cnblogs.com/jiekeng/archive/2006/11/08/554545.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: Spring Boot 3.0 is a major release that introduces a number of new features and improvements over previous versions. Some of the key features and enhancements include: 1. Java 16 Support: Spring Boot 3.0 now supports Java 16 and its new features, allowing developers to take advantage of the latest advancements in the Java platform. 2. Improved Actuator Endpoints: The Actuator endpoints have been improved to provide more detailed information about the application and its environment, making it easier to monitor and troubleshoot applications. 3. New Testing Features: Spring Boot 3.0 introduces several new testing features, including a new TestRestTemplate, support for testing with H2 databases, and improved support for testing with testcontainers. 4. Faster Startup Time: Spring Boot 3.0 has been optimized to start up faster, reducing the time it takes to get an application up and running. 5. Improved Security: Spring Boot 3.0 includes a number of security improvements, such as improved support for OAuth 2.0 and JWT, and improved support for securing RESTful APIs. 6. Better Support for Cloud-Native Deployments: Spring Boot 3.0 provides better support for cloud-native deployments, including improved support for Kubernetes and improved support for service discovery with Eureka. 7. Improved Performance: Spring Boot 3.0 has been optimized for better performance, with improvements in the handling of large numbers of requests and improved memory usage. These are some of the key new features and enhancements in Spring Boot 3.0. If you are looking to upgrade from an earlier version of Spring Boot or are just starting a new project, it is definitely worth considering this latest release. ### 回答2: 目前为止,还没有发布Spring Boot 3.0版本,因此无法提供确切的新特性。不过,可以根据过去版本的趋势和社区的需求,推测一些可能的新特性。 1. 支持最新的Java版本:随着Java的不断更新,Spring Boot 3.0可能会支持最新的Java版本,以提供更高的性能和安全性。 2. 更强大的自动化配置功能:Spring Boot以其自动化配置功能闻名,3.0版本可能会增加更多的自动化配置选项,减少开发人员的配置工作,加快项目的启动速度。 3. 更好的响应式和异步编程支持:近年来,响应式和异步编程成为了开发者关注的热门话题,Spring Boot 3.0可能会进一步改进响应式和异步编程的支持,以满足这方面的需求。 4. 更强大的监控和管理功能:随着分布式系统的兴起,对于监控和管理系统的需求也越来越高。Spring Boot 3.0可以提供更强大的监控和管理功能,以便于开发人员更好地了解和维护系统的状态。 5. 更多的集成和插件支持:Spring Boot生态系统非常丰富,与各种开发框架和工具的集成和插件支持是其受欢迎的原因之一。预计Spring Boot 3.0会进一步增加对各种框架和工具的集成和插件支持,以便于开发人员更好地利用现有的资源。 以上只是对于可能的新特性的猜测,具体的特性还需要根据Spring Boot官方发布的版本来确认。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值