Search code examples
web-servicessoapwsdl

Couldn't find <definitions> in WSDL


i tried to develop my first SOAP webservice, but i'm stuck with an error when i try to open my WSDL with wizdl. I got this error :

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Body>
<SOAP-ENV:Fault>
<faultcode>WSDL</faultcode>
<faultstring>
SOAP-ERROR: Parsing WSDL: Couldn't find <definitions> in 
'http://localhost/testSolution/test.wsdl'
</faultstring>
</SOAP-ENV:Fault>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Here is my code : testSolution.php :

 <?php

class Ws{

  function getString()
  {
    return "TESTASTOS";
  }
}

ini_set("soap.wsdl_cache_enabled", 0);

$serversoap = new SoapServer("http://localhost/testSolution/test.wsdl");

$serversoap->setClass("Ws");

$serversoap->handle();

?>

And test.wsdl :

<?xml version="1.0" encoding="iso-8859-1"?>
<definitions
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns="http://schemas.xmlsoap.org/wsdl"

  targetNamespace="urn:serviceTestwsdl"
  xmlns:tns="urn:serviceTestwsdl"
>


<types>
<xsd:schema targetNamespace="urn:serviceTestwsdl"/>
<xsd:import namespace="http://schemas.xmlsoap.org/soap/encoding/" />
<xsd:import namespace="http://schemas.xmlsoap.org/wsdl/" />
</types>

<message name="getStringRequest">
</message>
<message name="getStringResponse">
<part name="return" type="xsd:string" />
</message>

<portType name="serviceTestPortType">

<operation name="getString">
  <documentation>Récupère un string</documentation>
  <input message="tns:getStringRequest"/>
  <output message="tns:getStringResponse"/>
</operation>
</portType>


<binding name="serviceTestBinding" type="tns:serviceTestPortType">

 <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
 <operation name="getString">
  <soap:operation soapAction="urn:serviceTestwsdl#getString" style="rpc"/>
  <input>
    <soap:body use="encoded" namespace="urn:serviceTestwsdl" 
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
  </input>
  <output>
    <soap:body use="encoded" namespace="urn:serviceTestwsdl" 
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
  </output>
</operation>
</binding>

<service name="serviceTest">
<port name="serviceTestPort" binding="tns:serviceTestBinding">
  <soap:address location="http://localhost/testSolution/testSolution.php"/>
</port>

</service>
</definitions>

The mainly goal is to understand how a soap webservice work by making a small hello world on string.

Thanks a lot for your Help

Regards. Didier


Solution

  • You need to add the "wsdl" prefix like <wsdl:definitions> in the test.wsdl. Also to the first level of elements within that param:

    <wsdl:types>...</wsdl:types>
    <wsdl:operation>...</wsdl:operation>
    

    ... etc

    This will allow you to load the wsdl.