我正在尝试使用在.NET中创建的Web服务,该服务需要SOAP身份验证。您最感兴趣的部分是:
<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方法中没有这个选项。
对此的任何意见将不胜感激。提前感谢您的时间。
答案 0 :(得分:0)
在默认的Netbeans IDE中,似乎没有优雅的方法来执行此操作。
我正在尝试使用Eclipse,在我的所有搜索中,我都是这个 Apache Axis2 - 用于Eclipse Eclipse插件的代码生成器向导指南(我仍然无法发布链接因为我是新手)。
在使用上面的插件(WSDL2Java的某种eclipse附加组件)时,它生成了存根以及适当的SoapAuthenticationHeader对象,我可以传递这些对象进行验证。
所以我的代码现在是:
TeleCastStub stub = new TeleCastStub();
SoapAuthenticationHeader auth = new SoapAuthenticationHeader();
auth.setUsername(username);
auth.setPassword(password);
QueueRealTimeEmail pageObj = new QueueRealTimeEmail();
pageObj.setFrom(from);
pageObj.setTo(to);
pageObj.setSubject(subject);
pageObj.setBody(body);
SoapAuthenticationHeaderE authE = new SoapAuthenticationHeaderE();
authE.setSoapAuthenticationHeader(auth);
QueueRealTimeEmailResponse response = stub.queueRealTimeEmail(pageObj, authE);
它运作得很好。
现在这引出了一些问题:
再次感谢你的时间。
这个伟大的董事会,所以!已经多次保存我的隐藏。所以轮到我现在回馈社区。 p>