QtSoap:无法使用QDomDocument创建Soap消息?返回故障消息

时间:2014-01-16 08:40:17

标签: xml web-services qt soap

我正在尝试使用 QDomDocument 创建一条肥皂消息。但每次都会返回错误消息

这是我生成Soap消息的代码:

    {
    QDomDocument domDoc;

    domDoc.setPrefix("soapenv");

    QDomElement root = domDoc.createElement("Envelope");
    domDoc.appendChild(root);

    QDomElement tag = domDoc.createElement("Header");
    root.appendChild(tag);

    tag.setAttribute("receiver", "Printer1");
    tag.setAttribute("sender", "Host");

    QDomElement body = domDoc.createElement("Body");
    root.appendChild(body);

    QDomElement chngOperatingMode = domDoc.createElement("ChangeOperatingMode");
    chngOperatingMode.setAttribute("act", 50001);
    body.appendChild(chngOperatingMode);

    QDomElement operatingMode = domDoc.createElement("OperatingMode");
    chngOperatingMode.appendChild(operatingMode);

    QDomText tval = domDoc.createTextNode("1");
    operatingMode.appendChild(tval);


    QString xml = domDoc.toString();

    qDebug() << "xml data = \n" << xml ;

    request.clear();
    bool retval = request.setContent(domDoc);
    qDebug() << "Soap xml = \n " << request.toXmlString();
    }

上面代码使用 domDoc.toString()生成的XML是:

<Envelope>
 <Header sender="Host" receiver="Printer1"/>
 <Body>
   <ChangeOperatingMode act="50001">
     <OperatingMode>1</OperatingMode>
   </ChangeOperatingMode>
 </Body>
</Envelope>

上述代码作为肥皂消息的输出是:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/1999/XMLSchema">
<SOAP-ENV:Body xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Fault xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<Faultcode xsi:type="xsd:string" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance">SOAP-ENV:VersionMismatch</Faultcode>
<Faultstring xsi:type="xsd:string" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance">SOAP structure invalid</Faultstring>
<SOAP-ENV:Faultdetail xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<extra xsi:type="xsd:string" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance">Unsupported namespace for envelope element</extra>
</SOAP-ENV:Faultdetail>
</SOAP-ENV:Fault>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

任何人都可以帮我纠正错误吗?

请提供您的建议和意见。

0 个答案:

没有答案