Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I had massive problems when I tried to learn SOAP (thank fully for no other reason than extension of knowledge). Here is how I ended up getting it going:</p> <p>Step1: Download PHP2WSDL class from PHPClasses.org</p> <p>Step2: Generate WSDL with the following code require_once("PHPClasses/PHP2WSDL/WSDLCreator.php");</p> <pre><code>$test = new WSDLCreator("WSDLTester", "http://localhost/soap/SoapServer/"); //$test-&gt;includeMethodsDocumentation(false); $test-&gt;addFile("servicefunctions.php"); $test-&gt;addURLToClass("servicefunctions", "http://localhost/soap/SoapServer/server.php"); //$test-&gt;ignoreMethod(array("example1_1"=&gt;"getEx")); $test-&gt;createWSDL(); $test-&gt;saveWSDL("/path/to/dir/SoapServer/test.wsdl"); </code></pre> <p>I stored the above in a file called wsdl.php, which you then visit in the browser to generate the wsdl file. <strong>Note: The important thing is to put your class and the url of the soap server you create as the url in addURLToClass - as that is how your server goes into the wsdl to be called properly</strong></p> <p>The code for ServiceFunctions.php is below for completeness:</p> <pre><code>class servicefunctions { /** * stringifies * * @param string $string * @return string */ public function stringify(string $string) { return "I took the " . $string . " and stringified it"; } /** * Adds two numbers * * @param int $number1 * @param int $number2 * @return string */ public function addify(int $number1,int $number2) { $answer = ($number1 + $number2); $string = "the answer is " . $answer; return (string)$string; } } </code></pre> <p>Note the use of comments to enter the var types, which is then used by PHP2WSDL and in the resulting wsdl file.</p> <p>Then this creates the server:</p> <pre><code>try { $server = new SOAPServer("/home/liam/DevEnv/SoapServer/test.wsdl",array('cache_wsdl'=&gt;WSDL_CACHE_NONE)); $server-&gt;setClass("servicefunctions"); $server-&gt;handle(); } catch (SOAPFault $f) { print "ERROR".$f-&gt;faultstring; } </code></pre> <p>and this the client:</p> <pre><code>try { $client = new SoapClient("/home/liam/DevEnv/SoapServer/test.wsdl",array('cache_wsdl'=&gt;WSDL_CACHE_NONE)); echo print_r($client-&gt;__getFunctions(),true) . "&lt;br/&gt;"; echo $client-&gt;stringify("test new"); } catch (SOAPFault $f) { print "ERROR" . $f-&gt;faultstring; } </code></pre> <p>Outputs:</p> <pre><code>Array ( [0] =&gt; string addify(integer $number1, integer $number2) [1] =&gt; string stringify(string $string) ) I took the test new and stringified it </code></pre> <p>I am sure you can easily convert this to your class.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload