为了安全,使用带验证的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();
浙公网安备 33010602011771号