【问题标题】:How can I validate a SOAP Request如何验证 SOAP 请求
【发布时间】:2009-12-11 15:23:37
【问题描述】:

是否有一种快速验证 SOAP 消息的方法?我见过 JSON 对象的验证器。 SOAP 有这样的东西吗?我收到一个“错误请求:400”错误响应,其中包含我正在处理的 AJAX 帖子。我对 SOAP 不太熟悉,因为我通常只传递 JSON。有人可以告诉我我的请求有什么问题,或者可能建议一种自己调试的好方法吗? Firebug 错误消息只是 'Bad Request: 400' 这并没有真正的帮助。

<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:Body>
        <UpdateAutoChart xmlns='http://somewhere.org/hwconnect/services' soap:encodingStyle='http://schemas.xmlsoap.org/soap/encoding'>alertid=Test&companytoken=hw&autochart=false</UpdateAutoChart>
    </soap:Body>
</soap:Envelope>

这是我的 POST 函数:

function doPost(method, body) {
    var soapRequest = "<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' ";
    soapRequest = soapRequest + "xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>";
    soapRequest = soapRequest + "<soap:Body>"
    soapRequest = soapRequest + "<" + method + " xmlns='http://somewhere.org/hwconnect/services' soap:encodingStyle='http://schemas.xmlsoap.org/soap/encoding'>"; 
    soapRequest = soapRequest + body;
    soapRequest = soapRequest + "</" + method + ">";
    soapRequest = soapRequest + "</soap:Body></soap:Envelope>";
    jQuery.noConflict();
    jQuery.ajax({
        beforeSend: function(xhrObj) {
            xhrObj.setRequestHeader("Method", "POST");
            xhrObj.setRequestHeader("Content-Type", "text/xml; charset=\"utf-8\";");
            xhrObj.setRequestHeader("SOAPAction", "http://somewhere.org/hwconnect/services/" + method);
        },
        async: false,
        type: "POST",
        url: theURL,
        contentType: "text/xml; charset=\"utf-8\";",
        data: soapRequest,
        error: function(XMLHttpRequest, textStatus, errorThrown) {
            alert("XMLHttpRequest Failure: " + XMLHttpRequest.statusText);
        }
    });
}

【问题讨论】:

  • 另外,查看线路并发布实际发送的完整 XML。

标签: c# asp.net javascript ajax soap


【解决方案1】:

这可能不是 SOAP 问题,而是您发布数据的方式的问题:

400 error explained

我会检查您发送的最终 HTTP 标头以验证它们是否正确(尤其是数据大小)

【讨论】:

  • 去看看标题..谢谢
【解决方案2】:

我不知道 json 但soapaction 标头应该是这样的


SOAPAction: "myaction"

所以行:


xhrObj.setRequestHeader("SOAPAction", "http://somewhere.org/hwconnect/services/" + method);

应该看起来像这样是正确的:


xhrObj.setRequestHeader("SOAPAction", "\"http://somewhere.org/hwconnect/services/" + method + "\"");

【讨论】:

    猜你喜欢
    • 2016-01-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多