问题
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>
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);
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);
If I make this change manually, JAX-WS works fine. I wonder, if there any way to write an appropriate customization for that?
回答1:
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" />
also replace
<s:element minOccurs="0" maxOccurs="1" name="CSID2ExtRefsResult" type="tns:ArrayOfExtRef"/>
with
<s:element minOccurs="0" maxOccurs="unbounded" name="CSID2ExtRefsResult" type="tns:ExtRef"/>
Also you may remove complexType such as "ArrayOfString",ArrayOfExtRef.
来源:https://stackoverflow.com/questions/8091859/what-customization-to-apply-for-jax-ws-to-unwrap-return-objects-to-lists