的SOAPHeader认证 [英] soapheader authentication
本文介绍了的SOAPHeader认证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我不能让我的客户reconise AuthHeaderValue它的Visual Studio增加了代理类
我见过很多例子,但能找到如何解决这个没什么。
皂类
公共类AuthHeader:SOAPHEADER
{
公共字符串用户名;
公共字符串密码; }
Web服务
公共类服务:System.Web.Services.WebService
{
公共AuthHeader认证; **在哪里呢Visual Studio的附加价值代理 [SOAPHEADER(验证,必需=真)
[的WebMethod]
公共字符串的安全()
{
如果(Authentication.Username ==测试和放大器;&安培;
Authentication.Password ==测试)
{
返回认证;
}
其他
{
返回迷失
}
}
客户端
静态无效的主要(字串[] args)
{
ServiceReference1.AuthHeader AUTH =新ServiceReference1.AuthHeader();
auth.Username =测试;
auth.Password =测试; ServiceReference1.Service1SoapClient SER =新ServiceReference1.Service1SoapClient();
ser.AuthHeaderValue =权威性; **不reconise authheadervalue
字符串消息= ser.security();
Console.WriteLine(消息); }
解决方案
WebService的服务=新的WebService();
service.Authentication.Username =一个;
service.Authentication.Password =一个;
字符串str =服务.CheckAuthn();
应用是code
I cannot get my client to reconise AuthHeaderValue which visual studio adds to proxy class I have seen many examples but could find nothing on how to resolve this.
Soap class
public class AuthHeader : SoapHeader
{
public string Username;
public string Password;
}
web service
public class Service1 : System.Web.Services.WebService
{
public AuthHeader Authentication; ** where does visual studio append value to proxy
[SoapHeader("Authentication", Required = true)]
[WebMethod]
public string security()
{
if (Authentication.Username == "test" &&
Authentication.Password == "test")
{
return "authenticated";
}
else
{
return "get lost";
}
}
client
static void Main(string[] args)
{
ServiceReference1.AuthHeader auth = new ServiceReference1.AuthHeader();
auth.Username = "test";
auth.Password = "test";
ServiceReference1.Service1SoapClient ser = new ServiceReference1.Service1SoapClient();
ser.AuthHeaderValue = auth; ** does not reconise authheadervalue
String message = ser.security();
Console.WriteLine(message);
}
解决方案
WebService service = new WebService();
service.Authentication.Username = "a";
service.Authentication.Password = "a";
string str = service .CheckAuthn();
Apply that code
这篇关于的SOAPHeader认证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文