我在添加SOAP消息头信息时遇到了问题。有没有人知道如何正确地添加它呢?
我成功地添加了验证器部分,但仍然无法像下面展示的那样在验证器内添加用户名和密码。您可以看到下面的C#代码!
<?xml version="1.0" encoding="utf-8"?>
<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>
<Authenticator xmlns="http://www.namespacename.com/services/">
<UserName>string</UserName>
<Password>string</Password>
</Authenticator>
</soap:Header>
<soap:Body>
<ListItems xmlns="http://www.namespacename.com/services/">
<strCode>string</strCode>
</ListItems>
</soap:Body>
</soap:Envelope>
C# 代码
var client = new MySoapClient();
client.GetListCompleted += (a, b) =>
{
var list = b.Result;
};
using (OperationContextScope scope = new OperationContextScope(client.InnerChannel))
{
MessageHeader header = MessageHeader.CreateHeader("Authenticator", "http://......./", credentials);
OperationContext.Current.OutgoingMessageHeaders.Add(header);
client.GetListAsync(App.CouponCampaignCode);
}
public class _ServiceCredential
{
[XmlAttribute(Form = System.Xml.Schema.XmlSchemaForm.None)]
[DataMember(Order = 2)]
public string Password;
[DataMember(Order = 1)]
[XmlAttribute(Form = System.Xml.Schema.XmlSchemaForm.None)]
public string UserName;
}