当前位置:首页 > 芯闻号 > 充电吧
[导读]遇到问题记录一下: 1.手机访问电脑web的,记得关闭防火墙!2.不要使用localhost,指定IP地址.import org.ksoap2.SoapEnvelope; import org.kso

遇到问题记录一下: 1.手机访问电脑web的,记得关闭防火墙!2.不要使用localhost,指定IP地址.

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.MarshalBase64;
import org.ksoap2.serialization.SoapObject;  
import org.ksoap2.serialization.SoapSerializationEnvelope;  
import org.ksoap2.transport.HttpTransportSE;  

public void onClick_Event(View view) 
	{
		TextView txt1 = (TextView)findViewById(R.id.textView1);
String nameSpace = "http://192.168.0.103/soap/updateserver";  
// 调用的方法名称   
String methodName = "getVersion";  
String phoneSec = "12312321323";
// EndPoint   
String endPoint = "http://192.168.0.103/php/index.php?wsdl";  
// SOAP Action   
String soapAction = "http://192.168.0.103/php/index.php/getVersion";  
 
// 指定WebService的命名空间和调用的方法名   
SoapObject rpc = new SoapObject(nameSpace, methodName);  
 
// 设置需调用WebService接口需要传入的两个参数mobileCode、userId   
rpc.addProperty("appcode", phoneSec);  

 
// 生成调用WebService方法的SOAP请求信息,并指定SOAP的版本   
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER10);  
  
envelope.bodyOut = rpc;  
// 设置是否调用的是dotNet开发的WebService   
envelope.dotNet = false;  
// 等价于envelope.bodyOut = rpc;   
envelope.setOutputSoapObject(rpc);  
 
HttpTransportSE transport = new HttpTransportSE(endPoint);  
try {  
    // 调用WebService   
    transport.call(soapAction, envelope);  
    
    // 获取返回的数据   
SoapObject object = (SoapObject) envelope.bodyIn;  
// 获取返回的结果   
if(object !=null){
String result = object.getProperty(0).toString(); 
	// 将WebService返回的结果显示在TextView中   
	   txt1.setText(result);  
	}
} catch (Exception e) 
{  
	txt1.setText(e.getMessage().toString());
	e.printStackTrace();  
    return ;
}  
}
本站声明: 本文章由作者或相关机构授权发布,目的在于传递更多信息,并不代表本站赞同其观点,本站亦不保证或承诺内容真实性等。需要转载请联系该专栏作者,如若文章内容侵犯您的权益,请及时联系本站删除( 邮箱:macysun@21ic.com )。
换一批
延伸阅读
关闭