【发布时间】:2014-10-27 10:40:21
【问题描述】:
我将 Apache CXF 3.0.2 用于客户端和服务器。在服务器上有一个相当简单的 Web 服务,它接受各种参数,其中一个是字符串数组:
<xs:complexType name="getThing">
<xs:sequence>
<xs:element minOccurs="0" name="connection" type="tns:connectionID"/>
<xs:element maxOccurs="unbounded" minOccurs="0" name="types" type="xs:string"/>
</xs:sequence>
</xs:complexType>
当客户端调用它时,它可能希望为“类型”传递一个空值,这就是我遇到问题的地方。来自客户端的 SOAP 消息如下所示:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ns2:getThing xmlns:ns2="http://serverl.url/">
<connection>Connection details....</connection>
<types xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
</ns2:getThing>
</soap:Body>
</soap:Envelope>
我认为这是正确的,但是服务器上的 CXF 将其转换为具有单个空字符串值的数组; 不是包含空值的数组。这会导致服务器代码出现各种问题。
服务器实现的接口是这样的?
ThingResult getThing(@WebParam(name = "connection") ConnectionID connection, @WebParam(name = "types") String[] types)
{ code }
如果 'nil="true"' 无效,那么为什么 CXF 会生成它?
空数组可以正常工作(客户端从消息中省略元素,服务器将其解释为空),但不是包含空值的数组。为什么 CXF 会以这种方式运行?如何配置它以便服务器将 SOAP 消息正确反序列化回客户端发送的消息?
我到处寻找答案,我很确定我遗漏了一些非常明显的东西!
编辑:添加代码示例
【问题讨论】:
标签: web-services soap cxf jax-ws