我已經爲我需要使用的SOAP Web服務提供了wsdl。我已經使用wsdl在netbeans中創建webservice類。使用NetBeans生成的WebService類將ServiceAuthHeader添加到SOAP消息中
SOAP Header需要一個包含用戶名和密碼的ServiceAuthHeader。
NetBeans確實生成了一個ServiceAuthHeader類,但我不知道如何將它添加到使用生成的類發送的SOAP消息中。
我知道如何在較低層次上做到這一點,即創建一個SOAPMEssage,添加頭,連接到服務併發送它,但我從來沒有使用jws之前,在哪裏完成了基本的任務,我正在努力找出我在任何文檔或教程中添加它的位置。
的ServiceAuthHeader產生是這樣的:
package com.theservice.webservice;
import java.util.HashMap;
import java.util.Map;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAnyAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
import javax.xml.namespace.QName;
/**
* <p>Java class for ServiceAuthHeader complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* <complexType name="ServiceAuthHeader">
* <complexContent>
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* <sequence>
* <element name="Username" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
* <element name="Password" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
* </sequence>
* <anyAttribute/>
* </restriction>
* </complexContent>
* </complexType>
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "ServiceAuthHeader", propOrder = {
"username",
"password"
})
public class ServiceAuthHeader {
@XmlElement(name = "Username")
protected String username;
@XmlElement(name = "Password")
protected String password;
@XmlAnyAttribute
private Map<QName, String> otherAttributes = new HashMap<QName, String>();
/**
* Gets the value of the username property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getUsername() {
return username;
}
/**
* Sets the value of the username property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setUsername(String value) {
this.username = value;
}
/**
* Gets the value of the password property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getPassword() {
return password;
}
/**
* Sets the value of the password property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setPassword(String value) {
this.password = value;
}
/**
* Gets a map that contains attributes that aren't bound to any typed property on this class.
*
* <p>
* the map is keyed by the name of the attribute and
* the value is the string value of the attribute.
*
* the map returned by this method is live, and you can add new attribute
* by updating the map directly. Because of this design, there's no setter.
*
*
* @return
* always non-null
*/
public Map<QName, String> getOtherAttributes() {
return otherAttributes;
}
}
這樣我就可以使用這個succcesfully撥打服務:
private static PriceDetailRetunValue priceDetail(PriceDetailInputValue inputValue) {
com.theservice.webservice.WebService service = new com.theservice.webservice.WebService();
com.theservice.webservice.WebServiceSoap port = service.getWebServiceSoap12();
return port.priceDetail(inputValue);
}
,我可以解析響應,這當然會告訴我,我需要給證書。
那麼我怎樣才能得到實際SOAP Header消息的句柄,以便能夠添加ServiceAuthHeader?我一直在研究創建的WebService的方法,並發現您可以獲取請求上下文,並且我已經看到如何將憑證添加到http請求標頭中,但是我沒有找到可以添加到的任何位置SOAPMEssage。
任何幫助,將不勝感激。謝謝。
找到答案http://www.javadb.com/using-a-message-handler-to-alter-the-soap-header-in-a-web-service-client – iainmac999
你可以[回答你自己的問題問題](http://meta.stackexchange.com/q/17463/163188); [tag:javawebstart]是一個部署框架。 – trashgod