1,在AdroidManifest.xml中加入权限
<uses-permission android:name="android.permission.INTERNET"/>
2,导入ksoap2包
3,private String NameSpace="命名空间";
private String Url="---.asmx";//WebService发布地址
private String MethodName="方法名";
private String SoapAction="命名空间/方法名";
private SoapObject request=null;
private SoapPrimitive result=null;//要注意result类型
private SoapSerializationEnvelope envelope=null;
private HttpTransportSE androidHttpTransport=null;
4,androidHttpTransport=new HttpTransportSE(Url);
androidHttpTransport.debug=true;
request=new SoapObject(NameSpace,MethodName);
request.addProperty("para1","zy");
request.addProperty("para2","123");
envelope=new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet=true;//表示不用rpc方式
envelope.setOutputSoapObject(request);
envelope.bodyOut=request;
try{
androidHttpTransport.call(SoapAction, envelope);
result=(SoapPrimitive)envelope.getResponse();
String sb;
sb=result.toString();
Toast.makeText(this, "result is"+sb, Toast.LENGTH_SHORT).show();
}
catch(Exception e)
{
Log.e(TAG,"WebService Failed",e);
return;
}
※※※※※※※※※※※※※※--我的程序人生--※※※※※※※※※※※※※※