身份验证KSOAP2请求到Android的.NET Web服务 [英] Authentication in KSOAP2 request to .NET webservice in Android

查看:447
本文介绍了身份验证KSOAP2请求到Android的.NET Web服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图访​​问安全的.NET SOAP Web服务的Andr​​oid应用程序,使用KSOAP2库。我已经检查了对堆栈溢出其他的答案,但至今没有人帮助我。

I am trying to access a secure .NET SOAP webservice in an Android app, using the KSOAP2 library. I have checked for other answers on Stack Overflow, but so far none of them have helped me.

一个用户名和密码,以核实身份。该方法还需要一个字符串,并返回一个复杂类型。我已经得到了这个用相同的,但不安全的服务工作(即没有用户名/密码,但经过串并返回复杂类型的正常工作)。

A username and password are required for authentication. The method also takes a String and returns a complex type. I have gotten this to work with an identical but unsecure service (ie, no username/password, but passing String and returning complex type works fine).

我可以连接到使用的soapUI安全的Web服务。我所要做的就是通过了SoapUI请求属性给它正确的字符串参数,设置用户名和密码,并设置了WSS-PasswordType为PasswordText。

I can connect to the secure webservice using soapUI. All I have to do is give it the correct String parameter, set the username and password through the SoapUI request properties, and also set the WSS-PasswordType to "PasswordText".

我感到困惑的是如何通过我的Java code来实现这一目标。 soapUI的请求(其中工程)看起来是这样的:

I am confused about how to achieve this through my Java code. The SoapUI request (which works) looks like this:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">
   <soapenv:Header><wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
        <wsse:UsernameToken wsu:Id="UsernameToken-1" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
        <wsse:Username>(my username) </wsse:Username>
        <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">(my password) </wsse:Password>
        <wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">eic5EdyTomcBLocwyph5Mw==</wsse:Nonce>
        <wsu:Created>2012-02-08T09:47:55.225Z</wsu:Created>
        </wsse:UsernameToken></wsse:Security>
    </soapenv:Header>
   <soapenv:Body>
      <tem:GetClientByNationalID>
          <!--Optional:-->
         <tem:nationalID>(the nationalID) </tem:nationalID>
      </tem:GetClientByNationalID>
   </soapenv:Body>
</soapenv:Envelope>

我想我应该可以通过用户名和密码,在SOAP头,然后让我尝试下面的这个答案但这并没有工作。然后我用[拉​​利特的答案](http://stackoverflow.com/questions/3564467/soap-wev-service-on-android)下面编辑我的请求,头尽量使其等同于了SoapUI产生的请求,但我仍然得到同样的错误。这里是我的code现在生产:

I figured I should be passing username and password in the Soap header then so I tried following this answer but this didn't work. I then used [Lalit's answer] (http://stackoverflow.com/questions/3564467/soap-wev-service-on-android) below to edit the header of my request to try to make it identical to the SoapUI-generated request, but I am still getting the same error. Here is what my code is now producing:

<v:Envelope xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:d="http://www.w3.org/2001/XMLSchema" xmlns:c="http://schemas.xmlsoap.org/soap/encoding/" xmlns:v="http://schemas.xmlsoap.org/soap/envelope/">
    <v:Header>
    <n0:Security mustUnderstand="1" xmlns:n0="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
        <n0:UsernameToken n1:Id="UsernameToken-1" xmlns:n1="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
            <n0:Username>(my username)</n0:Username>
            <n0:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">(mypassword)</n0:Password>
            <n0:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">eic5EdyTomcBLocwyph5Mw==</n0:Nonce>
            <wsu:Created>2012-02-08T09:47:55.225Z</wsu:Created>
        </n0:UsernameToken>
    </n0:Security>
</v:Header>
<v:Body>
    <GetClientByNationalID xmlns="http://tempuri.org/" id="o0" c:root="1">
        <nationalID i:type="d:string">(testnationalID)</nationalID>
    </GetClientByNationalID>
</v:Body>

这是错误,我仍然得到在LogCat中:

This is the error I'm still getting in LogCat:

02-10 10:53:49.261: W/System.err(1187): javax.net.ssl.SSLHandshakeException:
java.security.cert.CertPathValidatorException: Trust anchor for certification path
not found.

这使它看起来像一个证书的问题,所以我进口证书从服务器InstallCert并验证了keytool,它是在我的密钥库中。这并没有区别。在另一方面,我认为这不是一个证书的问题,因为了SoapUI工作之前,我不得不安装了证书。

This makes it look like a certificate issue, so I imported the cert from the server with InstallCert and verified with Keytool that it's in my keystore. This made no difference. On the other hand, I assume it's not a certificate issue since SoapUI worked before I had that cert installed.

现在我很困惑,所以这里是我的问题:

Now I'm confused, so here are my questions:

1)添加证书到的cacerts密钥存储在我的JRE的lib /安全性不够,或者我需要写一些Java code到再访问此证书?

1) Is adding the cert to the cacerts keystore in my JRE lib/security enough, or do I need to write some Java code to then access this cert?

2)这是一个证书的问题可言,如果了SoapUI能够成功连接到Web服务没有我安装证书?

2) Is this a cert issue at all, if SoapUI was able to connect successfully to the webservice without me installing the cert?

3)。如果它不是一个证书的问题,任何人都可以提出建议什么样的code,我需要用它来制作,这将成功进行身份验证,然后执行该方法调用的SOAP请求?我presume这让我的java制作的请求看起来尽可能相似的了SoapUI产生的请求的情况下。

3) If it's not a cert issue, can anyone advise on what kind of code I need to use to produce a Soap request that will successfully authenticate and then execute the method call? I presume this is a case of getting my java-produced request to look as similar as possible to the SoapUI-generated request.

推荐答案

您可以创建标题元素,并添加验证信息,

You can create the Header element and add the Authentication details,

Element[] header = new Element[1];
header[0] = new Element().createElement(NAMESPACE,"AuthHeader");

添加用户名标签使用用户名,

Element username = new Element().createElement(NAMESPACE, "username_tag");
username.addChild(Node.TEXT, "username_value");
header[0].addChild(Node.ELEMENT, username);

添加标签的密码与密码,

Element password = new Element().createElement(NAMESPACE, "password_tag");
password.addChild(Node.TEXT, "password_value");
header[0].addChild(Node.ELEMENT, password);

添加标题为 SoapSerializationEnvelope

SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope
                                                                         .VER11);
envelope.dotNet = true;
envelope.headerOut = header;
envelope.setOutputSoapObject(request);

这篇关于身份验证KSOAP2请求到Android的.NET Web服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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