Titanium中SOAPClient访问SOAP协议的WebService

     在Titanium中通过SOAP类库调用SOAP协议的:

app.js代码如下:

/*
 * Single Window Application Template:
 * A basic starting point for your application.  Mostly a blank canvas.
 * 
 * In app.js, we generally take care of a few things:
 * - Bootstrap the application with any data we need
 * - Check for dependencies like device type, platform version or network connection
 * - Require and open our top-level UI component
 *  
 */

//bootstrap and check dependencies
if (Ti.version < 1.8 ) {
	alert('Sorry - this application template requires Titanium Mobile SDK 1.8 or later');
}
else if (Ti.Platform.osname === 'mobileweb') {
	alert('Mobile web is not yet supported by this template');
}
else {
	//require and open top level UI component
	//导入相关的UI
	//var ApplicationWindow = require('ui/ApplicationWindow');
	var win= Titanium.UI.createWindow();

	Titanium.include('suds.js');
	var b1 = Ti.UI.createButton({
		title:'调用SOAP协议',
		width:100,
		top:'10',
		height:40,
		left:10
	});
	
	win.add(b1);
   var msg = Ti.UI.createLabel({
	    color:'white',
		text:'结果',
		width:'auto',
		height:'auto',
		top:'50',
		left:10
	});
	
	win.add(msg);
	
	b1.addEventListener('click', function() {
        //请求SOAP协议的url
		var url = "http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx";
		//请求参数
		var callparams = {
			mobileCode:'13811047044',
			userId:''
		};
		//创建SOAP请求对象
		var suds = new SudsClient({
		    endpoint: url,
		    //请求的命名空间
		    targetNamespace: 'http://WebXml.com.cn/' 
		});
		var methodName='getMobileCodeInfo';
		try {
			//第一个参数方法名,第二个请求参数,第三个回调函数
		    suds.invoke(methodName, callparams, function(xmlDoc) {
		    	//SOAP 响应的结果信息的xml节点
		        var results = xmlDoc.documentElement.getElementsByTagName('getMobileCodeInfoResult');
		        if (results && results.length>0) {
		            var result = results.item(0);
		           msg.text = ' ' + result.text + '';
		        } else {
		             msg.text = 'Oops, could not determine result of SOAP call.';
		        }
		    });
		} catch(e) {
		    Ti.API.error('Error: ' + e);
		}

	});
	
	
	win.open();
	
}

 

你可能感兴趣的:(webservice)