webService
需要用到的IPA
1.SoapObject:这个用来设置webService的接口,里面放网页地址,几你需要的请求的选项;
2.SoapSerializationEnvelope:生成调用WebService方法的SOAP请求信息,并指定SOAP的版本;
3.HttpTransportSE:调用webService
调用webService的主要步骤:
1.定义地址,及需要的选项;
2.调用实例化SoapObject,将地址及选项放入它的两个参数中;
3.给SoapObject添加信息,要服务器端的信息要对应;
4.实例化SoapSerializationEnvelope,这个是Soap请求信息,确定其版本;
5.调用SoapSerializationEnvelope的API(bodyOut,dotNet ,setOutputSoapObject);
6.实例化HttpTransportSE ,里面参数为URL;
7.调用HttpTransportSE 的API(debug,call(子线程中执行));
8.获取返回的数据;
9.得到返回的结果;
public String webService_UserReg(String SN, String OrderProductType, String OrderProductVersion, String DealerName,
String CUnitName, String CUnitProvince, String CUnitCity, String CUnitCounty, String CUnitAddress,
String CUnitPost, String CUnitOwnner, String CustomerName, String CustomerJob, String CustomerNameTel,
String CustomerNameFax, String Mobile, String Email, int cType) throws Exception {
final String SOAP_ACTION = LedictUtil.NAMESPACE + "UserReg"; //http://tech.ledict.com/
String METHOD_NAME = "UserReg";
SoapObject rpc = new SoapObject(LedictUtil.NAMESPACE, METHOD_NAME);//设置需调用WebService接口
rpc.addProperty("SN", SN);// 4107cdd4080221cb
rpc.addProperty("CUnitProvince", CUnitProvince);//北京市
rpc.addProperty("CUnitCity", CUnitCity); //市辖区
rpc.addProperty("CUnitCounty", CUnitCounty); //东城区
final SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
// 生成调用WebService方法的SOAP请求信息,并指定SOAP的版本
envelope.bodyOut = rpc;
envelope.dotNet = true;
envelope.setOutputSoapObject(rpc); //这个是将这些数据插入到服务器
Log.i("TAG", "envelope"+envelope);
final HttpTransportSE ht = new HttpTransportSE(LedictUtil.URL);
// "http://tech.ledict.com/tax.asmx"
ht.debug = true;//是否是调试模式
new Thread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
try {
ht.call(SOAP_ACTION, envelope);//调用webService
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (XmlPullParserException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}).start();
// ht.call(SOAP_ACTION, envelope); //这里报错啦
//ht.call(LedictUtil.NAMESPACE+METHOD_NAME, envelope);
SoapObject detail = (SoapObject) envelope.bodyIn;//获取返回的数据
String result = detail.getProperty("UserRegResult").toString();//得到返回的结果
return result;
}