SOAP

1. 
Success !
(1)
Read article:
http://www.greenacorn-websolutions.com/php/working-with-nusoap.php

(2) download:
http://sourceforge.net/projects/nusoap/
  unzip into C:\xampp\htdocs\testSOAP\
    include lib, samples two folders
(3)
create food.php
--------------------------
        <?php
        require_once "lib/nusoap.php";
         
        class food {
         
            public function getFood4($type) {
                switch ($type) {
                    case 'starter':
                        return 'Soup33';
                        break;
                    case 'Main':
                        return 'Curry33';
                        break;
                    case 'Desert':
                        return 'Ice Cream33';
                        break;
                    default:
                        break;
                }
            }
        }
         
        $server = new soap_server();
        $server->configureWSDL("foodservice", "http://www.greenacorn-websolutions33.com/foodservice");
         
        $server->register("food.getFood4",
            array("type" => "xsd:string"),
            array("return" => "xsd:string"),
            "http://www.greenacorn-websolutions33.com/foodservice",
            "http://www.greenacorn-websolutions33.com/foodservice#getFood4",
            "rpc",
            "encoded",
            "Get food by type");
         
        @$server->service($HTTP_RAW_POST_DATA);
        ?>
------------------------------------
(4) browse http://localhost/TestSoap/food.php?wsdl get xml result,
copy and save to food.wsdl file:
--------------------------------------------------
        <?xml version="1.0" encoding="ISO-8859-1"?>
        <definitions xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="http://www.greenacorn-websolutions33.com/foodservice" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://www.greenacorn-websolutions33.com/foodservice">
            <types>
                <xsd:schema targetNamespace="http://www.greenacorn-websolutions33.com/foodservice">
                    <xsd:import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
                    <xsd:import namespace="http://schemas.xmlsoap.org/wsdl/"/>
                </xsd:schema>
            </types>
            <message name="food.getFoodRequest">
                <part name="type" type="xsd:string"/>
            </message>
            <message name="food.getFoodResponse">
                <part name="return" type="xsd:string"/>
            </message>
            <portType name="foodservicePortType">
                <operation name="food.getFood4">
                    <documentation>Get food by type</documentation>
                    <input message="tns:food.getFoodRequest"/>
                    <output message="tns:food.getFoodResponse"/>
                </operation>
            </portType>
            <binding name="foodserviceBinding" type="tns:foodservicePortType">
                <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
                <operation name="food.getFood4">
                    <soap:operation soapAction="http://www.greenacorn-websolutions33.com/foodservice#getFood4" style="rpc"/>
                    <input>
                        <soap:body use="encoded" namespace="http://www.greenacorn-websolutions33.com/foodservice" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
                    </input>
                    <output>
                        <soap:body use="encoded" namespace="http://www.greenacorn-websolutions33.com/foodservice" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
                    </output>
                </operation>
            </binding>
            <service name="foodservice">
                <port name="foodservicePort" binding="tns:foodserviceBinding">
                    <soap:address location="http://localhost/testSOAP/food.php"/>
                </port>
            </service>
        </definitions>

--------------------------------------------------
(5)
create foodclient.php:
----------------------------------------------------
    <?php
    require_once "lib/nusoap.php";
     
    $client = new nusoap_client("food.wsdl", true);
    $error  = $client->getError();
     
    if ($error) {
        echo "<h2>Constructor error</h2><pre>" . $error . "</pre>";
    }
     
    $result = $client->call("food.getFood4", array("type" => "Main"));
     
    if ($client->fault) {
        echo "<h2>Fault</h2><pre>";
        print_r($result);
        echo "</pre>";
    } else {
        $error = $client->getError();
        if ($error) {
            echo "<h2>Error</h2><pre>" . $error . "</pre>";
        } else {
            echo "<h2>Main</h2>";
            echo $result;
        }
    }
     
    // show soap request and response
    echo "<h2>Request</h2>";
    echo "<pre>" . htmlspecialchars($client->request, ENT_QUOTES) . "</pre>";
    echo "<h2>Response</h2>";
    echo "<pre>" . htmlspecialchars($client->response, ENT_QUOTES) . "</pre>";
    ?>

----------------------------------------------------
browse it: http://localhost/testSOAP/foodclient.php

will see:
=======================================
    Main

    Curry33
    Request

    POST /testSOAP/food.php HTTP/1.0
    Host: localhost
    User-Agent: NuSOAP/0.9.5 (1.123)
    Content-Type: text/xml; charset=ISO-8859-1
    SOAPAction: "http://www.greenacorn-websolutions33.com/foodservice#getFood4"
    Content-Length: 605

    <?xml version="1.0" encoding="ISO-8859-1"?><SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="http://www.greenacorn-websolutions33.com/foodservice"><SOAP-ENV:Body><tns:food.getFood4 xmlns:tns="http://www.greenacorn-websolutions33.com/foodservice"><type xsi:type="xsd:string">Main</type></tns:food.getFood4></SOAP-ENV:Body></SOAP-ENV:Envelope>
    Response

    HTTP/1.1 200 OK
    Date: Sat, 14 Mar 2015 16:00:39 GMT
    Server: Apache/2.4.10 (Win32) OpenSSL/1.0.1i PHP/5.6.3
    X-Powered-By: PHP/5.6.3
    X-SOAP-Server: NuSOAP/0.9.5 (1.123)
    Content-Length: 563
    Connection: close
    Content-Type: text/xml; charset=ISO-8859-1

    <?xml version="1.0" encoding="ISO-8859-1"?><SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><ns1:food.getFood4Response xmlns:ns1="http://www.greenacorn-websolutions33.com/foodservice"><return xsi:type="xsd:string">Curry33</return></ns1:food.getFood4Response></SOAP-ENV:Body></SOAP-ENV:Envelope>

=======================================
(6)
try proxy:
Create foodclient2.php
----------------------------------------------
<?php
require_once "lib/nusoap.php";
//require_once "lib/nusoap.php";
 
$client = new nusoap_client("food.wsdl", true);
 
$proxy = $client->getProxy();
echo $proxy->food__getFood4('Main');
?>
-----------------------------------------------
Browse it: http://localhost/testSOAP/foodclient2.php
will see:
    http://localhost/testSOAP/foodclient2.php

Done !    
  
  

http://localhost/testSOAP/foodclient.php

 

1.
Working with PHP NuSOAP
http://www.greenacorn-websolutions.com/php/working-with-nusoap.php
code: http://sourceforge.net/projects/nusoap/

Good: work !
http://localhost/php_try/01_nusoap-0.9.5/samples/wsdlclient1.php
H:\Tutoring2014\2015.03.07_Soap\01_nusoap_0.9.5\nusoap-0.9.5\samples\wsdlclient1.php

2.
NuSOAP for PHP 5.3
http://sourceforge.net/projects/nusoapforphp53/
H:\Tutoring2014\2015.03.07_Soap\02_NuSOAP_php53\
not work.

3.
PHP NuSOAP Tutorial, 2010
http://www.codeproject.com/Articles/140189/PHP-NuSOAP-Tutorial
H:\Tutoring2014\2015.03.07_Soap\03_NuSOAP_Tutorial\

Hello World: 
http://localhost/php_try/03_nusoaphelloworld/#

4.
http://api.yandex.com/direct/doc/dg-v4/examples/php-sample1.xml
SOAP (NuSOAP class)