最近在做一个android调用 webservice 的测试demo,如果是不带请求表头的,采用引入ksoap第三方jar包已经实现,做请求表头的时候,提示读取xml错误:Error reading XMLStreamReader.请各位大侠帮忙解决下,谢谢。
下面是请求的表头,利用cxf写的webservice,求支持,谢谢。
<soap:Header>
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" soap:mustUnderstand="1">
<wsse:UsernameToken wsu:Id="UsernameToken-1">
<wsse:Username>admin</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">admin</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</soap:Header>
下面是请求的表头,利用cxf写的webservice,求支持,谢谢。
<soap:Header>
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" soap:mustUnderstand="1">
<wsse:UsernameToken wsu:Id="UsernameToken-1">
<wsse:Username>admin</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">admin</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</soap:Header>
解决方案 »
- Android 开发问题:关于Excel导入数据库
- Android 请问如何更改android 数据库的存储路径?数据库存储默认路径为/data/data/databases 我想把它存到sdcard,如何做?
- android上部署web app问题
- 跪求一份社区客户端的产品设计方案,和 服务器源码(最好能有微博功能)
- 在listview中edittext控件的setOnFocusChangeListener问题
- myeclipse怎么搭建android2.2环境
- android的测试时候,需要在AndroidManifest.xml文件里添加什么?
- 大家来帮我看看有这种可能性吗
- Eclipse右键没有断点调试toggle breakpoint
- 安卓开发
- Android如何通过USB和PC进行TCP通讯
- android 求启动Calendar的通用方法
// webservice 访问URL
String serviceUrl = "http://192.168.0.200:8088/CxfService/UserService?wsdl";
// namespace
String NameSpace = "com.htxx.service";
// 调用的方法
String methodName = "getSomething";
//命名空间+方法名
String SOAP_Action = NameSpace + methodName;
// 实例化SoapObject对象
SoapObject request = new SoapObject(NameSpace, methodName);
// 设置参数,参数名不一定需要跟调用的服务器端的参数名相同,只需要对应的顺序相同即可
request.addProperty("arg0", "test");
//soapHeader
Element[] header = new Element[1];
header[0] = new Element().createElement(NameSpace, "wsse:UsernameToken");
Element userName = new Element().createElement(NameSpace, "wsse:Username");
userName.addChild(Node.TEXT, "admin");
header[0].addChild(Node.ELEMENT, userName);
Element pass = new Element().createElement(NameSpace, "wsse:Password");
pass.addChild(Node.TEXT, "admin");
header[0].addChild(Node.ELEMENT, pass);
//
// 使用soap1.0 协议创建Envelop对象
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER10);
envelope.headerOut=header;
envelope.bodyOut = request;
//envelope.dotNet = false;
// 将SoapObject对象设置为SoapSerializationEnvelope对象的传出SOAP消息
envelope.setOutputSoapObject(request);
// 创建httpTransportSE传输对象
HttpTransportSE ht = new HttpTransportSE(serviceUrl);
//ht.debug = true;
try {
// 调用webService
ht.call(SOAP_Action, envelope);
if (envelope.getResponse() != null) {
//detail =(SoapPrimitive) envelope.getResponse();
SoapObject result = (SoapObject) envelope.bodyIn;
String name = result.getProperty(0).toString();
} else {
}
} catch (Exception e) {
System.out.println("wenti--------");
e.printStackTrace();
}
Headers: {connection=[close], Content-Length=[538], content-type=[text/xml], host=[192.168.0.200:8088], SOAPAction=[com.htxx.servicegetSomething], user-agent=[kSOAP/2.0]}
Payload: <v:Envelope xmlns:i="http://www.w3.org/1999/XMLSchema-instance" xmlns:d="http://www.w3.org/1999/XMLSchema" xmlns:c="http://schemas.xmlsoap.org/soap/encoding/" xmlns:v="http://schemas.xmlsoap.org/soap/envelope/"><v:Header><n0:wsse:UsernameToken xmlns:n0="com.htxx.service"><n0:wsse:Username>admin</n0:wsse:Username><n0:wsse:Password>123</n0:wsse:Password></n0:wsse:UsernameToken></v:Header><v:Body><n1:getSomething id="o0" c:root="1" xmlns:n1="com.htxx.service"><arg0 i:type="d:string">test</arg0></n1:getSomething></v:Body></v:Envelope>