您的位置:首页 > 其它

带验证信息的web服务

2007-06-20 14:51 183 查看
为了安全,使用带验证的Web服务。Web服务是给予Soap协议和xml的。验证可以通过SOAP报头条目完成。如:

//soapheader
设置用户名和密码

public class HeadAuthentication : SoapHeader

{

public string username;

public string password;

}

在web 服务类中:

public[w1] Authgeader myheader;

[WebMethod]

[SoapHeader("myheader",Direction=SoapHeaderDirection.In,Required=true)]

public
string HelloWorld() {

if
(myheader.user == "wwb" &&
myheader.pws == "123")

{

return
"Hello World";

}

else

{

return
"hello Guest";

}

}

客户端:添加web服务

testws.Service myws = new WindowsApplication5.testws.Service();

testws.Authgeader myheader = new WindowsApplication5.testws.Authgeader()

myheader.user = "wwb";

myheader.pws = "123";

myws.AuthgeaderValue[w2] = myheader;

textBox1.Text=myws.HelloWorld();

[w1]必须是public,如果不加的话,会出现错误。为什么这样?

[w2]把Soap头添加,必须有这个,否则会报错。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: