如何在 Soap Request Java 中设置标头



我在形成 SOAP 请求时遇到问题。

在该请求中,我应该在标题部分而不是有效负载部分添加用户名,密码和其他一些信息。

在 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 文件,该文件没有用户名、密码等字段,我需要先设置这些参数才能重新制作

@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;
}

}

这是我需要调用的函数

@WebMethod(operationName = "UploadCustomerDocument", action = "http://tempuri.org/ISend/UploadCustomerDocument")
@WebResult(name = "ReturnUploadCustomerDocument", targetNamespace = "http://tempuri.org/", partName = "parameters")
@SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE)
public ReturnUploadCustomerDocument uploadCustomerDocument(
    @WebParam(name = "InputUploadCustomerDocument", targetNamespace = "http://tempuri.org/", partName = "parameters")
    InputUploadCustomerDocument parameters);

有人可以帮我如何设置这些标题吗?

您可以使用以下行在发出请求之前添加标头,因为您使用的是 JAX-WS:

SOAPHeader header = envelope.addHeader();

您可以参考很多教程。 转到谷歌并搜索使用SOAP Web Service。您可以参考以下一个教程:

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

希望这有帮助。

相关内容

  • 没有找到相关文章

最新更新