public SoapPrimitive detail;
// 命名空间
private static final String NAMESPACE = "http://tempuri.org/";
//webservice地址
private static String WebServiceURL = "http://www.xxx.com/Services/xxx.asmx";
//此处是命名空间+方法名
private static String SOAP_ACTION = "http://tempuri.org/GetComapnyXML";
//WSDL文档中的URL
private static final String WSDL="http://www.xxx.com/Services/xxxx.asmx?wsdl";
private OnClickListener calc = new OnClickListener() {
@Override
public void onClick(View v) {
//第一个参数是命名空间第二个参数是要调用的方法
SoapObject request = new SoapObject(NAMESPACE, "GetComapnyXML");
/* 第一种传参,参数名不一定要于webservice参数统一,但一定要按顺序
request.addProperty("StartCount", "1");
request.addProperty("EndCount", "2");
request.addProperty("jobCount", "2");
*/
 
/* 第二种传参 */
PropertyInfo pi = new PropertyInfo();
pi.setName("StartCount");
pi.setValue("1");
request.addProperty(pi);
pi = new PropertyInfo();
pi.setName("EndCount");
pi.setValue("2");
request.addProperty(pi);
pi = new PropertyInfo();
pi.setName("jobCount");
pi.setValue("2");
request.addProperty(pi);
 
Element[] header = new Element[1];
header[0] = new Element().createElement(NAMESPACE, "CompanyToken");
//如果有多个按下面一样写法
Element pwd = new Element().createElement(NAMESPACE, "CompanyKey");
pwd.addChild(Node.TEXT, "密码");
header[0].addChild(Node.ELEMENT, pwd);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.headerOut = header;
envelope.bodyOut = request;
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
//HttpTransportSE ht = new HttpTransportSE(WebServiceURL);
AndroidHttpTransport httpTranstation=new AndroidHttpTransport(WSDL);
try {
//ht.call(SOAP_ACTION, envelope);
httpTranstation.call(SOAP_ACTION, envelope);
detail = (SoapPrimitive) envelope.getResponse();
TextConten.setText(detail.toString());
} catch (IOException e) {
// TODO Auto-generated catch block
//e.printStackTrace();
Log.e(this.toString(),e.toString());
//Toast.makeText(WebserviceTestActivity.this,
// "文件流错误" + e.toString(), Toast.LENGTH_LONG);
} catch (XmlPullParserException e) {
// TODO Auto-generated catch block
e.printStackTrace();
//Toast.makeText(WebserviceTestActivity.this,
// "XML文件流错误" + e.toString(), Toast.LENGTH_LONG);
} catch (Exception e) {
// TODO: handle exception
//Toast.makeText(WebserviceTestActivity.this,
// "错误" + e.toString(), Toast.LENGTH_LONG);
Log.e(this.toString(),e.toString());
}
}
};

 

<?xml version="1.0" encoding="utf-8"?>
<soap:Header>
<CompanyToken xmlns="http://tempuri.org/">
<CompanyKey>string</CompanyKey>
</CompanyToken>
</soap:Header>
<soap:Body>
<GetComapnyXML xmlns="http://tempuri.org/">
<StartCount>string</StartCount>
<EndCount>string</EndCount>
<jobCount>string</jobCount>
</GetComapnyXML>
</soap:Body>