应用JAX-WS将返回对象解包到列表的自定义是什么? [英] What customization to apply for JAX-WS to unwrap return objects to lists?

查看:131
本文介绍了应用JAX-WS将返回对象解包到列表的自定义是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想找到是否有办法自定义,例如 CSID2ExtRefs ChemSpider WebService 的操作传递一个字符串列表作为参数之一并返回对象列表:

I am trying to find if there is a way to customize e.g. CSID2ExtRefs operation for ChemSpider WebService that is passed a list of strings as one of the arguments and returns the list of objects:

<!-- Request element: -->
<s:element name="CSID2ExtRefs">
  <s:complexType>
    <s:sequence>
      <s:element minOccurs="1" maxOccurs="1" name="CSID" type="s:int"/>
      <s:element minOccurs="0" maxOccurs="1" name="datasources" type="tns:ArrayOfString"/>
      <s:element minOccurs="0" maxOccurs="1" name="token" type="s:string"/>
    </s:sequence>
  </s:complexType>
</s:element>
<!-- Response element: -->
<s:element name="CSID2ExtRefsResponse">
  <s:complexType>
    <s:sequence>
      <s:element minOccurs="0" maxOccurs="1" name="CSID2ExtRefsResult" type="tns:ArrayOfExtRef"/>
    </s:sequence>
  </s:complexType>
</s:element>
<s:complexType name="ArrayOfExtRef">
  <s:sequence>
    <s:element minOccurs="0" maxOccurs="unbounded" name="ExtRef" type="tns:ExtRef"/>
  </s:sequence>
</s:complexType>
<s:complexType name="ArrayOfString">
  <s:sequence>
    <s:element minOccurs="0" maxOccurs="unbounded" name="string" nillable="true" type="s:string"/>
  </s:sequence>
</s:complexType>

wsimport 接口方法生成的是(使用 jaxws:enableWrapperStyle = true ):

The generated by wsimport interface method is (with jaxws:enableWrapperStyle = true):

@WebMethod(operationName = "CSID2ExtRefs", action = "http://www.chemspider.com/CSID2ExtRefs")
@WebResult(name = "CSID2ExtRefsResult", targetNamespace = "http://www.chemspider.com/")
@RequestWrapper(localName = "CSID2ExtRefs", targetNamespace = "http://www.chemspider.com/", className = "chemspider.core.CSID2ExtRefsRequest")
@ResponseWrapper(localName = "CSID2ExtRefsResponse", targetNamespace = "http://www.chemspider.com/", className = "chemspider.core.CSID2ExtRefsResponse")
public ArrayOfExtRef csid2ExtRefs(
    @WebParam(name = "CSID", targetNamespace = "http://www.chemspider.com/")
    int csid,
    @WebParam(name = "datasources", targetNamespace = "http://www.chemspider.com/")
    ArrayOfString datasources,
    @WebParam(name = "token", targetNamespace = "http://www.chemspider.com/")
    String token);

但我希望 ArrayOfExtRef ArrayOfString 解包并转向列表,例如得到以下内容:

but I would like to have ArrayOfExtRef and ArrayOfString unwrapped and turned to lists e.g. get the following:

public List<ExtRef> csid2ExtRefs(
    @WebParam(...)
    int csid,
    @WebParam(...)
    List<String> datasources,
    @WebParam(...)
    String token);

如果我手动进行此更改,JAX-WS工作正常。我想知道,有没有办法写一个合适的自定义对于那个?

If I make this change manually, JAX-WS works fine. I wonder, if there any way to write an appropriate customization for that?

推荐答案

首先,所有Web服务std都不是100%可移植的。
替换

First off all web service std are not 100% portable yet. Replace

<s:element minOccurs="0" maxOccurs="1" name="datasources" type="tns:ArrayOfString"/>

with

<s:element name="datasources" type="xs:string" form="qualified" minOccurs="0" maxOccurs="unbounded" />

还替换

<s:element minOccurs="0" maxOccurs="1" name="CSID2ExtRefsResult" type="tns:ArrayOfExtRef"/>

with

<s:element minOccurs="0" maxOccurs="unbounded" name="CSID2ExtRefsResult" type="tns:ExtRef"/>

您也可以删除complexType,例如ArrayOfString,ArrayOfExtRef。

Also you may remove complexType such as "ArrayOfString",ArrayOfExtRef.

这篇关于应用JAX-WS将返回对象解包到列表的自定义是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆