2010-08-25 148 views
2

我正在尝试使用kso​​ap2库连接到SOAP Web服务。我已经阅读了一堆关于它的文档,但由于我的请求不是普通的,我被卡住了。android上的SOAP web服务

我需要在发送请求之前指定一些标头。

时是使用SOAP客户端来测试Web服务我也需要把这个肥皂enveope头部分:

<SOAP-ENV:Header> 
<mns:AuthIn xmlns:mns="http://enablon/wsdl/" 
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> 
<UserInfo xsi:type="wsdlns:AuthHeader"> 
    <EnaHomeSite xsi:type="xsd:string">sss</EnaHomeSite> 
    <EnaUserName xsi:type="xsd:string">sadsa</EnaUserName> 
    <EnaPassword xsi:type="xsd:string">qwertf</EnaPassword> 
</UserInfo> 
</mns:AuthIn> 
</SOAP-ENV:Header> 

我的代码的其余部分与this方法

模拟器需要一点时间来进动,所以我认为它与服务器联系,但电话到...叫crases有:

org.xmlpull.v1.XmlPullParserException: expected: END_TAG {http://schemas.xmlsoap.org/soap/envelope/}Body (position:END_TAG </{http://schemas.xmlsoap.org/soap/envelope/}SOAP-ENV:Fault>@1:505 in [email protected]) 

我的问题是我如何重视上面提到的标题符合我的要求?

我没有设法为ksoap罚款漂亮的文档。也许一些教程或例子。任何人都可以指点我一些文档。我找到了javadoc,但它非常薄。

我也尝试格式化我自己的原始HTTP请求。 (设法在iPhone上这样做,它工作得很好)。不过,我似乎无法添加请求的主体。我的意思是包含所有标题名称空间和所需的数据调用的大肥皂xml。任何指向这个方向的指针也将非常感激。

非常感谢,伙计们。

干杯, 亚历

回答

3

我也遇到过同样的问题,为此,我已在以下方式创建头,


public static Element[] addheader() 
    { 
      Element[] header = new Element[1]; 
      header[0] = new Element().createElement("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd","Security"); 
      header[0].setAttribute(null, "mustUnderstand","1"); 
      Element usernametoken = new Element().createElement("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", "UsernameToken"); 
      // usernametoken.addChild(Node.TEXT,""); 
      usernametoken.setAttribute("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd", "Id", "UsernameToken-4"); 
      header[0].addChild(Node.ELEMENT,usernametoken); 
      Element username = new Element().createElement(null, "n0:Username"); 
      username.addChild(Node.TEXT, "username_value"); 
      //username.setPrefix("n0", null); 
      usernametoken.addChild(Node.ELEMENT, username); 
      Element pass = new Element().createElement(null, "n0:Password"); 
      //pass.setPrefix("n0",null); 
      pass.setAttribute(null, "Type", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText"); 
      pass.addChild(Node.TEXT, "password_value"); 

      usernametoken.addChild(Node.ELEMENT, pass); 
      return header; 
    } 

,并添加此头为soapEnvelope.headerOut = addheader();

因为它为我工作,如果应该为你工作。

+0

仍然我无法get.Same错误我越来越 – Raj008 2014-03-21 19:16:52