肥皂请求消息部分无法识别

时间:2015-09-17 06:45:57

标签: web-services soap wsdl apache-camel apache-karaf

当我向我的webservice发送请求时(使用apache camel构建并在apache karaf上运行)我总是得到

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
 <soap:Body>
  <soap:Fault>
     <faultcode>soap:Client</faultcode>
     <faultstring>Message part {http://localhost:8181/cxf/webservices/inputoutput}input was not recognized.  (Does it exist in service WSDL?)</faultstring>
  </soap:Fault>
 </soap:Body>
</soap:Envelope>

我的wsdl看起来像这样

<?xml version="1.0" encoding="ISO-8859-1"?>
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://localhost:8181/cxf/webservices/inputoutput"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
targetNamespace="http://localhost:8181/cxf/webservices/inputoutput">

<!-- Type definitions for input- and output parameters for webservice -->
<wsdl:types>
    <xs:schema targetNamespace="http://localhost:8181/cxf/webservices/inputoutput">
        <xs:element name="input">
            <xs:complexType>
                <xs:sequence>
                    <xs:element type="xs:string" name="surname"/>
                </xs:sequence>
            </xs:complexType>
        </xs:element>
        <xs:element name="output">
            <xs:complexType>
                <xs:sequence>
                    <xs:element type="xs:string" name="forename"/>
                </xs:sequence>
            </xs:complexType>
        </xs:element>
    </xs:schema>
</wsdl:types>

<!-- Message definitions for input and output -->
<wsdl:message name="input">
    <wsdl:part name="surname" element="tns:input"/>
</wsdl:message>
<wsdl:message name="output">
    <wsdl:part name="forename" element="tns:output"/>
</wsdl:message>

<!-- Port (interface) definitions -->
<wsdl:portType name="InputOutputEndpoint">
    <wsdl:operation name="InputOutput">
        <wsdl:input message="tns:input"/>
        <wsdl:output message="tns:output"/>
    </wsdl:operation>
</wsdl:portType>

<!-- Port bindings to transports and encoding - HTTP, document literal encoding is used -->
<wsdl:binding name="InputOutputBinding" type="tns:InputOutputEndpoint">
    <soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
    <wsdl:operation name="InputOutput">
        <soap:operation soapAction="http://localhost:8181/cxf/webservices/inputoutput" style="document"/>
        <wsdl:input>
            <soap:body parts="in" use="literal"/>
        </wsdl:input>
        <wsdl:output>
            <soap:body parts="out" use="literal"/>
        </wsdl:output>
    </wsdl:operation>
</wsdl:binding>

<!-- Service definition -->
<wsdl:service name="InputOutputEndpointService">
    <wsdl:port name="InputOutputEndpoint" binding="tns:InputOutputBinding">
        <soap:address location="http://localhost:8181/cxf/webservices/inputoutput"/>
    </wsdl:port>
</wsdl:service>

</wsdl:definitions>

这是我在SoapUI中的要求

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"    xmlns:rep="http://localhost:8181/cxf/webservices/inputoutput">
<soapenv:Header/>
<soapenv:Body>
  <rep:input>
    <surname>test</surname>
  </rep:input>
</soapenv:Body>
</soapenv:Envelope>

我的wsdl在这里找不到任何错误。有人知道是什么导致了这个吗?

3 个答案:

答案 0 :(得分:0)

我认为问题是wsdl中的目标命名空间和架构中的目标命名空间是相同

<?xml version="1.0" encoding="ISO-8859-1"?>
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://localhost:8181/cxf/webservices/inputoutput"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
targetNamespace="http://localhost:8181/cxf/webservices/inputoutput">

<!-- Type definitions for input- and output parameters for webservice -->
<wsdl:types>
    <xs:schema targetNamespace="http://localhost:8181/cxf/webservices/inputoutput">
...

然后在tns:input中使用'tns'前缀的消息部分中,它无法解析该元素:

<wsdl:message name="input">
    <wsdl:part name="surname" element="tns:input"/>
</wsdl:message>

您可以尝试在架构声明中定义不同的目标命名空间,并在<wsdl:definitions>中向该命名空间添加新前缀。

<?xml version="1.0" encoding="ISO-8859-1"?>
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://localhost:8181/cxf/webservices/inputoutput"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
targetNamespace="http://localhost:8181/cxf/webservices/inputoutput"
xmlns:types="http://localhost:8181/cxf/webservices/inputoutput/types">

<!-- Type definitions for input- and output parameters for webservice -->
<wsdl:types>
    <xs:schema targetNamespace="http://localhost:8181/cxf/webservices/inputoutput/types">
...

然后在消息部分中使用这个新前缀:

<wsdl:message name="input">
    <wsdl:part name="surname" element="types:input"/>
</wsdl:message>

现在我不记得是否必须为types元素中的wsdl和schema定义不同的targetnamespaces,但我确实记得面临类似的问题,并且这也是最佳实践。

我通常创建至少两个模式,一个用于'in',另一个用于'out'参数,两者都有自己的命名空间,以避免可能的名称冲突。

答案 1 :(得分:0)

尝试将属性名称添加到complexType:

<xs:complexType name="input">

答案 2 :(得分:0)

在路线开始时检查数据格式。

<from id="_to2" uri="cxf:bean:yourServiceClient?dataFormat=RAW"/>

RAW和MESSAGE数据格式可能会解决问题。

相关问题