HelloServerWsdl.php - SOAP 1.2 Server in WSDL Mode

This section describes a tutorial example of a complete SOAP application with both server and client programs using SOAP 1.2 in WSDL mode.

Now let's move forward one step further: creating a SOAP 1.2 server application in WSDL mode. Here is the same hello server modified to work in WSDL mode, HelloServerWdsl.php:

# HelloServerWsdl.php
# Copyright (c) HerongYang.com. All Rights Reserved.
function hello($someone) { 
   return "Hello " . $someone . "! - With WSDL";
   ini_set("soap.wsdl_cache_enabled", "0"); 
   $server = new SoapServer("http://localhost/Hello.wsdl",
      array('soap_version' => SOAP_1_2));

Nothing special in the program. The server object is now created with the location of the WSDL document.

Here is the WSDL document, Hello.wsdl

<?xml version="1.0"?>
<!-- Hello.wsdl
- Copyright (c) HerongYang.com. All Rights Reserved.
<definitions name="MyDefinition" 
 <message name="myRequest">
  <part name="reqParam" type="xsd:string"/>
 <message name="myResponse">
  <part name="resParam" type="xsd:string"/>
 <portType name="MyPortType">
  <operation name="hello">
   <input message="tns:myRequest"/>
   <output message="tns:myResponse"/>
 <binding name="MyBinding" type="tns:MyPortType">
  <soap:binding style="rpc"
  <operation name="hello">
   <soap:operation soapAction=""/>
    <soap:body use="encoded"
    <soap:body use="encoded"
 <service name="MyService">
  <documentation>Returns a greeting string.
  <port name="MyPort" binding="tns:MyBinding">

The WSDL document looks complicated. But it actually very simple to understand, as long as you remember the following points:

To install HelloServerWsdl.php to my Apache server, copy these two files to the Apache document directory:

C:\herong>copy HelloServerWsdl.php \local\apache\htdocs
C:\herong>copy Hello.wsdl \local\apache\htdocs

Of course, we need to modify our hello client program as, HelloClientWsdl.php:

# HelloClientWsdl.php
# Copyright (c) HerongYang.com. All Rights Reserved.
   $client = new SoapClient("http://localhost/Hello.wsdl",
      array('soap_version' => SOAP_1_2,'trace' => 1 ));

   echo("\nDumping client object functions:\n");

   $return = $client->__soapCall("hello",array("world"));
   echo("\nReturning value of __soapCall() call: ".$return);

#   $return = $client->hello("world");
#   echo("\nReturning value: ".$return);

   echo("\nDumping request headers:\n" 

   echo("\nDumping request:\n".$client->__getLastRequest());

   echo("\nDumping response headers:\n"

   echo("\nDumping response:\n".$client->__getLastResponse());

When you are ready to test, run HelloClientWsdl.php. You will get:

C:\herong>php HelloClientWsdl.php

Dumping client object functions:
array(1) {
  string(30) "string hello(string $reqParam)"

Returning value of __soapCall() call: Hello world! - With WSDL
Dumping request headers:
POST /HelloServerWsdl.php HTTP/1.1
Host: localhost
Connection: Keep-Alive
User-Agent: PHP-SOAP/7.0.2
Content-Type: application/soap+xml; charset=utf-8; action=""
Content-Length: 457

Dumping request:
<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope"
  <ns1:hello env:encodingStyle="http://www.w3.org/2003/05/soap-encoding">
   <reqParam xsi:type="xsd:string">world</reqParam>

Dumping response headers:
HTTP/1.1 200 OK
Date: Sun, 02 Sep 2018 18:50:59 GMT
Server: Apache/2.4.12 (Win32) PHP/7.0.2
X-Powered-By: PHP/7.0.2
Content-Length: 573
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: application/soap+xml; charset=utf-8

Dumping response:
<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope"
 <env:Body xmlns:rpc="http://www.w3.org/2003/05/soap-rpc">
   <resParam xsi:type="xsd:string">Hello world! - With WSDL</resParam>

Anything interesting here? Yes. Some names defined in the WSDL document did show up in the SOAP request message and response message, like: "urn:myInputNamespace", "reqParam", "urn:myOutputNamespace", etc.

Table of Contents

 About This Book

 Introduction to Web Service

 Introduction to SOAP (Simple Object Access Protocol)

 SOAP Message Structure

 SOAP Message Transmission and Processing

 SOAP Data Model

 SOAP Encoding

 SOAP RPC Presentation

 SOAP Properties Model

 SOAP MEP (Message Exchange Patterns)

 SOAP HTTP Binding

 SOAP PHP Implementations

 PHP SOAP Extension Client Programs

PHP SOAP Extension Server Programs

 PHP SOAP Extension Functions for Server Programs

 HelloServer.php - First SOAP Server Application

 HelloServer12.php - SOAP 1.2 Server Application

HelloServerWsdl.php - SOAP 1.2 Server in WSDL Mode

 HelloServerWsdl2.php - SOAP 1.1/1.2 Server in WSDL Mode

 PHP SOAP Web Service Example - getTemp

 SOAP Perl Implementations

 Perl SOAP::Lite - SOAP Server-Client Communication Module

 Perl Socket Test Program for HTTP and SOAP

 Perl SOAP::Lite for NumberToWords SOAP 1.1 Web Service

 Perl SOAP::Lite for SOAP 1.2 Web Services

 Perl SOAP::Lite for WSDL

 SOAP Java Implementations

 Java Socket and HttpURLConnection for SOAP

 SAAJ - SOAP with Attachments API for Java

 SoapUI - SOAP Web Service Testing Tool

 WS-Security - SOAP Message Security Extension

 WS-Security X.509 Certificate Token

 Perl SOAP::Lite for GetSpeech SOAP 1.1 Web Service

 Perl SOAP::Lite 0.710 for SOAP 1.2 Web Services

 Perl SOAP::Lite 0.710 for WSDL

 Web Services and SOAP Terminology

 Outdated Tutorials


 Full Version in PDF/EPUB