2017-03-20 22 views
0

我在形成SOAP請求時遇到了問題。如何在Soap請求中設置標題Java

在那個請求中,我應該在頭部分中添加用戶名,密碼和一些其他信息,而不是有效載荷的一部分。

低於WSDL

<wsdl:message name="InputUploadCustomerDocument_Headers"> 
<wsdl:part name="DocumentType" element="tns:DocumentType"/> 
<wsdl:part name="FileName" element="tns:FileName"/> 
<wsdl:part name="Password" element="tns:Password"/> 
<wsdl:part name="PinNo" element="tns:PinNo"/> 
<wsdl:part name="UserName" element="tns:UserName"/> 
</wsdl:message> 
<wsdl:message name="ReturnUploadCustomerDocument"> 
<wsdl:part name="parameters" element="tns:ReturnUploadCustomerDocument"/> 
</wsdl:message> 


<wsdl:operation name="UploadCustomerDocument"> 
<soap:operation soapAction="http://tempuri.org/ISend/UploadCustomerDocument" style="document"/> 
<wsdl:input name="InputUploadCustomerDocument"> 
<soap:header message="tns:InputUploadCustomerDocument_Headers" part="DocumentType" use="literal"/> 
<soap:header message="tns:InputUploadCustomerDocument_Headers" part="FileName" use="literal"/> 
<soap:header message="tns:InputUploadCustomerDocument_Headers" part="Password" use="literal"/> 
<soap:header message="tns:InputUploadCustomerDocument_Headers" part="PinNo" use="literal"/> 
<soap:header message="tns:InputUploadCustomerDocument_Headers" part="UserName" use="literal"/> 
<soap:body use="literal"/> 
</wsdl:input> 
<wsdl:output name="ReturnUploadCustomerDocument"> 
<soap:body use="literal"/> 
</wsdl:output> 
</wsdl:operation> 

的條目和InputUploadCustomerDocument Java文件下面,文件沒有用戶名,密碼和其他領域,我需要做reuqest

@XmlAccessorType(XmlAccessType.FIELD) 
@XmlType(name = "", propOrder = { 
"fileData" 
}) 
@XmlRootElement(name = "InputUploadCustomerDocument") 
public class InputUploadCustomerDocument { 

@XmlElement(name = "FileData", required = true) 
protected byte[] fileData; 

/** 
* Gets the value of the fileData property. 
* 
* @return 
*  possible object is 
*  byte[] 
*/ 
public byte[] getFileData() { 
    return fileData; 
} 

/** 
* Sets the value of the fileData property. 
* 
* @param value 
*  allowed object is 
*  byte[] 
*/ 
public void setFileData(byte[] value) { 
    this.fileData = value; 
} 
之前設置這些參數

}

這是我需要調用

0功能

有人可以幫助我如何設置這些標題?

回答

1

您可以使用此線下方發出請求之前添加頁眉,由於您使用的JAX-WS:

SOAPHeader header = envelope.addHeader(); 

有很多,你可以參考教程。轉到谷歌並搜索使用SOAP Web服務。這裏有一個這樣的教程,你可以參考一下:

http://www.javadb.com/using-a-message-handler-to-alter-the-soap-header-in-a-web-service-client/

這裏是你可以用另一個很好的例子: https://soa2world.blogspot.com/2009/05/direct-web-service-client-using-java.html

希望這有助於。