2012-05-29 54 views
1

我正在嘗試爲WCF WS-Security部署Android 3.0客戶端。 WCF WS將用戶名令牌實現爲安全訪問。 我用KSOAP2和我沒有問題,進入到一個ASMX服務,但是當我嘗試撥打電話到WCF WS應用程序將引發此異常:用於WCF的Android客戶端使用用戶名令牌進行wshttp綁定

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


} 

第二個問題。

我不知道如何發送到服務器的用戶名令牌和密碼到服務器。我是否必須爲自己添加標題創建一個soap信封,或者是否存在像.net這樣的方法,其中給出用戶名的值並將其傳遞給特定的對象?

回答

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

所以你接受所有證書