/**
* 设置webservice头部传入参数
* @param userName 用户名
* @param userPwdMD5 密码
* @return
*/
public Element[] setHeader(String userName,String userPwdMD5)
{
Element[] header = new Element[1];
header[0] = new Element().createElement(NAMESPACE, "AuthAPI");
Element username = new Element().createElement(NAMESPACE, "UserName");
username.addChild(Node.TEXT, userName);
header[0].addChild(Node.ELEMENT, username);
Element pass = new Element().createElement(NAMESPACE, "PassWord");
pass.addChild(Node.TEXT, userPwdMD5);
header[0].addChild(Node.ELEMENT, pass);
System.out.println("Header:"+header[0].getChildCount());
return header;
}
/**
* 带有信息头(授权)的取得返回数据方法
* @param methodName webservice方法名
* @param userName 登录用户名
* @param userPwdMD5 以MD5加密的用户密码
* @return webservice返回的数据
*/
public Object getSoap(String methodName,String userName,String userPwdMD5)
{
SoapObject rpc = new SoapObject(NAMESPACE, methodName);
setSoapProperty(rpc);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER12);
envelope.headerOut = this.setHeader(userName, userPwdMD5);
envelope.bodyOut = rpc;
envelope.dotNet = true;
// envelope.
envelope.setOutputSoapObject(rpc);
HttpTransportSE ht = new HttpTransportSE(URL);
try
{
ht.call(NAMESPACE + "/" + methodName, envelope);
return envelope.getResponse();
} catch (SoapFault e)
{
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
} catch (XmlPullParserException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
这只是初学菜鸟测试使用的,有问题帮忙改正,谢谢。 |
|