web服务-如何在javascript中处理soap错误

web services - How to handle soap fault in javascript

本文关键字:处理 soap 错误 javascript 服务 web      更新时间:2023-09-26

嗨,我正在使用javascript调用.net中的web服务。我使用http请求调用web服务,我想处理javascript中的soap错误,如何处理??

您可以使用jQuery Soap,这是一个使用Soap 与web服务通信的插件

此脚本使用$.ajax发送SOAP:Envelope。它可以接受XML DOM、XML字符串或JSON作为输入,响应也可以作为XML DOM、XML字符串或JSON返回。

我还没有尝试过,但它看起来很健壮,很容易上手。

示例:

$.soap({
    url: 'http://my.server.com/soapservices/',
    method: 'helloWorld',
data: {
    name: 'Remy Blom',
    msg: 'Hi!'
},
success: function (soapResponse) {
    // do stuff with soapResponse
    // if you want to have the response as JSON use soapResponse.toJSON();
    // or soapResponse.toString() to get XML string
    // or soapResponse.toXML() to get XML DOM
},
error: function (SOAPResponse) {
    // show error
}
});

来源:https://github.com/doedje/jquery.soap