1

我正在尝试为 WCF WS-Security 部署 Android 3.0 客户端。WCF WS 将用户名令牌实现为安全访问。我使用 KSOAP2,访问 asmx 服务没有问题,但是当我尝试调用 WCF WS 时,应用程序会抛出此异常:

javax.net.ssl.SSLHandshakeException:java.security.cert.CertPathValidatorException:找不到证书路径的信任锚。

看起来这是一个证书凭据,但我已将服务器凭据添加到我的项目使用的密钥库中。

这是我客户的代码:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    System.setProperty("http.keepAlive", "false");
    try {
    /**String NAMESPACE = "http://tempuri.org/";
    String URL = "http://**host**/ObtenerDatos/ServicioDatos.asmx";
    String METHOD_NAME = "SumadorDatos";
    String SOAP_ACTION = "http://tempuri.org/SumadorDatos";*/
    String NAMESPACE = "https://tempuri.org/";
    String URL = "http://**host**//WCFServicio/SWObtenerDatos.svc";
    URL url = new URL(URL);
    String METHOD_NAME = "MetodoEnWS";
    String SOAP_ACTION = "http://tempuri.org/IObtenerDatos/MetodoEnWS";
    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);      
    request.addProperty("xmlPeticion","dato");
    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    envelope.dotNet = true;
    envelope.setOutputSoapObject(request);
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();     
    StrictMode.setThreadPolicy(policy); 

    KeepAliveHttpsTransportSE transporte = new KeepAliveHttpsTransportSE(url.getHost(),url.getPort(),"",6000);
    try{

        transporte.call(SOAP_ACTION, envelope);

    try {
        SoapPrimitive resultado = (SoapPrimitive)envelope.getResponse();
        String res = resultado.toString();
        TextView tv = new TextView(this);
        tv.setText("El Resultado es: " + res);       
        setContentView(tv);
    } catch (SoapFault e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } 
    } catch (MalformedURLException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    } 
    }catch(Exception ex){
        ex.printStackTrace();
        this.closeContextMenu();
    }


}

第二个问题。

我不知道如何将用户名令牌和密码发送到服务器。我必须为自己添加标题创建一个肥皂信封,还是存在像 .net 这样的方法,在其中我给出用户名的值并传递给特定对象?

4

1 回答 1

0

要将属性添加到标题中,您必须执行以下操作:

     Element[] header = new Element[2];  
     header[0] = new Element().createElement(NAMESPACE, "username");                 
     header[0].addChild(Node.TEXT, "Your username");

     header[1] = new Element().createElement(NAMESPACE, "password");                
     header[1].addChild(Node.TEXT, "Your Password");

     envelope.headerOut = header;                                 

对于证书,您可以添加以下行:

HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
    conn.setHostnameVerifier(new HostnameVerifier() {
        @Override
        public boolean verify(String arg0, SSLSession arg1) {
            return true;
        }
    });

所以你接受所有证书

于 2012-06-24T10:11:42.007 回答