Showing posts with label wsdl. Show all posts
Showing posts with label wsdl. Show all posts

Saturday, April 27, 2013

Php making a soap based wsdl server

First create a wsdl file under www/soap/ directory named suppose soap1.wsdl:

<?xml version="1.0"?>
<definitions name="WsdlSoap" targetNamespace="urn:WsdlSoap"
             xmlns:tns="urn:WsdlSoap" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
             xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
             xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
             xmlns="http://schemas.xmlsoap.org/wsdl/">

    <message name="getMyName">
        <part name="name" type="string"/>
    </message>
    <message name="getMyNameResponse">
        <part name="return" type="string"/>
    </message>
    <portType name="WsdlSoapPort">
        <operation name="getMyName">
            <input message="tns:getMyName"/>
            <output message="tns:getMyNameResponse"/>
        </operation>
    </portType>
    <binding name="WsdlSoapBinding" type="tns:WsdlSoapPort">
        <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
        <operation name="getMyName">
            <soap:operation soapAction="urn:WsdlSoapAction"/>
            <input>
                <soap:body use="encoded" namespace="urn:WsdlSoap" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
            </input>
            <output>
                <soap:body use="encoded" namespace="urn:WsdlSoap" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
            </output>
        </operation>
    </binding>
    <service name="WsdlSoapService">
        <port name="WsdlSoapPort" binding="tns:WsdlSoapBinding">
            <soap:address location="http://localhost/soap/server1.php"/>
        </port>
    </service>
</definitions>

/soap/server1.php

<?php
function getMyName($name)
{

    return "Your name: ".$name;

}

$server = new SoapServer("soap1.wsdl");

$server->addFunction("getMyName");

$server->handle();
?>

Call soap:
$soap = new SoapClient("http://localhost/soap/soap1.wsdl");
echo $soap-> getMyName ("Pritom Kumar");
And it prints: "Your name: Pritom Kumar".