PHP soap client example

Hi guys, today I want to focused on a simple php thing: soap client. I found this very important in my last project so I want to share with you something about this. First of all it’s important to understand how vsld describe the method that client can call. An example of vsld is the following:

 
<message name="UserEnabled">
   <part name="parameters" element="tns:UserEnabled">;
</message>

<xs:element name="UserEnabled">
<xs:complexType>
<xs:sequence>
<xs:element name="userId"type="xs:int" />
</xs:sequence>
</xs:complexType>
</xs:element>

This is the description of a method interface for a generic soap server that manages some connection. In particular this method enable user at the operations on that server. Now we can implement the client for this vsdl, is very easy code:

$client = new SoapClient("http://serviceaddress/data/user.wso?wsdl");
$result = $client→UserEnabled(array('userId'=>$userId));

We can call the method exposed in the vsdl like a method of the instantiated soap client! Is very powerful!

Now, If you want to use this into a method, an example of implementation is something like this:

/**
 *
 * @param integer $userId
 * @return boolean
 */
 public function UserEnabled($userId)
 {
   $result = $this->signAction->UserEnabled(array('userId'=>(int)$userId));
   $ret = false;
   if($result->res == "OK")
   {
     $ret = true;
   }
   return $ret;
 }

See you soon bye bye!