1

Edit: There was no problem with my code. Server was reading wsdl file from cache. To solve the issue:

  1. Disable the cache with ini_set("soap.wsdl_cache_enabled", 0);
  2. Otherwise delete cache file from /tmp directory each time after changing wsdl file.

I am using zend soap for creating a web service. I am trying to return a complex type from it. My php class looks like this:

require_once 'myclass.php';

class MyService {
    /**
     *
     * @param integer param1
     * @param string param2
     * @return myclass
     */
    public function myfunction ($param1, $param2) {

        $myobj= new myclass();
        $myobj->returncode = 100;
        return $myobj;
    }
}

myclass is a simple class with two public variables

class myclass {
    /** @var int */
    public $returncode = '0';

    /** @var string */
    public $returnmessage = 'Başarılı';

}

I am using AutoDiscovery for generating wsdl file:

<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://my.domain.com/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap-enc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" name="MyService" targetNamespace="http://my.domain.com/wsdl/">
  <types>
  <xsd:schema targetNamespace="http://my.domain.com/wsdl/">
  <xsd:complexType name="myclass">
    <xsd:all>
    <xsd:element name="returncode" type="xsd:int"/>
    <xsd:element name="returnmessage" type="xsd:string"/>
    </xsd:all>
  </xsd:complexType>
  </xsd:schema>
  </types>
  <portType name="MyServicePort">
  <operation name="myfunction">
  <documentation></documentation>
  <input message="tns:myfunctionIn"/>
  <output message="tns:myfunctionOut"/>
  </operation>
  </portType>
  <binding name="MyServiceBinding" type="tns:MyServicePort">
  <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
  <operation name="myfunction">
  <soap:operation soapAction="http://my.domain.com/wsdl/#myfunction"/>
  <input>
  <soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://my.domain.com/wsdl/"/>
  </input>
  <output>
  <soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://my.domain.com/wsdl/"/>
  </output>
  </operation>
  </binding>
  <service name="MyServiceService">
  <port name="MyServicePort" binding="tns:MyServiceBinding">
  <soap:address location="http://my.domain.com/wsdl/"/>
  </port>
  </service>
  <message name="myfunctionIn">
  <part name="param1" type="xsd:int"/>
  <part name="param2" type="xsd:string"/>

  </message>
    <message name="myfunctionOut">
    <part name="return" type="tns:myclass"/>
  </message>
  </definitions>

I can receive primitive types without a problem. When i try to return an object it converts object to string (Displays "Object") and returns:

<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://my.domain.com/wsdl" 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/">
<SOAP-ENV:Body>
   <ns1:myfunctionResponse>
      <return xsi:type="xsd:string">Object</return>
  </ns1:myfunctionResponse>
</SOAP-ENV:Body>

I want a result like this:

<myclass>
  <returncode>100</returncode>
  <returnmessage>Ok</returnmessage>
</myclass>

Thank you.

Muhammet Emre
  • 349
  • 3
  • 17

0 Answers0