3

次のコードで C# XmlDocument クラスを使用して、eBay FindingAPI Web サービスへの SOAP 要求を作成しようとしています。

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";

そして、上記のコードの XML 出力は次のとおりです。

<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>

ただし、findItemsByKeywordsRequest 要素に追加の xmlns="" 属性があるため、この XML はサーバーによって認識されません。目的の XML 出力は次のようになります。

<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>

私のコードの問題を知っている人はいますか?ヒントを教えてください。ありがとう!

4

1 に答える 1