我在将标头信息添加到 SOAP 消息时遇到问题。任何人都知道如何以正确的方式做到这一点?
我成功地添加了 Authenticator 部分,但仍然无法在 Authenticator 中添加用户名和密码,如下所示。您还可以看到下面的 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;
}