Friday, March 21, 2014

A Complete PHP SOAP Server Example




In this tutorial, we will look at how to create a complete PHP SOAP server in WSDL mode. You can take a look at How we generated the WSDL file  for this tutorial.




I assumed that you have already enabled SOAP in your PHP configuration.




From the code below, we first create a simple php class, exampleClass with two functions; boom() and getDate(). We also create corresponding classes, boomResponse and getDateResponse for their return type. From the WSDL file, you will notice that the response type for both boom and getDate is defined as complexType. A complexType is represented as Struct in SOAP, which we can represent as a class in php. Also, note that the names of the response classes must match exactly what you have in your WSDL file.




After creating the appropriate classes for our soap server, we instantiate the PHP SoapServer object in WSDL mode by passing the WSDL file as a parameter. We call the setClass() method on the object to set the class for this soap server and finally call the handle() method to handle soap request.





Kindly leave a comment if you find this tutorial useful. 

7 comments:

  1. This comment has been removed by a blog administrator.

    ReplyDelete
  2. This is clear and easy example I have ever found in entire google search. You are awesome and keep it up good works!

    ReplyDelete
    Replies
    1. How did you get to see the example page

      Delete
  3. Good way to learn php web service soap server for starters!!!

    ReplyDelete
  4. Its dropping me this:

    string(182) "
    Parse error: syntax error, unexpected ' ' (T_STRING), expecting function (T_FUNCTION) in C:\xampp\htdocs\example\exampleClassServer.php on line 5
    "
    when i call it with your tutorial
    Send SOAP request XML via PHP cURL

    Any ideas?

    ReplyDelete
    Replies
    1. @Robert, there seems to be extra unicode characters (unicode) in your file. These characters are introduced during copy and paste which caused the php parser to throw the above error. Simply copy and paste the codes sample in notepad first and then copy from notepad to your exampleClassServer.php file.

      Delete

Related Posts Plugin for WordPress, Blogger...