HelloServer12.php - First SOAP 1.2 Server Application

This section provides a tutorial example on how to write a simple SOAP 1.2 server application. The HelloServer.php example defines a hello() function, adds it to the SOAP server, waits for the client program to call.

So far, we have tried only with SOAP 1.1. Can we do some tests with SOAP 1.2? Sure. Here is my hello server modified for SOAP 1.2, HelloServer12.php:

<?php # HelloServer12.php
#- Copyright (c) 2015, HerongYang.com, All Rights Reserved.
#
function hello($someone) { 
   return "Hello " . $someone . "! - SOAP 1.2";
} 
   $server = new SoapServer(null, array(
      'uri' => "urn://www.herong.home/res",
      'soap_version' => SOAP_1_2));
   $server->addFunction("hello"); 
   $server->handle(); 
?>

Here is my hello client modified for SOAP 1.2, HelloClient12.php:

<?php # HelloClient12.php
#- Copyright (c) 2015, HerongYang.com, All Rights Reserved.
#
   $client = new SoapClient(null, array(
      'location' => "http://localhost/HelloServer12.php",
      'uri'      => "urn://www.herong.home/req",
      'soap_version' => SOAP_1_2,
      'trace'    => 1 ));

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

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

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

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

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

Remember to move HelloServer12.php to IIS document directory. Then run HelloClient12.php. You will get:

Returning value of __soapCall() call: Hello world! - SOAP 1.2

Dumping request headers:
POST /HelloServer12.php HTTP/1.1
Host: localhost
Connection: Keep-Alive
User-Agent: PHP SOAP 0.1
Content-Type: application/soap+xml;
   charset=utf-8; action="urn://www.herong.home/req#hello"
Content-Length: 458

Dumping request:
<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope
 xmlns:env="http://www.w3.org/2003/05/soap-envelope"
 xmlns:ns1="urn://www.herong.home/req" 
 xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
 xmlns:enc="http://www.w3.org/2003/05/soap-encoding">
 <env:Body>
  <ns1:hello
   env:encodingStyle="http://www.w3.org/2003/05/soap-encoding">
   <param0 xsi:type="xsd:string">world</param0>
  </ns1:hello>
 </env:Body>
</env:Envelope>

Dumping response headers:
HTTP/1.1 200 OK
Server: Microsoft-IIS/5.1
Connection: close
Content-Type: application/soap+xml; charset=utf-8
X-Powered-By: PHP/5.0.4
Content-Length: 570

Dumping response:
<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope
 xmlns:env="http://www.w3.org/2003/05/soap-envelope"
 xmlns:ns1="urn://www.herong.home/res" 
 xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
 xmlns:enc="http://www.w3.org/2003/05/soap-encoding">
 <env:Body
  xmlns:rpc="http://www.w3.org/2003/05/soap-rpc">
  <ns1:helloResponse
   env:encodingStyle="http://www.w3.org/2003/05/soap-encoding">
   <rpc:result>return</rpc:result>
   <return xsi:type="xsd:string">Hello world! - SOAP 1.2</return>
  </ns1:helloResponse>
 </env:Body>
</env:Envelope>

Now the output is more interesting:

Last update: 2015.

Table of Contents

 About This Book

 Introduction and Installation of PHP 7.0

 PHP Script File Syntax

 PHP Data Types and Data Literals

 Variables, References, and Constants

 Expressions, Operations and Type Conversions

 Conditional Statements - "if" and "switch"

 Loop Statements - "while", "for", and "do ... while"

 Function Declaration, Arguments, and Return Values

 Arrays - Ordered Maps

 Configuring and Sending out Emails

 Retrieving Information from HTTP Requests

 Creating and Managing Sessions in PHP Scripts

 Sending and Receiving Cookies in PHP Scripts

 Controlling HTTP Response Header Lines in PHP Scripts

 MySQL Server Connection and Access Functions

 Functions to Manage Directories, Files and Images

 SOAP Extension Function and Calling Web Services

SOAP Server Functions and Examples

 SoapServer - SOAP Server Class and Functions

 HelloServer.php - First SOAP Server Application

HelloServer12.php - First SOAP 1.2 Server Application

 HelloServerWsdl.php - SOAP 1.2 Server Application in WSDL Mode

 Localization Overview of Web Applications

 Using Non-ASCII Characters in HTML Documents

 Using Non-ASCII Characters as PHP Script String Literals

 Receiving Non-ASCII Characters from Input Forms

 "mbstring" Extension and Non-ASCII Encoding Management

 Managing Non-ASCII Character Strings with MySQL Servers

 Introduction of Class and Object

 Integrating PHP with Apache Web Server

 Outdated Tutorials

 References

 PDF Printing Version