最近在做一个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>

解决方案 »

  1.   

    调用以下代码,解析出现问题,报xmlStreamReader错误,请各位大侠帮忙看看:
    // 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();
    }
      

  2.   

    下面代码是访问后服务器产生的日志,求各位大侠帮忙解决下
    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>