简体   繁体   English

如何使用Java发送标头消息?

[英]How can I send header message in Java?

I have a request message like this, in SOAPUI: 我在SOAPUI中有这样的请求消息:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"    xmlns:service="www.xxxxx.xx">
<soapenv:Header>
  <service:SessionInfo>
    <service:UserPassword>?</service:UserPassword>
 </service:SessionInfo></soapenv:Header> 
<soapenv:Body>
 <service:Method1>
 <!--Optional:-->
 <service:Arguments>
    <service:Parameter1>?</service:Parameter1>
    <service:Parameter2>?</service:Parameter2>
    <!--Optional:-->
    <service:Parameter3>?</service:Parameter3>
    <!--Optional:-->
    <service:Parameter4>?</service:Parameter4>
 </service:Arguments>
 </service:Method1></soapenv:Body></soapenv:Envelope>

I am having problem while sending header message of this wsdl in Java. 在Java中发送此wsdl的标头消息时遇到问题。 I sent the request message in C# and SOAPUI successfully. 我在C#和SOAPUI中成功发送了请求消息。 I was able to view partial class in C# which is soapenv:Header in SOAPUI. 我能够在C#中查看SOAPUI中的soapenv:Header的部分类。 I could not view partial class after importing wsdl in Java. 在Java中导入wsdl后,我无法查看部分类。 Do I have to do something different in Java? 我需要在Java中做些不同的事情吗?

Thanks. 谢谢。

Normally you'd use a library to invoke the SOAP endpoint such as axis2. 通常,您会使用一个库来调用SOAP端点,例如axis2。

This blog post shows how to set the headers using this library. 这篇博客文章显示了如何使用该库设置标题。

MessageContext responseMessageContext =
       MessageContext.getCurrentMessageContext().getOperationContext().getMessageContext(
               WSDLConstants.MESSAGE_LABEL_OUT_VALUE);
List headers = new ArrayList();
headers.add(new Header(HTTPConstants.HEADER_CONTENT_ENCODING, "identity"));
responseMessageContext.setProperty(HTTPConstants.HTTP_HEADERS, headers);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM