2015-05-31 72 views
-1

我需要使用身份驗證訪問Web服務。他們給我SOAP和WSDL。我可以在SoapUI中輸入用戶名/密碼並獲得迴應。他們告訴我他們在Web服務中使用基本身份驗證。但是用戶名和密碼如何傳輸?使用htp:// xxx/xxxService?userId = & password =?或者是在Soap消息中保存的用戶名/密碼?使用基本身份驗證訪問Web服務

我該如何處理由wsimport生成的客戶端代碼中的用戶名/密碼?我可以在哪裏輸入它們?

我正在使用jax-ws,wsgen和wsimport來訪問服務。

+0

你是谷歌嗎? http://en.wikipedia.org/wiki/Basic_access_authentication –

+0

沒有違法,但這個問題太寬... 基本名稱auth ..當然...什麼是你使用的框架?只有基於此,解決方案是不同的......說你正在使用軸..那麼它是壘......如果你使用spring-ws ......那麼你使用spring stack ..請,當你提出問題時,添加一些上下文.... – witchedwiz

+0

我用戶Jax-WS,wsgen和wsimport。 – user3376741

回答

0

我不是專家,但是我自己,如果您使用基本身份驗證與JAX-WS,您可以使用

Authenticator myAuth = new Authenticator(){ 
     @Override 
     protected PasswordAuthentication getPasswordAuthentication() 
     { 
      String user="user",pass="pass"; 
      return new PasswordAuthentication(user, pass.toCharArray()); 
     } 
    }; 

    Authenticator.setDefault(myAuth); 

我把這個方法裏面的actionPerformed(ActionEvent的AE),當我打電話的動作一個按鈕,它工作得很好。我讀過這是一個安全風險,但對於基本測試,它的工作非常好。

相關問題