我需要设置SOAP头信息的Web方法验证的一部分。我使用的的 ksoap2 的 API来调用.NET Web服务。下面是请求SOAP头。
I need to set the soap header information as part of authentication of a web method. I'm using ksoap2 API to call .NET web service. Here is the soap header with request.
<soap:Header>
<DTHeader xmlns="http://myServer.com/webservices/">
<Username> string </Username>
<Password> string </Password>
</DTHeader>
</soap:Header>
<soap:Body>
<MyTestMethod xmlns="http://myServer.com/webservices/">
<ID> string </ID>
<TransID> guid </TransID>
</MyTestMethod>
</soap:Body>
您可以请提供安卓code设置SOAP头DTHeader,并设置用户名和密码。
Can you please provide the android code to set the soap header "DTHeader" and set "Username" and "Password".
我这样做,是这样的:
import org.kxml2.kdom.Element;
然后同时preparing信封
then while preparing envelope
soapEnvelope.headerOut = new Element[1];
soapEnvelope.headerOut[0] = buildAuthHeader();
// ...send request...
与
private Element buildAuthHeader() {
Element h = new Element().createElement(NAMESPACE, "AuthHeader");
Element username = new Element().createElement(NAMESPACE, "user");
username.addChild(Node.TEXT, USERNAME);
h.addChild(Node.ELEMENT, username);
Element pass = new Element().createElement(NAMESPACE, "pass");
pass.addChild(Node.TEXT, PASSWORD);
h.addChild(Node.ELEMENT, pass);
return h;
}
显然,根据需要改变的字符串。
obviously, change strings as needed.
上一篇:Android的手机短信接收器不工作接收器、手机短信、工作、Android
下一篇:有没有办法直接使用SpeechRecognizer API进行语音输入?没有办法、语音、直接、SpeechRecognizer