Search code examples
soapwsdlapache-axis

Communicating to WSDL using SOAP, I don't know how to form correctly my SOAP to interact with the WSDL in a remote server


I have to make a request to a web service, that uses Axis2, I'm too close to have it working but i keep getting error messages and i'm sure it is in the construction of my SOAP XML. This was the SOAP:

<?xml version="1.0" encoding="UTF-8"?>
    <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">
        <soap:Header>
            <RequestsoapHeader>
                <spId>SPID</spId>
                <spPassword>RandomPass</spPassword>
                <timeStamp>20130115160251</timeStamp>
            </RequestsoapHeader>
        </soap:Header>
        <soap:Body>
            <operation>
                <name>getSPToken</name>
                <input>http://zzz.zzz.zzz.zzz/my/redirection/url/</input>
            </operation>
        </soap:Body>
    </soap:Envelope>

UPDATE!!!! Now the soap is this:

<?xml version="1.0" encoding="UTF-8"?>
    <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">
        <soap:Header>
            <RequestsoapHeader>
                <spId>SPID</spId>
                <spPassword>RandomPass</spPassword>
                <timeStamp>20130115160251</timeStamp>
            </RequestsoapHeader>
        </soap:Header>
        <soap:Body>
            <getSPTokenRequest>
                <SPredirectURL>http://zzz.zzz.zzz.zzz/my/redirection/url/</SPredirectURL>
            </getSPTokenRequest>
        </soap:Body>
    </soap:Envelope>

The part i can't fix is the Body, i tried to call the operation in different ways, for example instead of <operation> i used <operation name="getSPToken">, i also tried not using operation and created a tag with the name: <getSPToken>, but nothing works.

This is the WSDL part that describes the operation i'm trying to call in the Web Service:

    <wsdl:operation name="getSPToken">
        <soap:operation soapAction="" style="document"/>
        <wsdl:input>
            <soap:body use="literal"/>
        </wsdl:input>
        <wsdl:output>
            <soap:body use="literal"/>
        </wsdl:output>
        <wsdl:fault name="ServiceException">
            <soap:fault name="ServiceException" use="literal"/>
        </wsdl:fault>
        <wsdl:fault name="PolicyException">
            <soap:fault name="PolicyException" use="literal"/>
        </wsdl:fault>
    </wsdl:operation>

UPDATE!!! This is the interface XML (part of the WSDL) that i didn't post before:

<wsdl:types>
    <xsd:schema elementFormDefault="qualified" 
        xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
        targetNamespace="http://www.csapi.org/schema/parlayx/sicoweb/v1_0/local">
        <xsd:element name="getSPTokenRequest" type="osg_sicoweb_local_xsd:getSPTokenRequest"/>
        <xsd:complexType name="getSPTokenRequest">
            <xsd:sequence>
                <xsd:element name="SPredirectURL"
                    type="xsd:string" maxOccurs="1" minOccurs="1">
                    <xsd:annotation>
                        <xsd:documentation></xsd:documentation>
                    </xsd:annotation>
                </xsd:element>
            </xsd:sequence>
        </xsd:complexType>

        <xsd:element name="getSPTokenResponse" type="osg_sicoweb_local_xsd:getSPTokenResponse"/>
        <xsd:complexType name="getSPTokenResponse">
            <xsd:sequence>
                <xsd:element name="SPToken" type="xsd:string"/>
            </xsd:sequence>
        </xsd:complexType>
    </xsd:schema>
</wsdl:types>

And this is the response i was getting:

HTTP/1.1 500 Internal Server Error
Server: Apache-Coyote/1.1
Content-Type: text/xml;charset=UTF-8
Date: Tue, 15 Jan 2013 21:10:49 GMT
Connection: close
<?xml version='1.0' encoding='UTF-8'?>
    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
        <soapenv:Body>
            <soapenv:Fault xmlns:axis2ns73="http://schemas.xmlsoap.org/soap/envelope/">
                <faultcode>axis2ns73:Client</faultcode>
                <faultstring>The endpoint reference (EPR) for the Operation not found is http://xxx.xxx.xxx.xxx:xxx/path/to/service/ and the WSA Action = </faultstring>
                <detail />
            </soapenv:Fault>
        </soapenv:Body>
    </soapenv:Envelope>

UPDATE!!!! With the new changes, the response i'm getting is this one:

<?xml version='1.0' encoding='UTF-8'?>
    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
        <soapenv:Body>
            <soapenv:Fault>
                <faultcode>soapenv:Server</faultcode>
                <faultstring>org.apache.axis2.databinding.ADBException: Unexpected subelement getSPTokenRequest</faultstring>
                <detail />
            </soapenv:Fault>
        </soapenv:Body>
    </soapenv:Envelope>

The operation getSPToken receives one parameter called SPredirectURL, that contains a URL of redirection, please help.


Solution

  • Try one of the following as your body:

    <soap:Body>
      <SPredirectURL>http://zzz.zzz.zzz.zzz/my/redirection/url/</SPredirectURL>
    </soap:Body>
    
    <soap:Body>
      <getSPTokenRequest xmlns="http://www.csapi.org/schema/parlayx/sicoweb/v1_0/local">
        <SPredirectURL>http://zzz.zzz.zzz.zzz/my/redirection/url/</SPredirectURL>
      </getSPTokenRequest>
    </soap:Body>
    

    Based on the WSDL snippet, the web service endpoint is using the document/literal convention for messages, but without the WSDL message declarations it is unclear whether the 'bare' (first example) or 'wrapped' (second example) version is expected. The post at this address (http://www.ibm.com/developerworks/webservices/library/ws-whichwsdl/) gives good insight into the various dialects described by WSDL.

    UPDATE: Based on the schema inside the wsdl:types section, the fully-qualified name for the element expected by the service (based on the declared targetNamespace attribute of the schema element) is http://www.csapi.org/schema/parlayx/sicoweb/v1_0/local{getSPTokenRequest}

    One way of establishing that name (inline namespace declaration) is shown in the updated second body above.

    Post back with the next iteration.