【问题标题】:How to construct soap message with xsd element name rather element type如何用xsd元素名称而不是元素类型构造soap消息
【发布时间】:2015-05-27 22:57:02
【问题描述】:
<xsd:element name="echodemo" type="EchodemoType">
    <xsd:annotation>
        <xsd:documentation>
            Root element
        </xsd:documentation>
    </xsd:annotation>

这是我的 XSD。

但是当我通过选择在 RSA 中生成 java 来从 xsd 生成 java 对象时,它会生成 EchodemoType.java .. 所以在将请求传递给我的服务之前,我在下面创建实例 LIKE

EchodemoType request = new EchodemoType();
request.setEchoRequest("This is Echo String !!!");
request .setVersion(new BigDecimal("1.0"));

在调用我的网络服务时,我看到了如下所示的肥皂消息。,

<EchodemoType version="1.0">
<ns2:echoRequest>This is Echo String !!!</ns2:echoRequest>
</EchodemoType>

基本上我想要带有元素名称“echodemo”而不是类型“EchodemoType”的肥皂消息开始标签。我也希望它带有名称空间

<echodemo  version="1.0" xmlns="http://test.com/api/test/services/echodemo">
 <ns2:echoRequest>This is Echo String !!!</ns2:echoRequest>here
</echodemo>

请告诉我生成该类以获取该肥皂消息的方式或我需要在哪里更正此问题?

【问题讨论】:

    标签: web-services jakarta-ee soap jaxb


    【解决方案1】:

    使用 Object Factory 像下面这样对对象进行封装,您无需在 DemoType.java 中使用 @XmlRootElement 。,

    DemoType demoServiceRequest = new DemoType();
    demoServiceRequest.setName("fgfg"); 
    ObjectFactory obDemo = new ObjectFactory();  
    Request requestObject = new Request();     
    requestObject.setAny(obDemo.createDemo(demoServiceRequest));
    

    并在 Request.java 中添加 DemoType 类,如 @XmlSeeAlso({DemoType.class})

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-24
      • 2020-05-31
      • 1970-01-01
      • 1970-01-01
      • 2019-05-29
      • 2019-03-06
      相关资源
      最近更新 更多