【发布时间】:2011-01-03 18:42:10
【问题描述】:
我正在尝试使用在 .NET 中创建的需要 SOAP 身份验证的 Web 服务。您最感兴趣的部分是:
<s:element name="SoapAuthenticationHeader" type="tns:SoapAuthenticationHeader" />
<s:complexType name="SoapAuthenticationHeader">
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="Username" type="s:string" />
<s:element minOccurs="0" maxOccurs="1" name="Password" type="s:string" />
</s:sequence>
<s:anyAttribute />
</s:complexType>
我能够成功使用 Netbeans 中的 Web 服务。但我无法使用它,因为在自动生成的存根/方法中,我无法输入用户名和密码进行身份验证。
Netbeans 自动生成的存根包括以下内容:
JAX-WS
try { // Call Web Service Operation
org.tempuri.TeleCast service = new org.tempuri.TeleCast();
org.tempuri.TeleCastSoap port = service.getTeleCastSoap();
// TODO initialize WS operation arguments here
int campaignid = 0;
java.lang.String to = "";
java.lang.String from = "";
java.lang.String subject = "";
java.lang.String body = "";
java.lang.String uniqueid = "";
// TODO process result here
boolean result = port.queueRealTimeEmail(campaignid, to, from, subject, body, uniqueid);
System.out.println("Result = "+result);
} catch (Exception ex) {
// TODO handle custom exceptions here
}
JAX-RPC
try { // This code block invokes the TeleCastSoap:queueRealTimeEmail operation on web service
telecastclient.TeleCast teleCast = new telecastclient.TeleCast_Impl();
telecastclient.TeleCastSoap teleCastSoap = teleCast.getTeleCastSoap();
teleCastSoap.queueRealTimeEmail(/* TODO enter operation arguments*/);
} catch(javax.xml.rpc.ServiceException ex) {
java.util.logging.Logger.getLogger(telecastclient.TeleCast.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch(java.rmi.RemoteException ex) {
java.util.logging.Logger.getLogger(telecastclient.TeleCast.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch(Exception ex) {
java.util.logging.Logger.getLogger(telecastclient.TeleCast.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
至少当我使用 JAX-WS 方法时,我得到了一个名为 SoapAuthenticationHeader 的类,我可以在其中设置用户名和密码。但我不知道如何在调用 Web 服务之前或期间传递 SoapAuthenticationHeader 对象以执行各种操作。
org.tempuri.SoapAuthenticationHeader auth = new SoapAuthenticationHeader();
auth.setUsername("username");
auth.setPassword("password");
我在 JAX-RPC 方法中没有这个选项。
对此的任何意见将不胜感激。提前感谢您的宝贵时间。
【问题讨论】:
标签: java web-services authentication soap header