In SOAP web service interaction, you often encounter the need to pass structured data as parameters to the service. When using PHP's SoapClient class, understanding how to properly construct this data is crucial.
Consider the following scenario:
You need to call "FirstFunction" and pass the following data:
The SoapClient class is flexible in handling data structures. However, adhering to the WSDL definition is essential. According to the given WSDL, the "FirstFunction" method expects the parameters to be structured as follows:
struct Contact { id id; name name; } string "string description" int "int amount"
Based on the above structure, the PHP code to make the SOAP call would be:
$contact = new Contact(100, "John"); $params = array( "Contact" => $contact, "description" => "Barrel of Oil", "amount" => 500 ); $client = new SoapClient("http://example.com/webservices?wsdl"); $response = $client->__soapCall("Function1", array($params));
The above is the detailed content of How to Structure Data for SOAP Calls Using PHP's SoapClient?. For more information, please follow other related articles on the PHP Chinese website!