3
我在將標頭信息添加到SOAP消息時遇到問題。任何人有一個關於如何以正確的方式做到這一點的想法?適用於Windows Phone的SOAP標頭
我成功地添加了Authenticator部件,但仍然無法在Authenticator中添加UserName和Password,如下所示。你也可以看到下面的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;
}
您是否收到任何具體的錯誤消息? – DaveHogan
我實際上從服務器得到了一個自定義答覆,說我發送的數據不正確,但用戶名和密碼實際存在(用提琴手檢查) – user1747573
使用Fiddler我已經能夠手動修改SOAP消息以準確找出什麼在不正確的SOAP。 – user1747573