Windows phone 7 Windows Phone的SOAP头

Windows phone 7 Windows Phone的SOAP头,windows-phone-7,soap,Windows Phone 7,Soap,我在向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"

我在向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> 

您是否收到任何特定的错误消息?实际上,我收到了来自服务器的自定义回复,表示我发送的数据不正确,但用户名和密码确实存在(与fiddler一起检查)使用Fiddler,我能够手动修改SOAP消息,以准确地找出SOAP中哪些不正确。使用Fiddler,我可以准确地找出SOAP消息中哪些不正确。“>Fiddler非常适合追踪此类问题。所以我想你现在知道问题是什么了吧?
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;
}
private void callWebservice()
{
    NetworkCredential credentials = new NetworkCredential(userName, Password, domain);
    HttpWebRequest request = CreateWebRequest(url, credentials);
    XDocument soapEnvelope = CreateSoapEnvelope(soapEnvelope );
    InsertSoapEnvelopeIntoWebRequest(soapEnvelope, request);
}

private static HttpWebRequest CreateWebRequest(string url, NetworkCredential credentials)
   {
        string action = link;// my action link
        HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(url);
        req.Credentials = credentials;
        req.Headers["SOAPAction"] = action;
        req.ContentType = "text/xml;charset=\"utf-8\"";
        req.Accept = "text/xml";
        req.Method = "POST";
        return req;
    }

private static XDocument CreateSoapEnvelope(string content)
{
    XDocument soapEnvelopeXml = XDocument.Parse(content);
    return soapEnvelopeXml;
}

private static void InsertSoapEnvelopeIntoWebRequest(XDocument soapEnvelopeXml,                          HttpWebRequest webRequest)
{
    webRequest.BeginGetRequestStream((IAsyncResult asynchronousResult) =>
    {
        HttpWebRequest request = (HttpWebRequest)asynchronousResult.AsyncState;
        Stream postStream = request.EndGetRequestStream(asynchronousResult);
        soapEnvelopeXml.Save(postStream);
        postStream.Close();

        request.BeginGetResponse(new AsyncCallback(GetResponseCallback), request);
    }, webRequest);
}