Home > Backend Development > PHP Tutorial > How to Make SOAP Calls Using PHP's SoapClient Class?

How to Make SOAP Calls Using PHP's SoapClient Class?

Barbara Streisand
Release: 2024-12-24 06:16:14
Original
646 people have browsed it

How to Make SOAP Calls Using PHP's SoapClient Class?

Creating SOAP Calls with PHP's SoapClient Class

When working with SOAP services as a client, structuring the proper SOAP call can be challenging. Using PHP's SoapClient class to make such calls can be daunting, especially for those less familiar with object-oriented coding.

Let's take the example of a SOAP function called "FirstFunction" that expects a "Contact" object as one of its parameters. The Contact object possesses the properties "id" and "name." Additionally, it requires a description and an amount.

Creating the SoapClient Object

Begin by referencing the WSDL file to establish a SoapClient object:

$client = new SoapClient("http://example.com/webservices?wsdl");
Copy after login

Structuring the Parameters

To create the "Contact" object, utilize the following code:

$contact = new Contact(100, "John");
Copy after login

Next, define the remaining parameters:

$description = "Barrel of Oil";
$amount = 500;
Copy after login

Combine these parameters into an array:

$params = array(
  "Contact" => $contact,
  "description" => $description,
  "amount" => $amount
);
Copy after login

Invoking the SOAP Call

Finally, invoke the SOAP call using the SoapClient's __soapCall method:

$response = $client->__soapCall("FirstFunction", array($params));
Copy after login

This complete code should successfully execute the desired SOAP call:

id = $id;
        $this->name = $name;
    }
}

$client = new SoapClient("http://example.com/webservices?wsdl");

$contact = new Contact(100, "John");
$description = "Barrel of Oil";
$amount = 500;

$params = array(
  "Contact" => $contact,
  "description" => $description,
  "amount" => $amount
);

$response = $client->__soapCall("FirstFunction", array($params));

var_dump($response);

?>
Copy after login

The above is the detailed content of How to Make SOAP Calls Using PHP's SoapClient Class?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template