WebService中两种访问验证方法
在和BPM对接时,要用到验证. 对BPM内部的验证不了解, 不知道采用了什么方式. 经一周多的测试,得出结果,现总结如下:
验证方式1.
IIS用户验证.
H3BPM采用此模式验证
IIS用户验证是指发布WebService后,在WS代码中没有采取验证,而是WS的运行平台IIS中设置验证.

这样设置后, 在访问时,会提示用户和密码. 基于WINDOWS的用户密码.
这种验证方式的代码调用时如何传入参数值:
//要引入System.Net using System.Net //测试IIS 验证 Token test = new Token(); //实例WebService NetworkCredential nc = new NetworkCredential() //实例一个WINDOWS验证的类,并赋值 { UserName = "00519", Password = "1015" }; test.Credentials = nc; //把定义的验证类型赋值给WebService //输出结果 string aa = test.HelloWorld(); Response.Write(aa);
如果用户验证通过,就调用方式成功.
验证方式2
SOAP协议验证.
WS服务端如下设置:
在WS的方法顶部,WebMethod下面加入标记,并定义一个公共类来接收SOAP
[WebMethod] [System.Web.Services.Protocols.SoapHeader("authentication")] //标记是带SOAP头的 public string HelloWorld() { Validate validate = new Validate(); //实例验证方法 return validate.ValidateSoapHeader(authentication); } public Authentication authentication = new Authentication(); //注意,这里必须定义一个公共类,来接收传入的SOAP协议头信息
定义一个验证用户密码的类
//定义SOAPHeader,包含用户和密码 public class Authentication : System.Web.Services.Protocols.SoapHeader { public Authentication() { } public Authentication(string SystemCode, string Secret) { this.SystemCode = SystemCode; this.Secret = Secret; } public string SystemCode { get; set; } public string Secret { get; set; } }
定义一个验证方法,对传进来的SOAP标记验证,怎么验证, 这块自己搞就行.
public class Validate { public string ValidateSoapHeader(Authentication authentication) { string result = "测试成功"; if (authentication == null) { result = "请输入身份认证信息!"; return result; } bool YN = this.Engine.SSOManager.ValidateSSOSystem(authentication.SystemCode, authentication.Secret); if (!YN) { result = "帐号或密码不正确!"; } return result; // this.Engine = UserValidator.Engine; // this.Engine = OThinker.H3.WorkSheet.AppUtility.Engine; } }
在客户端调用时如下:
在引用了WEB服务后, 先实例化验证类,并赋值. 然后装类型一起传到WS中.
protected void Button2_Click(object sender, EventArgs e) { //测试SOAPHEADER验证 Authentication myHeader = new Authentication(); //soaphead头定义 myHeader.SystemCode = "RiChen111"; myHeader.Secret = "richen.com"; ERPInsert test = new ERPInsert(); //实例WS类 test.AuthenticationValue = myHeader; //SOAP头赋值,传入WS中 //输出结果 string aa = test.HelloWorld(); Response.Write(aa); }

浙公网安备 33010602011771号