Android 上的 SOAP 网络服务 [英] SOAP web service on android
问题描述
我正在尝试使用 ksoap2 库连接到 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客户端来测试webservice我还需要把它放在soap 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>
我的其余代码类似于这个方法
The rest of my code is similar to this approach
模拟器需要一些时间来处理,所以我假设它联系了服务器,但是调用 ...call crases with:
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.任何关于这个方向的指针也将不胜感激.
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.
非常感谢,伙计们.
干杯,亚历克斯
推荐答案
我遇到了同样的问题,为此我按照以下方式创建了 Header,
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 网络服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!