在Android SOAP的Web服务 [英] SOAP web service on android

查看:181
本文介绍了在Android SOAP的Web服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在尝试连接到使用kso​​ap2库中的SOAP Web服务。我读了一堆关于它的文档,但我坚持我的要求是不是一般人。

I am am trying to connect to a SOAP web service using ksoap2 library. I have read a bunch of docs about it, but i am stuck as my request is not an ordinary one.

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

I need to specify some headers prior to sending the request.

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

when is use a soap client to test the webservice i also need to put this in the soap enveope header section:

<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>

我的code,其余类似于这种方法

模拟器需要一点时间来precess,所以我认为它与服务器联系,而是调用...叫crases有:

The emulator takes a bit of time to precess so i assume it contacts the server, but the call to ...call crases with:

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 java.io.InputStreamReader@43ef45e8) 

我的问题是我如何重视上述我的要求中提到的头?

My question is how do i attach the header mentioned above to my request?

我没能很好的罚款文档的KSOAP。也许一些教程或例子。任何人都可以点我一些文件。我已经找到了javadoc的,但它是相当薄的。

I didn't manage to fine nice doc for ksoap. maybe some tutorials or examples. can anyone point me to some docs. I have found the javadoc, but it is rather thin.

我也试图格式化自己的原始HTTP请求。 (成功地做到这一点在iPhone和它工作得很好)。不过,我似乎无法能够添加请求的身体。我的意思是包含所有标题命名空间和所需的数据呼叫的大SOAP XML。在这个方向的任何指针会也备受AP preciated。

I have also tried to format my own raw HTTP request. (managed to do so on iPhone and it works just fine). However i can't seem to be able to add the body of the request in. I mean the big soap xml containing all headers namespaces and required data for the call. Any pointer on this direction would be also much appreciated.

非常感谢,伙计们。

干杯, 亚历克斯

推荐答案

我也遇到过同样的问题,对于我在下面的方式创建头,

I have encountered same issue and for that i have created Header in following way,

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();

由于这是为我工作,如果要为你工作。

As it is working for me, if should work for you.

这篇关于在Android SOAP的Web服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆