Home > Backend Development > PHP Tutorial > How to Use PHP's SoapClient to Integrate with SOAP Web Services?

How to Use PHP's SoapClient to Integrate with SOAP Web Services?

Barbara Streisand
Release: 2024-12-27 05:02:15
Original
391 people have browsed it

How to Use PHP's SoapClient to Integrate with SOAP Web Services?

How to Integrate PHP SOAP Functionality Using SoapClient

Often, non-Object-Oriented programmers encounter challenges when integrating SOAP functionality into their PHP scripts. Despite having a WSDL file, they may struggle with the correct syntax for invoking SOAP calls.

Setting Up the Connection

To interact with a SOAP service as a client, you can utilize the SoapClient class. Begin by creating an instance of SoapClient with the WSDL file's URL:

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

To retrieve information about available functions and types, use:

var_dump($client->__getFunctions());
var_dump($client->__getTypes());
Copy after login

Constructing the SOAP Call

Now, let's focus on constructing the SOAP call itself. Say you want to invoke the "Function1" function with the following data:

  • Contact ID: 100
  • Contact Name: John
  • General Description: Barrel of Oil
  • Amount: 500

The Data Structure

The WSDL document indicates that Contact is a complex type with two properties: id and name.

The Call Syntax

To make the SOAP call with your desired data, you'll need to use the following syntax:

$params = array(
  "Contact" => new Contact(100, "John"),
  "description" => "Barrel of Oil",
  "amount" => 500,
);
$response = $client->__soapCall("Function1", array($params));
Copy after login

This code creates a new instance of the Contact class with the specified ID and name. It then assembles the request parameters into the $params array and invokes the SOAP call using __soapCall.

The response from the SOAP service will be stored in the $response variable. You can inspect the response to obtain the results of the call.

The above is the detailed content of How to Use PHP's SoapClient to Integrate with SOAP Web Services?. 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