Android手機(jī)調(diào)用筆記本電腦的webservices
遇到問題記錄一下: 1.手機(jī)訪問電腦web的,記得關(guān)閉防火墻!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";??
//?調(diào)用的方法名稱???
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的命名空間和調(diào)用的方法名???
SoapObject?rpc?=?new?SoapObject(nameSpace,?methodName);??
?
//?設(shè)置需調(diào)用WebService接口需要傳入的兩個(gè)參數(shù)mobileCode、userId???
rpc.addProperty("appcode",?phoneSec);??
?
//?生成調(diào)用WebService方法的SOAP請(qǐng)求信息,并指定SOAP的版本???
SoapSerializationEnvelope?envelope?=?new?SoapSerializationEnvelope(SoapEnvelope.VER10);??
??
envelope.bodyOut?=?rpc;??
//?設(shè)置是否調(diào)用的是dotNet開發(fā)的WebService???
envelope.dotNet?=?false;??
//?等價(jià)于envelope.bodyOut?=?rpc;???
envelope.setOutputSoapObject(rpc);??
?
HttpTransportSE?transport?=?new?HttpTransportSE(endPoint);??
try?{??
????//?調(diào)用WebService???
????transport.call(soapAction,?envelope);??
????
????//?獲取返回的數(shù)據(jù)???
SoapObject?object?=?(SoapObject)?envelope.bodyIn;??
//?獲取返回的結(jié)果???
if(object?!=null){
String?result?=?object.getProperty(0).toString();?
//?將WebService返回的結(jié)果顯示在TextView中???
???txt1.setText(result);??
}
}?catch?(Exception?e)?
{??
txt1.setText(e.getMessage().toString());
e.printStackTrace();??
????return?;
}??
} 




