How to call a SOAP Web Service from PHP?

In this article we will show to to invoke a JAX-WS Web Service from PHP using the SOAP Client PHP Class.

Coding the Server Side Web Service

Firstly, we will build a sample SOAP Web Service and deploy in on WildFly application Server:

package com.sample;

import javax.jws.WebMethod;    
import javax.jws.WebService;   
import javax.jws.soap.SOAPBinding;   

@WebService(targetNamespace = "", serviceName = "HelloWorldService") 
@SOAPBinding(style = SOAPBinding.Style.RPC)   
public class HelloWorld     
   public String sayHello(String input)   
      return "Welcome " +input + " !";   

Deploy the Web Service. This will expose the following WSDL:

<definitions name="HelloWorldService" targetNamespace="" xmlns="" xmlns:soap="" xmlns:tns="" xmlns:xsd="">
  <types /> 
  <message name="HelloWorld_sayHello">
   <part name="arg0" type="xsd:string" /> 
 <message name="HelloWorld_sayHelloResponse">
  <part name="return" type="xsd:string" /> 
 <portType name="HelloWorld">
 <operation name="sayHello" parameterOrder="arg0">
  <input message="tns:HelloWorld_sayHello" /> 
  <output message="tns:HelloWorld_sayHelloResponse" /> 
 <binding name="HelloWorldBinding" type="tns:HelloWorld">
  <soap:binding style="rpc" transport="" /> 
 <operation name="sayHello">
  <soap:operation soapAction="" /> 
  <soap:body namespace="" use="literal" /> 
  <soap:body namespace="" use="literal" /> 
  <service name="HelloWorldService">
   <port binding="tns:HelloWorldBinding" name="HelloWorldPort">
     <soap:address location="" /> 

Creating the PHP Client

To call a JAX-WS web service from PHP, you can use the PHP SoapClient class. Here is an example of how you can use the SoapClient class to call a JAX-WS web service:

$wsdl = "";
$client = new SoapClient($wsdl);

// Call a web service function with parameters
$response = $client->sayHello(array("name" => "Frank"));

// Print the response

Save this php page in your htdocs Apache folder and verify that the it correctly invokes the JBoss Web Service:


Welcome Frank !

You may also need to set additional options for the SoapClient object, such as the authentication credentials for the web service, or the location of the web service endpoint. You can set these options using the SoapClient’s __setOptions method. For example:

$options = array(
    'login' => 'username',
    'password' => 'password',
    'location' => ''


That’s all! I hope this explains how to invoke a JAX-WS Web service from PHP.