C# 无法使用C上的soap标头#
我正在使用C#.Net2将soap消息传输到我的web服务 soap消息是:C# 无法使用C上的soap标头#,c#,web-services,soap,header,soapheader,C#,Web Services,Soap,Header,Soapheader,我正在使用C#.Net2将soap消息传输到我的web服务 soap消息是: <?xml version="1.0"?> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <
<?xml version="1.0"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<AUTHHEADER xmlns="http://mysite.com/WebServices/Agent">
<AgentGUID>24563532-c973-fbf3-d072-d9cf671d5905</AgentGUID>
</AUTHHEADER>
</soap:Header>
<soap:Body>
<LoginRSA xmlns="http://mysite.com/WebServices/Agent">
<loginId>admin@dt.com</loginId>
<password>password</password>
<tenant></tenant>
</LoginRSA>
</soap:Body>
</soap:Envelope>
但是我的身份验证总是空的,我不能读取头,但是我得到了soap:body中的所有变量
你能看出我的错误吗?
谢谢。关于XML名称如何映射到类型/字段名称,我找不到太多详细信息,现在我也无法通过实验轻松找到它,但请尝试将类型名称和/或字段名称更改为
AUTHHEADER
。看看这是否改变了什么。@TimS。我不太明白您想要什么,我尝试了许多操作,但都失败了。我将用示例代码作为答案。
public class AuthHeader : SoapHeader
{
public string AgentGUID;
}
[WebService(Namespace = "http://mysite.com/WebServices/Agent", Description = "Some description")]
public class AgentService : WebService
{
public AuthHeader Authentication;
[SoapHeader("Authentication")]
[WebMethod(Description = "SomeDesc.", MessageName = "LoginRSA")]
public LoginResult LoginRSA(string loginId, string password, string tenant)
{
if (Authentication != null)
{
string guid = Authentication.AgentGUID;
}
}
}