Problem with Soap Server Input Params

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Problem with Soap Server Input Params

Kai Szymanski

Hi!

I try to write my first "soap server" but have some problems. Here my
very simple soapserver:

/**
  * Input Param
  */
class inputParam {
     /**
      * @var string stringVar String
      */
     public $stringVar;

     /**
      * @var int numericVar
      */
     public $numericVar;
}

class outputParam {
     /**
      * @var int result
      */
     public $result;
}

// My class
class soapTest {

     /**
      * Do something
      *
      * @param inputParam $input
      * @return outputParam $output
      */
     public function doSomething(inputParam $testparam) {
         $resultParam = new outputParam();

         $resultParam->result = 1;
         return $resultParam;
     }
}

// Code to handle soapAction :)
ini_set("soap.wsdl_cache_enabled", "0");

if(isset($_GET['wsdl'])) {
     $autodiscover = new Zend_Soap_AutoDiscover();
     $autodiscover->setClass('soapTest');
     $autodiscover->handle();
} else {
     $soap = new Zend_Soap_Server($wsdlUri);
     $soap->setClass('soapTest');
     $soap->handle();
}

And now the client:

$soapClient = new Zend_Soap_Client(SERVER_PROTOCOL . HOST_NAME_APPS .
trim(dirname($_SERVER["SCRIPT_NAME"]),"/") . "/testZend_Server.php?wsdl");

$input = new inputParam();
$input->stringVar = "string";
$input->numericVar = 1;

try {
     $result = $soapClient->doSomething($input);
     print_r($result);
} catch (SoapFault $fault) {
     header ("Content-Type:text/xml");
     echo $fault->getMessage();
}

When i cal it i get...nothing. In my php-error log i find:

PHP Catchable fatal error:  Argument 1 passed to
soapTest::doSomethingl() must be an instance of inputParam, instance of
stdClass given

Also the wsdl looks correct.

Thanks for your help!

Best regards,
   Kai.


--
List: [hidden email]
Info: http://framework.zend.com/archives
Unsubscribe: [hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: Problem with Soap Server Input Params

Enrico Zimuel-2
Hi Kai,

your problem comes from a bug of the SoapServer class of PHP (see
https://bugs.php.net/bug.php?id=60077). The type-hinting seems to be not
supported in the SoapServer. To solve the probelm you have to remove the
type-hinting in the doSemthing method of your soapTest class.
As follow:

     /**
      * Do something
      *
      * @param inputParam $input
      * @return outputParam
      */
     public function doSomething($input) {
         $resultParam = new outputParam();
         $resultParam->result = 1;
         return $resultParam;
     }

Be careful with the phpdoc, you have to use the same variable name in
the phpdoc and in the function specification (you used $testparam and
$input).

Regards,
Enrico

On Wed, 2012-01-18 at 15:51 +0100, Kai Szymanski wrote:

> Hi!
>
> I try to write my first "soap server" but have some problems. Here my
> very simple soapserver:
>
> /**
>   * Input Param
>   */
> class inputParam {
>      /**
>       * @var string stringVar String
>       */
>      public $stringVar;
>
>      /**
>       * @var int numericVar
>       */
>      public $numericVar;
> }
>
> class outputParam {
>      /**
>       * @var int result
>       */
>      public $result;
> }
>
> // My class
> class soapTest {
>
>      /**
>       * Do something
>       *
>       * @param inputParam $input
>       * @return outputParam $output
>       */
>      public function doSomething(inputParam $testparam) {
>          $resultParam = new outputParam();
>
>          $resultParam->result = 1;
>          return $resultParam;
>      }
> }
>
> // Code to handle soapAction :)
> ini_set("soap.wsdl_cache_enabled", "0");
>
> if(isset($_GET['wsdl'])) {
>      $autodiscover = new Zend_Soap_AutoDiscover();
>      $autodiscover->setClass('soapTest');
>      $autodiscover->handle();
> } else {
>      $soap = new Zend_Soap_Server($wsdlUri);
>      $soap->setClass('soapTest');
>      $soap->handle();
> }
>
> And now the client:
>
> $soapClient = new Zend_Soap_Client(SERVER_PROTOCOL . HOST_NAME_APPS .
> trim(dirname($_SERVER["SCRIPT_NAME"]),"/") . "/testZend_Server.php?wsdl");
>
> $input = new inputParam();
> $input->stringVar = "string";
> $input->numericVar = 1;
>
> try {
>      $result = $soapClient->doSomething($input);
>      print_r($result);
> } catch (SoapFault $fault) {
>      header ("Content-Type:text/xml");
>      echo $fault->getMessage();
> }
>
> When i cal it i get...nothing. In my php-error log i find:
>
> PHP Catchable fatal error:  Argument 1 passed to
> soapTest::doSomethingl() must be an instance of inputParam, instance of
> stdClass given
>
> Also the wsdl looks correct.
>
> Thanks for your help!
>
> Best regards,
>    Kai.
>
>

--
Enrico Zimuel
Senior PHP Engineer     | [hidden email]
Zend Framework Team     | http://framework.zend.com
Zend Technologies Ltd.
http://www.zend.com


--
List: [hidden email]
Info: http://framework.zend.com/archives
Unsubscribe: [hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: Problem with Soap Server Input Params

Kai Szymanski

Hi Enrico,

thanks for your answer!

I try now using classmaps and this seems to work (my doSomething gets an
object of inputParam) also with type-hinting. But there seems no check
on Clientside.

If i use:

-- Params

class inputParam {

     /**
      * @var string stringVar String
      */
     public $stringVar;

     /**
      * @var int numericVar Numerisch
      */
     public $numericVar;

     /**
      * @var bool booleanVar Boolean
      */
     public $booleanVar;

     /**
      * @var bool booleanVar Boolean
      */
     public $booleanVar2;
}

/**
  * Output Param
  */
class outputParam {

     /**
      * @var string resultString String
      */
     public $resultString;

     /**
      * @var bool resultBool Boolean
      */
     public $resultBool;
}

-- My Class

class soapTest {

     /**
      * Check if we have to update Portal
      *
      * @param inputParam $testparam
      * @return outputParam $resultParam
      */
     public function doSomething(inputParam $testparam) {
         $resultParam = new outputParam();

         $resultParam->resultBool = true;
         $resultParam->resultString = print_r($testparam,true);

         return $resultParam;
     }
}

-- Soap Server

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

if(isset($_GET['wsdl'])) {
     $autodiscover = new
Zend_Soap_AutoDiscover('Zend_Soap_Wsdl_Strategy_ArrayOfTypeComplex');
     $autodiscover->setClass('soapTest');
     $autodiscover->handle();
} else {
     $classMap = array( 'classmap' => array(
                                             'inputParam' => 'inputParam',
                                             'outputParam' => 'outputParam'
                                             )
     );
     $soap = new Zend_Soap_Server($wsdlUri,$classMap);
     $soap->setClass('soapTest');
     $soap->handle();
}

And use

-- Soap Client Test 1

soapClient = new Zend_Soap_Client(SERVER_PROTOCOL . HOST_NAME_APPS .
trim(dirname($_SERVER["SCRIPT_NAME"]),"/") . "/testZend_Server.php?wsdl");

$input = new inputParam();
$input->booleanVar = true;
$input->numericVar = "aaa";
$input->stringVar = "string";

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

try {
     $result = $soapClient->doSomething($input);
     print_r($result);
} catch (SoapFault $fault) {
     header ("Content-Type:text/xml");
     echo $fault->getMessage();
}

i get

stdClass Object ( [resultString] => inputParam Object ( [stringVar] =>
string [numericVar] => 0 [booleanVar] => 1 [booleanVar2] => )
[resultBool] => 1 )

If is use

-- Soap Client Test 2

[...]
         $result = $soapClient->doSomething("there should be an soapfault");

[...]

i get

stdClass Object ( [resultString] => inputParam Object ( [stringVar] =>
[numericVar] => [booleanVar] => [booleanVar2] => ) [resultBool] => 1 )

I ask myself why i give a hint to the soapserver ;)

Best regards,
   Kai.



On 18.01.2012 17:26, Enrico Zimuel wrote:

> Hi Kai,
>
> your problem comes from a bug of the SoapServer class of PHP (see
> https://bugs.php.net/bug.php?id=60077). The type-hinting seems to be not
> supported in the SoapServer. To solve the probelm you have to remove the
> type-hinting in the doSemthing method of your soapTest class.
> As follow:
>
>       /**
>        * Do something
>        *
>        * @param inputParam $input
>        * @return outputParam
>        */
>       public function doSomething($input) {
>           $resultParam = new outputParam();
>           $resultParam->result = 1;
>           return $resultParam;
>       }
>
> Be careful with the phpdoc, you have to use the same variable name in
> the phpdoc and in the function specification (you used $testparam and
> $input).
>
> Regards,
> Enrico
>
> On Wed, 2012-01-18 at 15:51 +0100, Kai Szymanski wrote:
>> Hi!
>>
>> I try to write my first "soap server" but have some problems. Here my
>> very simple soapserver:
>>
>> /**
>>    * Input Param
>>    */
>> class inputParam {
>>       /**
>>        * @var string stringVar String
>>        */
>>       public $stringVar;
>>
>>       /**
>>        * @var int numericVar
>>        */
>>       public $numericVar;
>> }
>>
>> class outputParam {
>>       /**
>>        * @var int result
>>        */
>>       public $result;
>> }
>>
>> // My class
>> class soapTest {
>>
>>       /**
>>        * Do something
>>        *
>>        * @param inputParam $input
>>        * @return outputParam $output
>>        */
>>       public function doSomething(inputParam $testparam) {
>>           $resultParam = new outputParam();
>>
>>           $resultParam->result = 1;
>>           return $resultParam;
>>       }
>> }
>>
>> // Code to handle soapAction :)
>> ini_set("soap.wsdl_cache_enabled", "0");
>>
>> if(isset($_GET['wsdl'])) {
>>       $autodiscover = new Zend_Soap_AutoDiscover();
>>       $autodiscover->setClass('soapTest');
>>       $autodiscover->handle();
>> } else {
>>       $soap = new Zend_Soap_Server($wsdlUri);
>>       $soap->setClass('soapTest');
>>       $soap->handle();
>> }
>>
>> And now the client:
>>
>> $soapClient = new Zend_Soap_Client(SERVER_PROTOCOL . HOST_NAME_APPS .
>> trim(dirname($_SERVER["SCRIPT_NAME"]),"/") . "/testZend_Server.php?wsdl");
>>
>> $input = new inputParam();
>> $input->stringVar = "string";
>> $input->numericVar = 1;
>>
>> try {
>>       $result = $soapClient->doSomething($input);
>>       print_r($result);
>> } catch (SoapFault $fault) {
>>       header ("Content-Type:text/xml");
>>       echo $fault->getMessage();
>> }
>>
>> When i cal it i get...nothing. In my php-error log i find:
>>
>> PHP Catchable fatal error:  Argument 1 passed to
>> soapTest::doSomethingl() must be an instance of inputParam, instance of
>> stdClass given
>>
>> Also the wsdl looks correct.
>>
>> Thanks for your help!
>>
>> Best regards,
>>     Kai.
>>
>>


--
Kai Szymanski

Auf dem Peterswerder 17
28205 Bremen

EMail [hidden email] / Web http://www.codebiz.de

Diese E-Mail enthält vertrauliche und/oder rechtlich geschützte Informationen. Wenn Sie nicht der richtige Adressat sind oder diese E-Mail irrtümlich erhalten haben, informieren Sie bitte sofort den Absender und löschen Sie diese Mail. Das unerlaubte Kopieren sowie die unbefugte Weitergabe dieser Mail und der darin enthaltenen Informationen sind nicht gestattet.

This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and delete this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden.


--
List: [hidden email]
Info: http://framework.zend.com/archives
Unsubscribe: [hidden email]