Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Soap request Message part was not recognized

When I send a request to my webservice (build with apache camel and running on apache karaf) I always get

<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>

My wsdl looks like this

<?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>

And this is my request in 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>

I can't find anything wrong in my wsdl here. Anyone got an idea what leads to this?

like image 226
Milla Avatar asked Sep 17 '15 06:09

Milla


1 Answers

I think the problem is that the target namespace in the wsdl and the one in the schema are the same:

<?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">
...

And then in the message part when you use the 'tns' prefix in tns:input it cannot resolve the element:

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

You can try defining a different target namespace in the schema declaration and adding a new prefix in <wsdl:definitions>to that namespace.

<?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">
...

And then in the message part use this new prefix:

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

Right now I don't remember if it's mandatory to define different targetnamespaces for the wsdl and the schema in the types element, but I do remember facing a similar issue, and it's also considered a best practice to do so.

I usually create at least two schemas, one for the 'in' and another for the 'out' parameters both having their own namespace to avoid possible name collisions.

like image 128
David Lizárraga Avatar answered Nov 04 '22 14:11

David Lizárraga