yii2-services icon indicating copy to clipboard operation
yii2-services copied to clipboard

Return complex type

Open hartois opened this issue 2 years ago • 2 comments

Hello, I'm trying return complex type from action:

    public function actions()
    {
        return [
            'soap' => [
                'class' => WebServiceAction::class,
                'wsdlUrl' => 'http://smsbat.local/service/soap',
                'serviceUrl' => 'http://smsbat.local/service/soap?ws=1',
                'classMap' => ['TestMessage' => \app\controllers\TestMessage::class]
            ],
        ];
    }

    /**
     * @param string msid
     * @return \app\controllers\TestMessage
     * @soap
     */
    public function SendMessage($msid)
    {
        $obj = new TestMessage();
        $obj->messageID = 123;
        $obj->msid = 12312321;
        return $obj;
    }
..............

namespace app\controllers;

class TestMessage{
    public $msid;
    public $name = 'test';
}

But in response I see:

<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:app/controllers/ServiceControllerwsdl" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
   <SOAP-ENV:Body>
      <ns1:SendMessageResponse>
         <return xsi:type="ns1:TestMessage"/>
      </ns1:SendMessageResponse>
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

where no properties of TestMessage object :( Am I doing something wrong or misunderstanding how this is supposed to work? Please help me.

hartois avatar Apr 14 '22 07:04 hartois

Hell, @hartois! Check WSDL description of TestMessage, it should contains properties msid,name. It looks like you forgot to add annotations to these properties.

class TestMessage{
    /**
     * @soap
    */
    public $msid;
...
}

borodulin avatar Apr 14 '22 08:04 borodulin

I'm added:

class TestMessage{
    /**
     * @soap
     */
    public $msid;
    /**
     * @soap
     */
    public $name = 'test';
}

but in wsdl:

         <xsd:complexType name="TestMessage">
            <xsd:all/>
         </xsd:complexType>

cache disabled by:

        ini_set("soap.wsdl_cache_enabled", '0');

hartois avatar Apr 18 '22 10:04 hartois