I'm trying to compose a SOAP request to ebay FindingAPI web service by using C# XmlDocument class in the following code:
XmlDocument doc = new XmlDocument();
XmlElement root = (XmlElement)doc.AppendChild(doc.CreateElement("soap", "Envelope", "http://www.w3.org/2003/05/soap-envelope"));
root.SetAttribute("xmlns", "http://www.ebay.com/marketplace/search/v1/services");
XmlElement header = (XmlElement)root.AppendChild(doc.CreateElement("soap", "Header", "http://www.w3.org/2003/05/soap-envelope"));
XmlElement body = (XmlElement)root.AppendChild(doc.CreateElement("soap", "Body", "http://www.w3.org/2003/05/soap-envelope"));
XmlElement request = (XmlElement)body.AppendChild(doc.CreateElement("findItemsByKeywordsRequest"));
XmlElement param = (XmlElement)request.AppendChild(doc.CreateElement("keywords"));
param.InnerText = "harry potter phoenix";
And, the XML output of above code is:
<soap:Envelope xmlns="http://www.ebay.com/marketplace/search/v1/services" xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
<soap:Header />
<soap:Body>
<findItemsByKeywordsRequest xmlns="">
<keywords>harry potter phoenix</keywords>
</findItemsByKeywordsRequest>
</soap:Body>
</soap:Envelope>
However, this XML can't be recognized by the server because of the extra xmlns="" attribute in the findItemsByKeywordsRequest element. The desired XML output should be as below:
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns="http://www.ebay.com/marketplace/search/v1/services">
<soap:Header/>
<soap:Body>
<findItemsByKeywordsRequest>
<keywords>harry potter phoenix</keywords>
</findItemsByKeywordsRequest>
</soap:Body>
</soap:Envelope>
Does anyone know what is the problem of my code and please give me some hints. Thanks!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…