Titanium 使用suds.js库时如何设置超时

Titanium 使用suds.js库时如何设置超时,titanium,Titanium,我正在从事SOAPWebservices的工作,正在调用Tianium。我只想为请求设置超时,这样,如果数据不在规定的时间内,我就可以显示正确的消息。现在我正在显示加载消息,因为没有超时,它正在显示加载,直到数据到来 以下是代码: var soap_client = new soap({ endpoint : Alloy.Globals.url, targetNamespace : 'xyz' }); //调用web服务 Alloy.Globals.callWebService = funct

我正在从事SOAPWebservices的工作,正在调用Tianium。我只想为请求设置超时,这样,如果数据不在规定的时间内,我就可以显示正确的消息。现在我正在显示加载消息,因为没有超时,它正在显示加载,直到数据到来

以下是代码:

var soap_client = new soap({
endpoint : Alloy.Globals.url,
targetNamespace : 'xyz'
});
//调用web服务

Alloy.Globals.callWebService = function(soap_action, post_data, callback) {

if (Titanium.Network.online) {

    Alloy.Globals.showIndicator();

    soap_client.invoke(soap_action, post_data, function(xmlDoc) {
        if (xmlDoc) {
            var xml = new XMLTools(xmlDoc);
            callback(xml);
        } else {
            Alloy.Globals.hideIndicator();
            Alloy.Globals.showAlert("No data found!");
        }
    });
} else {
    Alloy.Globals.showAlert("No internet connection!");
}
};
感谢您的帮助。
谢谢。

我建议不要使用外部setTimeout方法,但您应该编辑soap库并在库代码中设置timeout属性。

将timeout参数传递给soap构造函数应该可以解决一个问题:

var soap_client = new soap({
    endpoint : Alloy.Globals.url,
    targetNamespace : 'xyz',
    timeout: 1000
});
您可以在以下位置检查可能参数的完整列表及其默认值:


作为补充说明,使用XMLHttpRequest对象从Tianium应用程序发出Http请求是非常不寻常的,我建议在当前模块的基础上寻找模块构建/创建自己的模块/分叉当前模块,并用Tianium.Network.HTTPClient替换XMLHttpRequest。

您能告诉我如何使用吗?我尝试将timeout属性与endpoint和targetNamespace一起传递,但不知道对于可能支持的参数,该属性是否存在+1。然而,我尝试过这个,但不认为它是工作。它没有任何超时的效果。您能告诉我如何在这里捕获超时异常吗?因为我的代码中没有任何try-catch-only-if-else。@RoshanJha我用我的想法编辑了我的答案,如何从Tianium SDK获取超时回调+关于XMLHttpRequest而不是HTTPClient奇怪用法的小旁注。
// Client Configuration
var config = extend({
    endpoint:'http://localhost',
    targetNamespace: 'http://localhost',
    envelopeBegin: '<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:ns0="PLACEHOLDER" 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/">',
    headerBegin: '<soap:Header>',
    headerNode:'head',
    headerEnd: '</soap:Header>',
    bodyBegin:'<soap:Body>',
    envelopeEnd: '</soap:Body></soap:Envelope>',
    timeout: 5000, 
    responseType: 'object'
},_options);
xhr = soap_client.getXHR();
xhr.ontimeout = function() {
    console.log('Timeout');
}