我正在使用Apache CXF 2.7.3,并且遇到名称空间问题,我真的不明白。我已经尝试过在这方面进行广泛的搜索,但是我发现的大部分结果都是针对不同的行为。问题是调用Web服务时,如果参数元素是名称空间限定的,它将失败。消息中的所有其他元素都是限定的,并且它只接受参数元素。这里是精确的行为:使用Apache CXF的Web服务上的名称空间问题
请求WITHOUT参数元素合格:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ord="http://www.example.org/order">
<soapenv:Header/>
<soapenv:Body>
<ord:getOrder>
<id>a</id>
</ord:getOrder>
</soapenv:Body>
</soapenv:Envelope>
结果成功:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ns2:getOrderResponse xmlns:ns2="http://www.example.org/order">
<return>
<ns2:errorCode/>
<ns2:errorMessage/>
<ns2:order>
<ns2:orderNumber>ABC123</ns2:orderNumber>
<ns2:lastName>Smith</ns2:lastName>
</ns2:order>
</return>
</ns2:getOrderResponse>
</soap:Body>
</soap:Envelope>
请求WITH参数合格:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ord="http://www.example.org/order">
<soapenv:Header/>
<soapenv:Body>
<ord:getOrder>
<ord:id>a</ord:id>
</ord:getOrder>
</soapenv:Body>
</soapenv:Envelope>
个结果异常从JAXB:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<soap:Fault>
<faultcode>soap:Client</faultcode>
<faultstring>Unmarshalling Error: unexpected element (uri:"http://www.example.org/order", local:"id"). Expected elements are <{}id></faultstring>
</soap:Fault>
</soap:Body>
</soap:Envelope>
在所有我做过的研究,这通常意味着一个命名空间不匹配的地方。但我已经彻底检查过了,命名空间在任何地方都是一样的,包括ObjectFactory.class,package-info.class和cxf-servlet.xml配置文件以及@WebService注释。任何人都可以指出我在正确的方向,我在这里失去了什么?
我终于找到了解决方案。当然,这是在我发布之后发生的,呃...因为我是新人,而且我的名声太低,所以在8个小时之前我不能回答这个问题。然后我会发布我的解决方案。抱歉的人。 – 2013-05-13 15:10:31
为什么有人没有解释或评论downvote? – 2013-05-14 18:24:28