Search code examples
phpweb-servicessoapwsdl

SOAP and WSDL Webservice in PHP


I am trying to create a simple web-service with SOAP and WSDL. I use the built in Soap-server for the handling. When i try to run the web-service i get this error:

SOAP-ERROR: Parsing WSDL: Couldn't load from 'E:\xampp\htdocs\PHPWebService\blog.wsdl' : Start tag expected, '<' not found

I have tried putting the Soap-server code in the begin of the code and on the end to see if that resulted in something but it doesn't.

Here is my code:

<?php



    class TestClass{
        public function getVar($var){
            return "Value of var = " + $var;
        }
    }

    $oServer = new SoapServer("blog.wsdl");
    $oServer->setClass("TestClass");
    $oServer->handle();

?>

Solution

  • I used a RESTful webservice now. So this question doesnt have to be answered no more. What i did is i used jakesankey's webservice: https://github.com/jakesankey/PHP-RestServer-Class and run this simple code:

    I hope anyone find this usefull

       <?php
     require_once "RestServer.php";
    
     class Hello
     {
       public function sayHello($name, $poop)
       {
          // RestServer will encode return objects as JSON
          return array("Response" => "Hello, " . $name . " and dont forget ".$poop);
       }
     }
    
     $hello = new Hello();
     $rest = new RestServer($hello);
     $rest->handle();
    
    ?>