Patrick's playground

Random thoughts, problems and solutions

Simple PHP SOAP example

This post will show a simple example of how to interpretate a WSDL file and a very simple, yet quick example of how to extract information from this file through PHP.

Prior assumptions

In this example I assume that you've already have SOAP enabled in your PHP configuration because this is beyond the scope of this example. If you're not sure, you can check your phpinfo file. There should be something like this:

SOAP information

SOAP information

Example WSDL file

For the example WSDL file we'll take this WSDL file. It's about the World Championship football 2010 held in South Africa.

Analyzing the WSDL file

Let's analyze this file for a simple method we can call. I usually work with Notepad++ or Smultron. The following line number apply to Notepad++ and probably also to Smulton.

Let's try and print the top goal scorers of the tournament. For doing this, we can see the following on line 1295 - 1300:

<operation name="TopGoalScorers">
Returns an array with the top N goal scorers and their current score. Pass 0 as TopN and you get them all.
  <input message="tns:TopGoalScorersSoapRequest"/>
  <output message="tns:TopGoalScorersSoapResponse"/>

We now see that the operation we should call is called TopGoalScorers. This operation expects as input a TopGoalScorersSoapRequest. We don't know what it is yet, so let's find out. If we search the document for this message, we get to line 999 - 1002 which says:

<message name="TopGoalScorersSoapRequest">
  <part name="parameters" element="tns:TopGoalScorers" />

Right. So now we know that the TopGoalScorersSoapRequest consists of just one part (the parameters). We know that the element is called TopGoalScorers, but we do not know anything about this parameter yet. So we search the document for the element TopGoalScorers. We can find this element at line 384 - 390. These lines say

<xs:element name="TopGoalScorers">
      <xs:element name="iTopN" type="xs:int" />

Now there we have it: we now finally know that the method TopGoalScorers which we saw in the first WSDL fragment expects one parameter as input. This parameter is called iTopN and is of the type int.

Getting to the code

Finally we can do something with the WSDL. Actually we can do this in a very short way thanks to the PHP SoapClient!

Calling the service with the parameter and obtaining the results can be done in just 2 lines of code. Let's give it a try and obtain the top 5 goal scorers. We can do this by the following two lines:

$client = new SoapClient("");
$result = $client->TopGoalScorers(array('iTopN'=>5));

Note that we use the information we obtained from the WSDL file here: on the $client object, we call the method TopGoalScorers and provide an array of parameters. In this case the array contains only one parameter: the iTopN parameter with an int value of 5.

The result will contain an object, so you will need to traverse the object structure.

Choose how much results

There are a lot of possibilities for abstracting such a Web Service call further. I will just give a very simple example file where you can choose how many results you want to see and visualize this in a table.



if ($_POST['topn'] > 0 && (int) $_POST['topn'] <= 20){
  $topn = (int) $_POST['topn'];
  $client = new SoapClient("");
  $result = $client->TopGoalScorers(array('iTopN' => $topn));
  // Note that $array contains the result of the traversed object structure
  $array = $result->TopGoalScorersResult->tTopGoalScorer;

  print "
    <table border='2'>
  foreach($array as $k=>$v){
    print "
        <td align='right'>" . ($k+1) . "</td>
          <td>" . $v->sName . "</td>
          <td align='right'>" . $v->iGoals . "</td>
  print "</table>";
else {


  <form id="topscorers" action="index.php" method="post">
    How long should your topscorers list be? (Choose a digit between 1 and 20).
    <input id="topn" name="topn" size="2" type="text" value="10" />
    <input id="submit" name="submit" type="submit" value="submit" />




Note that the form calls index.php. This is because I called this script index.php. If you call your script differently, the action should be your script file name. (The reason why I didn't use $_SERVER['PHP_SELF'] is because of this Dutch source about how this element can cause an XSS problem).

I hope you found the example useful. If not, let me know! Now go and play with PHP, SOAP and WSDL some more!

Edit 11/08/2010: Noticed that the WSDL was removed. Changed to WC 2010 WSDL file which seems to have the same format as the original WSDL.

Be Sociable, Share!


    It’s been a while


    Python ParserFactory


    1. this is great work done but i want to work on it do send me example of the code that you use

    2. Vanessa B

      Thanks this help me a lot…. you’re great

    3. Patrick, thanks for this simple and clear example!

    4. Vanessa

      This code is great…. You’ve done a really good job

    5. is this a drupal site?

    6. Andrew,

      This is not a Drupal site, but just a WordPress site.

      People who didn’t notice it yet and read asad’s comment: this is all the code there is!

    7. Lan

      Thank you so much.

      If you can also provide the XML message in HTTP for Soap request and Soap response, that would be better. Maybe I’m somewhat lazy, because I can do it by myself. : -)

      Anyway, your simple example helps me a lot…

    8. Hi Lan,

      These messages are all handled by the PHP Soapclient. Most languages already provide you with such classes / libraries. E.g. for Python you have SoapPy and Soaplib.

    9. Douwe

      Excellent example! Helped me a lot

    10. Joseph

      Thank you very much!
      Finally I have found an example that is clear and understandable.

      Best wishes

    11. ADAM

      Hi Patrick,
      It is a good example, Could you please mail in my email ID. I need your help for implementing SOAP-PHP.
      Please email me.
      Thank you

    12. ADAM,

      Perhaps it’s more useful to discuss such things here. This way more people can benefit from the knowledge..


    13. GS

      Hi Patrick,

      Can you please guide me regarding how to use soap headers for sending user credentials in php. I am getting “Invalid Credentials Error” soap protocol with faultcode as soap-server. Don’t know how to fix it please help me out in this if possible.


    14. Hi GS,

      An example SOAP message containing user credentials can be found here.
      Which programming language do you use? This post shows that .NET may put an anchor in the message, which results in an Invalid Credentials Error.

      Hopefully this can be of help. If not, please let me know.



    15. Wilbo

      Great tut, very clear – only I can’t get it to work!
      Soap is intalled on the server, the wsdl file is still there, but when I run the script I just get the old Cannot Display the Webpage message
      Any ideas?

    16. Wilbo,

      I’ve added the source file here.
      On my machine it works with this script.. (php_soap should be enabled of course).

    17. Tomas

      Hello, If I start index.php evrithing is ok and I write a long of top list and click on submit then it write: Fatal error: Class ‘SoapClient’ not found in W:\docs\SOAP\index.php on line 14. Where I have to define class SoapClient.

      Thanks for your answer.

    18. Hi Tomas,

      SoapClient is a php extension which can be enabled in the php (ini) config of the web server.

    19. Cybufex

      Thanks to this post I was able to determine that the problem I had had nothing to do with my programming skills but rather everything to do with the STUPID ISA server our company uses.

      Thanks for your post.

    20. Ayaz Pasha

      Hi Patrick, I will have to pass the soap request via proxy server. Unfortunately I don’t know PHP, can you let me know how can I have this code working for having a proxy server.

    21. Ayaz Pasha

      Any idea? Still stuck with the same issue from past 2 days. Any comment regarding this issue will be of greater help.

    22. Ayaz Pasha

      Finally got it to work.

      $client = new SoapClient(“http://someaddress?WSDL”, array(‘proxy_host’ => “”,’proxy_port’ => portnumber));

    23. Hi Ayaz,

      I just saw your remarks from this morning. I thought that you were running a proxy server yourself. I misunderstood your actual question.
      Thanks for posting this information anyway!

    24. Ayaz Pasha

      Thnks Patrick, I have another issue now, while I was using apache I was able to successfully get this code working and result was being displayed but now I installed & configured IIS for PHP, henceforth I am getting an empty result for this code (there are no any fatal errors though). Any help?

      Sorry if I am posting something that is out of scope for this blog.

    25. Ayaz,

      Are all required modules present? I don’t have any experience with IIS I must admit.
      If there aren’t any errors or warnings debugging is pretty hard. Can you actually run other PHP scripts which generate output?
      Does the server log itself say anything which could be of use?

    26. Ayaz Pasha


      My team mate installed a new version of PHP & it worked all fine again, thanks for help. You are right, may be some modules were not enabled(like soap client).

      Thnks for the help, this blog helped me a lot.

    27. 🙂 nice sample code … thank you

    28. Simple and Awesome !!!! …. Thanks 🙂

    29. MockY

      Simple and to the point. SOAP demystified. Thanks.

    30. excellent job… its awsome… 😉

    31. Jen

      I cannot get this to work .. i’m hoping you can help once i hit the client call i get nothing after that i.e. (stops my script, blank page) …

    32. Hi Jen,

      Does your php error_log tell you anything? The page is completely blank. When I look at the page source, it’s also completely blank. Seems like an error is occurring before the output is started.


    33. Jen

      are you saying to enable error logging and have it log to a file… im on a vps with plesk 8.6 and i’ve seen some posts about problems with plesk and soap. that being said, this is my first time around trying to implement a web service, so i think i’ll just stick my nose back into chapter 18 (SOAP) of pro php and xml services for now to ensure i am taking the right steps…


    34. I also use a Plesk VPS and it was preconfigured to log to a file. When developing in PHP, it is always advised to use the error logging 😉

    35. Kiran

      Hi Patrick,

      I am implementing soap php. I can able to call your wsdl file. But my client has given one wsdl url. In that client has defined custom types. I dont know how to pass custom type argument. Can you give a sample example.

      HOw will I call sopaclient function

    36. Hi Kiran,

      My apologies for my late response. Can you give an example what such a custom type looks like? I assume such a custom type consists of ‘basic’ types like string or int. In that case you should perform and extra operation to put together such a custom type and then pass it as a parameter.

      Kind regards,


    37. Hi Patrick,

      I’ve tried your code, and i works perfectly… Well i’m new about web service, so I’ve a question.

      in your code :
      $client = new SoapClient(“”)

      but when I changed it to :
      $client = new nusoap_client(“”);

      it shows an error. So what’s the diference ? I usually use nusoap for learn about web service.

      Sorry for the newbie question..

    38. Hi qill,

      Everyone’s gotta start somewhere 😉
      What does the error tell you? Did you check the php error_log for any more details regarding the error? And are you using a kind of custom class?
      I did a little search on nusoap examples and all the hits I got use the same lines as the SoapClient example shown above:

      $client = new soapclient($wsdl, true);

      instead of

      $client = new nusoap_client($wsdl);



    39. the error is “Fatal error: Call to undefined method nusoap_client::TopGoalScorers() in C:\xampp\htdocs\ws_2\fbtopscorer.php on line 18”

      I use new version of nusoap for study about web service (nusoap-0.9.5)
      And yes.. some example they use $client = new soapclient($wsdl, true);
      but when I try it, it showed an error…

      but when I try $client = new nusoap_client($wsdl);, it works…so I started to use it to create new client object…
      my guess is maybe it because I use it in localhost (not connect in Internet)? is that true ???

      my second question is, I use your code to display all coaches. (

      It works, but I want to display their team info too.. can you help me ??

    40. Hi qill,

      You can use it from your localhost as long as you’re running a proper LAMP/WAMP/MAMP stack with the right extensions.
      You connect to the remote wsdl file, right?
      Which team info do you actually want to display? There is a team info tag nested in the coaches result. This can be accessed directly from the results you get back from the SOAP call. If you want other data to be displayed you probably need to do this in more than one step.

      Was this helpful for you?



    41. Yes…I connect to the remote wsdl… thanks, that makes sense…

      When we invoke coaches function, it return coaches name and team info tag nested (like you mention above)… and I realise that the result will be return as an array.

      but I’m not sure how to manipulate the result in order to display the team info (because it nested)…can you show me the code if I want to show like :
      maradona | argentina | argentina’s flag | argentina url
      capello | england | england’s flag | england url

      it’s just about array manipulation right ???

    42. Yes, it’s just about array manipulation.
      If you look at line 8 of the last code fragment you can see that you can also traverse the results in a way.

      Suppose that $result in this case is the CoachesResult you get from your soap client call.
      You can do $result->CoachesResult->tCoaches to get the coaches
      if you take $v as a tCoaches object, you can access the TeamInfo by getting $v->TeamInfo.

      For directly accessing the team info you can use $result->CoachesResult->tCoaches->TeamInfo

      Hope this helps!


    43. great…that works… thanks patrick

    44. nosebleed

      Hey, I have a question. How do you connect actually to the database to get the results? Thanks.

    45. Hi nosebleed,

      Do you mean at the server side? The WSDL file does nothing more than denote the remote method that’s called and the data format that will be returned.
      Basically the client’s calling a remote method. That method runs at the server, connects to its database and returns the data (in the format the WSDL describes). There’s nothing different than normal to it.

      Hopefully that answers your question. If not, please reply.



    46. ali

      I created a service using wsdl. I am passing two parameters to my port. but second parameter has no effect could any body tell me why??

    47. Anthony

      Its nice job,

      Is anyone knows how to make a soap server, like a creating a web service and wsdl file according to that?

      then anyone can send request by soap client..

    48. Chaitanya


    49. Pete

      Hey great example, works out of the box. Thanks very much (edited the latter part, Patrick)

    50. AtReyU

      Rocking, thanks so much, this has helped me a ton. Had to teach myself how to use SOAP today and you made that very possible.

    51. This code is not woking for me or may it is taking too much time. Because I didnot see any display for this code. Please help in this regard.


    52. Ihsanullah,

      Is there any output? Have you checked the error_log for messages? This could help you solve the problem faster.



    53. Stephan

      Thanks, works great 🙂

    54. baljit

      great work

    55. Farooq

      Hi Patrick,
      here is a link to wsdl file i want to know if we can make calls through this wsdl file as it seems different from the one which you used..
      here is the link:

      Will be waiting for your response,

      Thank you.


    56. Hi Farooq,

      The file indeed is not structurally 100% the same. There’s some more puzzling involved. Let’s take an example:

      WSDL part

      In this case we have an element ‘operation name’, which is LookupNAICSDetails. It’s kind of the same structure as I mentioned above. You see the documentation tag (which is not filled in, so that’s of no use), but also the the input structure, the structure you get back and also which structure(s) will be returned when an error occurs.
      So you need to put in a structure called IBusinessProcess_LookupNAICSDetails_InputMessage and you get back an IBusinessProcess_LookupNAICSDetails_OutputMessage. The structure of these messages can be found in the WSDL as well.

      Hope this helps you!


    57. Judhisthira


      Thanks,.I am new to SOAP-PHP.
      I not getting the things..I have a class(Wether) in server who has method named ReturnTodayWeather.I have the wsdl file in server for the Wether class.How i will call the web service using WSDL. in client website.

      Kindly give a test mail from your mail id.
      I need your help very badly to implement SOAP service.

      [removed e-mailaddress to reduce spam]

    58. Vishnu

      Hi Patrick,
      Heartfelt thanks for the great article. I particularly liked your lucid methodology.
      I am from Java background and have started using PHP for using Drupal (i.e customizing it).
      I was able to refer a PHP soap example.
      This works perfectly.
      But for a web service i need to hit -an https link i have been struggling
      to get it running.
      This wsdl file has a “Logon” method which when passed the Username and password will return me a ticket to be used for the user session.

      I am able to hit the web service method via PHP but it returns me a “User invalid error” instead of the ticket thrown by the source
      hosting the web service.
      I am able to obtain the required ticket when i use Eclipse via Java and its web client option.
      So the only difference there is that i have all the stubs and skeletons i.e. the dependencies auto created by eclipse in java;
      when used with java owing to which i am able to call the method appropriately

      Would like to know ifthere is a way to have the set of dependencies generated for a PHP based approach for consuming a web service.

      Thanks & Regards
      Vishnu S

    59. Judhisthira,

      You have the WSDL file, so you know the location, right? I would start off with:
      $wsdlfile = ;
      $client = new SoapClient($wsdlfile);

      That should initialize the soapclient. From there on you should be able to do method calls.
      If you still encounter difficulties, please explain your problem more thoroughly.



    60. Hi Vishnu,

      That’s an interesting one! Are you sure the right information is received by the web service? Seeing the error, it seems like the dispatching method does its job, but doesn’t get the right information. Is it possible to check server sided if the parameters are received in good order? It could have something to do with how data is sent. This could be different in Eclipse than it is when doing directly via PHP.
      As long as the SoapClient is working it should be okay. I haven’t came across dependencies on other packages.
      Hope this points you in the right direction. If not, please tell me.



    61. Shahriar

      Thanks, great article for beginners.

    62. Why don’t you just use ?

      Then the filename can be everything.

    63. M ZUBAIR

      good work! very helpful, thanks alot

    64. Mehul

      Hello Patrick,

      Wonderful Article. I am working on a project which requires authentication to access the operations. Can you please provide me the utility used to do the same in php?

    65. derjanni

      Nice article. I did a tutorial with NuSOAP in PHP in German as well … maybe someone’s interested in it:

      Best regards,


    66. Aashish

      in my case the operation is getProductDetails, which takes parameter of type
      productinfo as shown below!

      how do handle this?

    67. This is nice example with considerabl information, I was learning SOAP from W3Schools but this is more practical.

    68. Vas

      Hi Patrick,

      Fist of all great example/tutorial.
      I run your example without any issue on my website, however, once I changed to my own example i got an error.
      I have been struggling for few days but I have no luck .
      Hope you could help me figure it out.
      Here is part of the code which im using:

      password is a string
      username is an integer.

      $client = new SoapClient(“http://myURL.wsdl?WSDL”);
      $result = $client->CityList(array(‘username’=>123456,’password’=>’0123456’));
      At the above line I get the folling error:

      Fatal error: Uncaught SoapFault exception: [soap:Server] System.Web.Services.Protocols.SoapException:
      Server was unable to process request. —>
      System.NullReferenceException: Object reference not set to an instance of an object.
      at BIWS.BIWebService.LoginUser(SqlConnection myConn) at BIWS.BIWebService.CityList()
      — End of inner exception stack trace
      — in C:\Inetpub\vhosts\\httpdocs\webservice\ws.php:68
      Stack trace: #0 [internal function]: SoapClient->__call(‘CityList’, Array)
      #1 C:\Inetpub\vhosts\\httpdocs\webservice\ws.php(68): S
      oapClient->CityList(Array) #2 {main} thrown in
      C:\Inetpub\vhosts\\httpdocs\webservice\ws.php on line 68

      Here is a list of function which I get from the server:
      array(16) {
      string(53) “ShowBasicsResponse ShowBasics(ShowBasics $parameters)”
      string(56) “ShowDetailsResponse ShowDetails(ShowDetails $parameters)”
      string(59) “PerformancesResponse Performances(Performances $parameters)”
      string(122) “PerformancesPOHPricesAvailabilityResponse PerformancesPOHPricesAvailability(PerformancesPOHPricesAvailability $parameters)”
      string(59) “PremiumSeatsResponse PremiumSeats(PremiumSeats $parameters)”
      string(47) “CityListResponse CityList(CityList $parameters)”
      string(47) “NewOrderResponse NewOrder(NewOrder $parameters)”
      string(50) “HeartbeatResponse Heartbeat(Heartbeat $parameters)”
      string(53) “ShowBasicsResponse ShowBasics(ShowBasics $parameters)”
      string(56) “ShowDetailsResponse ShowDetails(ShowDetails $parameters)”
      string(59) “PerformancesResponse Performances(Performances $parameters)”
      string(122) “PerformancesPOHPricesAvailabilityResponse PerformancesPOHPricesAvailability(PerformancesPOHPricesAvailability $parameters)”
      string(59) “PremiumSeatsResponse PremiumSeats(PremiumSeats $parameters)”
      string(47) “CityListResponse CityList(CityList $parameters)”
      string(47) “NewOrderResponse NewOrder(NewOrder $parameters)”
      string(50) “HeartbeatResponse Heartbeat(Heartbeat $parameters)”

      I can get CityList results from my local machine using SOAPUI but not from the website.

      Note: the vendor is restricting access by IP and username and password.

      Hope you could help with issue.



    69. Hi Vas,

      Could it be that there’s no database connection on the remote host? The message ‘System.NullReferenceException: Object reference not set to an instance of an BIWS.BIWebService.LoginUser(SqlConnection myConn)’ seems to refer to that I think.
      As I cannot see the WSDL file you’re using: is it correct the method you’re calling expects a username and password as parameters?



    70. Hi Aashish,

      I might be missing something, but I can’t find the details you’re referring to. However, as the parameter is of type productinfo, which is not a standard object/type, I think you should check the WSDL file to see how you should construct the productinfo parameter. Probably it’s a complex type (e.g. consists of various simple or complex types like string/int or objects).



    71. Hi Patrick,

      I was able to implement your example and retrieve data with no problem. I’m trying to get High Low Tide Pred data from this website and can’t seem to modify the script properly to accept multiple parameters. Would it be possible for you to provide an example script and form to help me get started?

      Thx in advance.

    72. an phong

      hi admin!
      i have a problem relate for web service.
      this article very good about client in web service, but i have a problem about server in web service.
      admin has example about i need, please send me pass address email!
      thanks you so much!

    73. Vas

      Hey Patrick,

      Thanks for the reply.

      I don’t think is the DB connection issue, because the company which provides the webservice is saying that I’m hiting their server, but they don’t give more info then that.

      I tried to make a call with our username and password as parameters and get the same error.

      Here is the output of WSDL file:


      Thanks a lot for your help.


    74. Hello Patrick,
      Thanks for the great article. It surely works great but my requirement is little different. I am supposed to pull data from a seperate WSDL and it gives me error as below …

      Fatal error: Uncaught SoapFault exception: [Client] DTD are not supported by SOAP in F:\wamp\www\soap\client.php:5 Stack trace: #0 [internal function]: SoapClient->__call(‘getUpdate’, Array) #1 F:\wamp\www\soap\client.php(5): SoapClient->getUpdate(‘doggy’) #2 {main} thrown in F:\wamp\www\soap\client.php on line 5

      Tired of it … can you help on this?

    75. Hi Vas,

      So that company will only tell you that the request reaches their server. Hmm.. but they won’t tell you if you use the right credentials?
      Well.. the error message is a cryptic one, not really describing the actual error. I’m still not able to see the result you wanted to post. Is it possible to put it somewhere on a service like or pastebin and provide the link?



    76. Hi O. Nepal,,

      From what I read on various blogs it mostly has something to do with the server not responding with a proper SOAP message, but rather an HTML page (like a 403 or 404 error message or just a web page). Is the receiving end (the server sided part) handling the request properly and serving responses in SOAP format? (Did you code the server part?)



    77. Vas

      Hey Partric,

      Thanks a lot for getting back to me.
      Here is the link of the webservice

      but they restrict it by IP so I’m not sure that your will get anything.
      However, as you requested it fro here is the link.
      Hope you will be able to see the XML .
      Your help is greatly appreciated.



    78. Sitansu

      Nice example.Keep it up.

    79. Jan Møller

      Hello Patrick van Kouteren.

      This is the most useful, short and informative description i have found on the subject PHP, WSDL and SOAP!

      Thanx a lot.

      Jan Møller, Denmark

    80. Jitendra

      very nice example for who don’t aware about soap

    81. Dave Joyce

      Great example and easy to follow. Just a follow up to your action=’index.php’ comment. I had a customer server (NT) crash and had to re-install a custom php database program on W7 computer with latest XAMPP code and found that the action=$_SERVER[‘PHP_SELF’] also cause problems.

      I changed all form actions that call themselves to just action=”. Then html forces the correct action. Worked fine with your example too. Not sure if this works on all servers.

      Thanks again for the timeless tutorial.

      Dave Joyce, Canada

    82. soap newb

      This is such a great article, simple yet get the point across of what SOAP does, and how to use it with php. nice!

    83. Hannu-Pekka Heinäjärvi

      Thanks, really good article!

    84. Roshni

      Thanks for the good article

    85. Hello Patrick,

      I just wanna say you , thanks a lot for this tutorial.
      I was really helpful for me when i started to learn SOAP ..

      I have 1 question,
      how can we create WSDL like ?

      Great Work ..
      God bless you..

    86. thank you for your easiest example ever

    87. Hi Milap,

      You COULD of course create it by hand (hehe), but often there are tools which can create a WSDL file for you. As far as I know there wasn’t a native PHP thingy for it (yet). However, there must be some smart guy who’s done this already.

      (It basically comes down to indexing the methods and putting the docs / metadata you’ve defined in the SOAP API into a specific (read: WSDL) format)



    88. Hi Patrick,

      I just came across to your php example and i tried to get some knowledge of it but it seems that i’m having problems with arrays within arrays.

      My question is : How do i form my arrays in order to get the result correctly?

      usefull information:

      using soapui tests i get as request from service:


      and as result:


      at the moment i’ve done this in php :

      $HeaderInfo= array(‘AgentCode’ => $AgentCode,’AgentUser’ => $AgentUser,’AgentPasswd’ => $AgentPasswd,’AgentSignature’ => $AgentSignature);

      $PricingPerPassenger = array(‘ClassAbbr’=>’A1′,’PassType’=>’AD’);
      $PricingPerVehicle = array(‘VehicleType’=>’IX1′,’Meters’=>’425′);

      $PricingReq[]= new SoapVar($Data_,SOAP_ENC_OBJECT);
      $PricingReq[]= new SoapVar($PricingPerPassenger,SOAP_ENC_OBJECT,null,null,’PricingPerPassenger’);
      $PricingReq[]= new SoapVar($PricingPerVehicle,SOAP_ENC_OBJECT,null,null,’PricingPerVehicle’);

      $HeaderInfo = new SoapVar($HeaderInfo SOAP_ENC_OBJECT);
      $PricingReq= new SoapVar($PricingReq, SOAP_ENC_OBJECT);

      $client = new SoapClient(“http://something-wsdl”,array(‘trace’=>1,’exception’=>0));


      but i’m getting back from the service a response with no values

      myrequest with above php code:


      service response:

      any help will be much appeciated



    89. i removed some < in order to post results, sorry for this 🙂

      using soapui tests i get as request from service:


      and as result:


      myrequest with above php code:


      service response:

    90. david

      url does not open

    91. Great article for beginners with PHP SOAP. Just what I needed. Thx!

      Max Qubit

    92. hi great article…could you send me an email as i will need your help for a project.thanks

    93. Hi Yusuf,

      You can reach me trough here, or Twitter, if it’s short 🙂



    94. Aspirin

      Your example worked like a charm, BUT when using that with this link
      i got a “Extra content at the end of the document” Fatal Error.
      any suggestions or ideas how to connect?

    95. vinod palan

      Code looks great but I am getting this error can you please help.

      Warning: SoapClient::__construct(https://…../departments/ps/DPM/_vti_bin/Lists.asmx?WSDL) [function.SoapClient—construct]: failed to open stream: HTTP request failed! HTTP/1.1 401 Unauthorized in …/testsoap.php on line 33

    96. Hi Vinod,

      Is the WSDL file you’re trying to access at a secured area? Seems like it expects HTTP authentication. If you try to access the WSDL file through your browser, do you get a login prompt?



    97. Hi Aspirin,

      Hmmm.. that’s a nice one. Did you perform a search on the internet on that? And do you know at which line it goes wrong? This StackOverflow question is about the same problem. I don’t know if it’s a PHP bug or not.



    98. I have started to develop an API for one of my project which will be providing direct access payment services. It will be like a online payment system. For communications between merchant and my API i have selected to use SOAP and to be honest, it is my first time to work with SOAP 🙂 . This article provided me a basic start and intro to SOAP and now i am running the sample code and arranging it for my use.
      Thank you for a good post.

    99. Thank you for the tutorial , let me try. I need to create somethng where user can check user/pass and return correct xml.

    100. Thanks for your sharing! it’s great tutorial and i can do it! 🙂

    101. This is very simple and easily understandable example, great post.

    102. Sree

      Hi Patrick,

      Great example for the starters. But I am having issues. I just tried implementing your code. Please tell me what I should check.

      Notice: Undefined property: stdClass::$tTopGoalScorer

    103. Hi Patrick,

      As everyone is saying, thank you for a great example and getting me started on SOAP calls. I tired to get your updated soaptest.php file to work but I am stuck. In the soaptest.php file I changed the URL to

      $client = new SoapClient(“”);

      as the URL in the file was

      $client = new SoapClient(“”);

      which did not work. So, I can get the WSDL but when the PHP SoapClient makes the request

      $result = $client->TopGoalScorers(array(‘iTopN’=>$topn));

      I get this error

      Notice: Undefined property: stdClass::$tTopGoalScorer in D:\Apache\htdocs\SimplePHPSOAPExample\soaptest.php on line 21

      which leads to this error

      Warning: Invalid argument supplied for foreach() in D:\Apache\htdocs\SimplePHPSOAPExample\soaptest.php on line 32

      This leads me to believe that the call failed and no result object was returned. I looked at the WSDL and it is as you have your example (meaning that the operation name is still TopGoalScorers) so I’m at a loss as we why the call is failing. I did put and error_log() stmt in the code to check on the value of $topn and $_POST[‘topn’] and they look fine

      [Thu May 24 13:52:39 2012] [error] [client] KEN $topn => 3 $_POST[topn] => 3, referer: http://localhost/SimplePHPSOAPExample/soaptest.php

      The PHP error log reflects what I see in the browser

      [Thu May 24 13:52:42 2012] [error] [client] PHP Notice: Undefined property: stdClass::$tTopGoalScorer in D:\\Apache\\htdocs\\SimplePHPSOAPExample\\soaptest.php on line 21, referer: http://localhost/SimplePHPSOAPExample/soaptest.php
      [Thu May 24 13:52:42 2012] [error] [client] PHP Warning: Invalid argument supplied for foreach() in D:\\Apache\\htdocs\\SimplePHPSOAPExample\\soaptest.php on line 32, referer: http://localhost/SimplePHPSOAPExample/soaptest.php

      Hope you can help.


    104. frozeng

      Notice: Undefined property: stdClass::$tTopGoalScorer

      This seems to be caused by the the server returning no data currently for TopGoalScorer (possibly this is outside of a season or maybe its broken). gives a list of the methods and a form to test them. TopGoalScorer currently returns an empty array.

      The following method works:
      $result = $client->TopSelectedGoalScorers(array(‘iTopN’ => 1));
      $array = $result->TopSelectedGoalScorersResult->tTopSelectedGoalScorer->sName;
      var_dump( $array );

    105. Thanks forzeng, that makes sense. I tried your snippet, vardump($array) returns 1 name interestingly when I replace ‘iTopN’ => 1 with ‘iTopN’ => 10 and run it again, vardump($array) returns NULL. Do you think that’s just a bug with the web service?

      vardump() was a good debugging tool as well 🙂

    106. Thanks that was easy. Advanced Documentation you find on

    107. Rasmus

      Hey Patrick!

      Great guide, but I’m having trouble getting the results back from your example; I just get a blank page. I’m running PHP through MAMP (1.9) and SOAP _should_ be activated afaik. Any ideas on what might be the problem?

    108. Hello Rasmus,

      Is it about the actual retrieving of the results or do you already get a blank page when trying to access the form?
      Do you get any errors regarding SoapClient in your error_log?
      Can you read the WSDL file from the URL? (Does it give output in your browser?)
      If so, you can use some var_dump statements (as shown in earlier comments) to debug which step is not working.



    109. David

      Great job! I do have a question, could you explain how to connect using an API with password and username as well as getting a information out?

    110. Chester

      Hi Patrick!

      Great job. I have only one doubt, it would be perfect if you could help me…
      I have a webservice that require a parameter to be sent as xml.
      Do you know how to send it, using php?

      Thanks in advance,

    111. Bill Zimmerly

      Great article Patrick! You helped me with this. By the way, here’s another PHP goodie that I found VERY useful in my own SOAP experiments –> the var_dump() function! With it, it is easy to determine what the contents of ANY object being returned from the server is. It decomposes the objects very cleanly, and you can use it step-by-step to decode the arrays returned.

    112. Nadeem

      Great! Its help me a lot, to understand.

    113. Mohamed

      Good job thank u

    114. supachoup

      Thank you so much for your job, you litterally saved my life !!!!!!

    115. toorup

      I am a novice to web services and coming across is a blessing. I would be grateful if you can send me the source code. Thanks in advance

    116. Hi toorup,

      All code in the blogpost is basically all there is!



    117. toorup

      Never mind sending me the source code… I copied the code I could lay my hands on here and I was actually able to change the table format to print out in xml format… Here is the edited code below… Nice tutorials… Thanks man!


      if ($_POST[‘topn’] > 0 && (int) $_POST[‘topn’] TopGoalScorers(array(‘iTopN’ => $topn));
      // Note that $array contains the result of the traversed object structure
      $array = $result->TopGoalScorersResult->tTopGoalScorer;
      header(“Content-type: text/xml”);
      print ”

      foreach($array as $k=>$v){
      print ”

      ” . ($k+1) . ”
      ” . $v->sName . ”
      ” . $v->iGoals . ”
      print “”;
      else {


      <form id="topscorers" action="” method=”post”>
      How long should your topscorers list be? (Choose a digit between 1 and 20).

    118. Good blog about client in web service, and it is very simple and easily understandable example, great post.

    119. behnam

      Hey man, I was wondering if you could help me:

      This is my wsdl

      They request data from me with this format:

      They expect my response to be this format:

      I thought I use something like this but your code looks like the right way to go:
      $xml = simplexml_load_file(“receive.xml”);
      $xml->registerXPathNamespace(‘ot’, ‘’);
      $hotel_ref = $xml->xpath(“//ot:HotelRef”);
      $attributes = $hotel_ref[0]->attributes();
      $hotel_id = $attributes[‘HotelCode’];

      Can you please help me with this or show me how you do it?


    120. De gran ayuda tu artículo.

      Thank for article. I was helpful.


    121. really usefull post…Thanks

    122. Rocky

      Can you please send me example of the code.

    123. Iulian

      Good post, well explained.

    124. Hi Patrick,
      I have created a web services for one of my project using php soap. Currently i process all the returned data in arrays (associative arrays).
      I want to know is it possible to get the returned data in clean xml format without the soap headers?
      I also have a solution (not tested yet), that i can take the results at server side, and create an xml string, and that xml string is returned back to the client, so the client will have the result in an array and the value will be an xml structure. But not sure about this.
      Can you please give me a guide line here.
      May thanks for the good post and your help.

    125. Mahu

      This post is really old but it helped me in a way any other soap tutorial could do. Thanks a lot!

    126. Jashid


      After running this code i got an error.

      Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn’t load from ‘’ : failed to load external entity “” in /var/www/html/testphp/form_submission.php:5 Stack trace: #0 /var/www/html/testphp/form_submission.php(5): SoapClient->SoapClient(‘http://football…’) #1 {main} thrown in /var/www/html/testphp/form_submission.php on line 5

    127. Mohamed

      Hello how can I sort by Goal on display please help me.

    128. I cannot get this to work .. i’m hoping you can help once i hit the client call i get nothing after that i.e. (stops my script, blank page) …

    129. Dhaval


      Thanks for a great explanation with example.

      I’m beginner in using SOAP. I need to ask you one question, the WSDL file I’m using needs to pass header with user/pass but I don’t know how to do that as I’m a beginner. Can you tell me how to pass whole header through SoapClient example you provide.


    130. blackwolf

      Thanks for the great tut. it works and i did a change to get all the player names and country for testing.

      im currently working on a bit of code that has to use WSDL, “kenteken” submit and retrieve car information however i cant get the darn thing to work.

      if you have some time can you take a piek @ my code? and tell me what im doing wrong.


    131. For those who wants to use SOAP Web Services in PHP easily, I would recomand you to use this package which can be very usefull. Test it and tell me what you think about it 😉


    132. this help me to understand the basic of soap, thanks patrick

    133. Cenital

      First of all thank you for sharing your work Patrick.
      I have a short question hope you can help me because I´m a little bit lost on that.

      I nedd to get some data from SOAP server but it´s not offering no WSDL… but I have the data sctructure for the data that SOAP server is waiting for, I have the IP and the port address too where I should send the request.

      So questión is…. How can I do a SOAP request without having a WSDL?. Is it possible using PHP-SOAP?.

      Thank you so much in advance.
      Best regards.

    134. Cenital

      …one more thing related to the prior question. I have a raw data to send into the call method but I have no name for the parameter. What I mean is that I have no pair ‘param name’, ‘param value’ , what I have it´s just ‘param value’ .. This is because the SOAP server it´s just an integration engine wich receives the values and it´s acting like a gateway to other aplication so that It´s because I guess no ‘param name’ is needed.

      Thank´s (once again) 🙂

    135. monish

      First f all thnkx 4 the wndrful tut..

      But when i tried i am getting

      Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn’t load from ‘’ : failed to load external entity “” in /home/ Stack trace: #0 /home/ SoapClient->SoapClient(‘http://euro2008…’) #1 {main} thrown in /home/ on line 14

      how to i fix this issue?

      and when i tried ur WSDL link it gives me

      The connection to the server was reset while the page was loading.

      so is ur link to the WSDL is still active ?

      any way thnx again for ur tut…

    136. vish

      I passed this url to soapclient
      but i get soap parsing error,what could be the reason can you please help me?

      $client =
      new SoapClient(“”);


      i get error here.

    137. This gave me basic idea about the SOAP..Nice article thanks

    138. The best example online, thank you friend, you saved me
      from buenos aires

    139. Hardik

      It is very nice great work

    140. Hardik

      It is very nice that you give such nice article to public. It help me a lot

    141. Good article.Thanks

    142. soo cool this tutorial is……A single skimming through and I was able to solve a problem that has otherwise disturbed me for a whole week.Thankssss!!!!!!!

    143. Hello LOvely friend
      Everything here is looking fine, but is not working for me!!
      Here is my code

      0 && (int) $_POST[‘topn’] getForms(array(‘nomos’=>’Λάρισας’));
      // Note that $array contains the result of the traversed object structure
      $array = $result->getFormsReturn->item;

      print ”



      foreach($array as $k=>$v){
      print ”

      ” . ($k+1) . ”
      ” . $v->omada . ”
      ” . $v->omada_desc . ”

      print “”;
      else {


      Πόσες άδειες θέλεις? (>Επέλεξε από 1 εως 20).

      I have test the webservice with firefox soa client plugin and is working with the some elements!
      Can you help please and I will den an ouzo from Greece to you!

    144. 0 && (int) $_POST[‘topn’] getForms(array(‘nomos’=>’Λάρισας’));
      // Note that $array contains the result of the traversed object structure
      $array = $result->getFormsReturn->item;

      print ”



      foreach($array as $k=>$v){
      print ”

      ” . ($k+1) . ”
      ” . $v->omada . ”
      ” . $v->omada_desc . ”

      print “”;
      else {


      Πόσες άδειες θέλεις? (>Επέλεξε από 1 εως 20).

      Sorry!! here is the correct code!

    145. if ($_POST[‘topn’] > 0 && (int) $_POST[‘topn’] getForms(array(‘nomos’=>’Λάρισας’));
      // Note that $array contains the result of the traversed object structure
      $array = $result->getFormsReturn->item;

      print ”



      foreach($array as $k=>$v){
      print ”

      ” . ($k+1) . ”
      ” . $v->omada . ”
      ” . $v->omada_desc . ”

      print “”;
      else {


      Πόσες άδειες θέλεις? (>Επέλεξε από 1 εως 20).



      O.K. now I understand how to paste here php code

    146. I cannot understand how to paste my code…

    147. Dimitris, you can also paste your code at and link to it 🙂

    148. aksh

      hi patrick

      i cant connect to your remote wsdl file.i run your code in local wamp server but getting error like: Fatal error: SOAP-ERROR: Parsing WSDL: Couldn’t load from ‘’ : failed to load external entity “”

    149. Cobus

      Hi Patrick

      I have created a php soap client and server. They work perfectly well in non-wsdl mode. But when I use the wsdl file for my service the soap server ignores the header with the client’s authentication details. Thus making the client’s authentication fail. Any help would be appreciated.

    150. WB

      If you are looking for a good start to a PHP SOAP Client generated directly from the WSDL file, take a look at

      Includes some documentation with the generated classes.

      Hope it helps all of you somehow.

    151. Kuldeep Singh

      Nice short soap examples. Thankyou very much

    152. SD

      Hi Patrick,

      thanks for your nice article.
      im new in using apache2triad and enabled extention of php_soap.dll,php_xml.dll,soap.wsdl_cache_enabled=0,

      but i can not make it working.would u please suggest anything in this regard?


    153. Hi SD,

      Is there ANY form of output (either in the browser or the error_log) that can be of any help?



    154. SD

      Hi patrick,

      im new in using apache2triad and enabled extention of php_soap.dll,php_xml.dll,soap.wsdl_cache_enabled=0,

      Please help.

      here is my wsdl :

      Here is my soap-server.php :


      Here is my soap-client.php :

      simple SOAP test


      } catch (SoapFault $fault) {

      echo “Error :”.$fault->getMessage();


      echo $response;

    155. SD

      Dear Parick,

      thanks for your reply.
      I Did not found any error log in error logfile and even in the browsing showing nothing i.e. blank.

      i want to give u my files (wsdl,server.php & client.php) to check and help.

      where can i paste these ?

      Thanks once again for your kindly reply.

    156. SD

      Dear Patrick,
      please find out my files :

      appreciate your suggestion in this regard.


    157. Joseph Kurt Leonardo


      I would just like to know how it process the information after you called “->TopGoalScorers()” and what file it called to return the vlaues?

    158. Raja

      Patrick i am using calling WCF service with .svc extension for payment, it uses https address.when i tried to request the service i got following error “SoapFault Object
      [message:protected] => Failed to find the specified routing message element within the incoming message.
      [string:Exception:private] =>
      [code:protected] => 0
      [file:protected] => C:\wamp\www\multichoice\m_start.php
      [line:protected] => 16
      [trace:Exception:private] => Array
      [0] => Array
      [file] => C:\wamp\www\multichoice\m_start.php
      [line] => 16
      [function] => __call
      [class] => SoapClient
      [type] => ->
      [args] => Array
      [0] => SubmitPayment
      [1] => Array
      [paymentVendorCode] => RTTP_Ghana_PostOffice
      [transactionNumber] => 121305555
      [dataSource] => Angola_QA
      [smartCardNumber] => 4263998620
      [amount] => 1
      [currency] => USD
      [paymentDescription] => Test Payment
      [methodofPayment] => MOBILE
      [productCollection] => PRMW4




      [previous:Exception:private] =>
      [faultstring] => Failed to find the specified routing message element within the incoming message.
      [faultcode] => s:Client
      [detail] => stdClass Object
      [RoutingFailure] => stdClass Object
      [Message] => Failed to find the specified routing message element within the incoming message.


      please help to get this issue resolved, i have been trying for 2 days.

    159. Raja

      Data given is dummy data

    160. Louis

      This was a great jump start for a project I was working on.
      Thank you!

    161. Love this post , very helpful to work around SOAP request and Response with Error Tracking.


    162. Awesome guide. Really nice 🙂 Helped me quite a lot

    163. Thanks for the post.I am new and very easy to install for me.
      Thanks again
      sonu Sindhu

    164. gianluca

      thanks patrick

    165. Nazatul

      Hi Patrick,
      Help me..i’m stuck with this credential security in header..
      My xml is like this:


      already tried all the example found online, but failed. Really appreciate if u could help me.
      Thanks in advance 🙂

    166. Nazatul

      Hi Patrick,
      Help me..i’m stuck with this credential security in header..
      My xml is like this:

      <wsse:Security xmlns:wsse="; soapenv:mustUnderstand="1">
      <wsse:UsernameToken xmlns:wsu="; wsu:Id="UsernameToken-123">
      <wsse:Password Type="">123456</wsse:Password&gt;

      already tried all the example found online, but failed. Really appreciate if u could help me.
      Thanks in advance 🙂

    167. Hannu

      Edit 11/08/2010: Noticed that the WSDL was removed. Changed to WC 2010 WSDL file which seems to have the same format as the original WSDL.

      $client = new SoapClient(“”);

      So, what is the new wsdl adress exactly.

    168. vinod

      its great . . but can you please explain me. . with small doc that how arrays are filling with the values . ?

    169. Badr

      Thank you so mush 😉

    170. Hi Vinod,

      Which array do you mean? The resulting array?
      This is PHP turning a list of SOAP XML items into an array.
      Basically what you get back from PHP is a StdObject which you then can traverse. Named tags are transformed into properties. Lists are transformed into arrays.



    171. Ed


      I am trying to learn SOAP and came across you site. The link at displays an image and not XML contents. Do you happen to have a link to the old data?


    172. Thank you SO much for your help!!
      You’ve just saved me and my family xD

    173. eMale


      Excelent article! Thanks.

      i’m working with MS-Navision and I have a little challenge with parameters etc. I’m trying to get XML-Document as response, however I don’t know how to use parameters.

      If anybody can help.. Please!

      here is the part of the WSDL:



      And so far I’ve done this. (ps. Authentication is functioning ok)

      $codeunit = new NTLMSoapClient($codeunitURL);

      $params = array(‘productList’ => ”);;
      $result = $codeunit->GetWebProducts($params);
      $test = $result->productList;

      How ever I’m not sure if $params are okay, because this is not working! There fore the question is what should be in the $params because element type is “q1:root” not INT like in your case and result should include XML-document.


    174. eMale


      here is part of the WSDL again..

      operation name=”GetWebProducts”>

    175. eMale

      here is part of the WSDL again.. One more time…. in

    176. Alok

      Hello Friends,
      After Registering function in wsdl file i got two parameters

      1-in response i can easily pass parameters

      /*——-Room Cat Function Call———-*/
      echo ‘    Room Category Updated’;
      echo ‘    Room Category Added’;
      And i can access this under ->ForRequest as a partname

      2->ForResponse how can i add our parameters i am unable to add parameters
      basicaly i want to generate parameters from database

      3->When i register function my wsdl file not show any complextype parameters

    177. AYepez

      Excelent , thanks for share Patrick.

      regards from MX

    178. Bartosz


      Very nice and simple tutorial. It’s what I was looking for.

      Greets from Poland 🙂

    179. Have a wonderful day Patrick,

      I am wondering if you can help me, I am trying to use this WS in response I always got CONTENT IS NOT ALLOWED IN PROLOG I have checked every single line in my XML file (is the parameter for the “validacionComprobante” method). I need some advice over this issue. I really appreciate your help. From Quito Ecuador South America. My project is the SOAPclient program is /include/SRIcliente.php and the file that I am trying to send as a parameter is /archivos/vaya41136.xml the parameter must be sent in base64binary. Than you again.

    180. Hi Juan,

      I can’t look at it today, but tomorrow I might have some time to do that. In the meantime: I see that you’re base64 encoding the whole XML. Is that what should be done? Or should only a particular part be base64 encoded? Is the end result of your script a valid SOAP request?
      The response you get back basically tells you that there’s an invalid character in your request. As the request is encoded, perhaps it’s worth trying to print the resulting (encoded) SOAP call to check if there are no invalid characters in there.

      Hope this gives you some pointers. Cheers,


    181. TX

      Good job thank u!

    182. Charles

      Patrick, Thank you for this great tutorial and found it helpful since I’m being thrown into a project and in need of developing a SOAP request as quickly as possible.
      I understand how you populate your response with the sName and iGoals fields; but my issue is I’m trying to send 5 fields that are required and it generates 1 field in an XML string. I need to take that and convert it to URL links.

      So, how can I send 5 values in an envelop to generate the 1 response?
      I see you’re sending 1 from the form like this:
      $result = $client->TopGoalScorers(array(‘iTopN’ => 5));

      and based on another tutorial, I have tried this (without success):
      $result = $client->ListDocumentsInParentFolder(
      ‘asParentFolderPath’ => array(‘Employment Policies\Employment Policies PDF’=>’asParentFolderPath’,’type’=>’xsd:string’);
      ‘abUsePDF’ => array(‘True’=>’abUsePDF’, ‘type’=>’xsd:string’);
      ‘aiAuthenticationMode’ => array(‘2’=>’aiAuthenticationMode’, ‘type’=>’xsd:int’);
      ‘asRole’ => array(‘Administrator’=>’asRole’, ‘type’=>’xsd:string’);
      ‘asServiceKey’ => array(‘Key’=>’asServiceKey’, ‘type’=>’xsd:string’));

      any insight would be most helpful.

    183. Saroj

      Good one, simple and clear example
      Thanks a lot

    184. Almas


      I think it is good article, but now i cannot download wsdl file by pointed link tomake some experiments. When i click to wsdl-download-link i can see a little flag of Holland. Would you ammend this please

      With best regard,

    185. Hi Charles,

      Seeing the array that you try to send, you send the type per field as well, this is not necessary. This is just a type field from the WSDL to indicate what type the parameter should be.
      In the array that you send, the key should be the name of the parameter and the value should be the parameter value.

      You try to call the SOAP method ListDocumentsInParentFolder. From what I can see from your example, I’d say it should be as follows:

      $result = $client->ListDocumentsInParentFolder(
      ‘asParentFolderPath’ =>‘Employment Policies\Employment Policies PDF’,
      ‘abUsePDF’ => ‘True’,
      ‘aiAuthenticationMode’ => 2,
      ‘asRole’ => ‘Administrator’
      ‘asServiceKey’ => ‘Key’,



    186. Pablo

      Hi Patrick
      It has helped me much your post.
      I have agreed to another web service, and call a parameter as your example I get well.
      Could you please help me?
      When I make the call with several parameters not work for me.
      What could be the error?

      You command the example that works for me and who does not

      $paramdef = array(‘authenticationData’=>$parametros);
      $paramCode = array(‘conuntryCode’=>’ES’);

      $client = new SoapClient(‘http://xxxx/?wsdl’,array(‘encoding’=>’ISO-8859-1’));

      result = $client->getCountries($paramdef);
      $array = $result->country;

      foreach ( $array as $k=>$v){

      print ” Cod Country: ” . $v->code . “”;


      This works perfectly

      But by introducing a parameter more

      $resultt = $client->getProvinces($paramdef,$paramCode);
      $arrayt = $resultt->province;

      foreach ( $arrayt as $a=>$b){

      print ” Provincia: ” . $b->shortName . “”;

      I get this error

      Notice: Undefined property: stdClass::$province in C:\xxxx\pruebaws.php on line 43

      Warning: Invalid argument supplied for foreach() in C:\xxxx\pruebaws.php on line 45

      I agradeciria much your help and I’m locked

      thank you very much

    187. Pablo

      I send the code wsdl so you can view

    188. Pablo

      <xs:complexType name="getCountries"
      <xs:element minOccurs="0" name="authenticationData" type="ns1:authenticationData"
      <xs:complexType name="getCountriesResponse"
      <xs:element maxOccurs="unbounded" minOccurs="0" name="country" type="ns3:item"
      <xs:complexType name="getProvinces"
      <xs:element minOccurs="0" name="authenticationData" type="ns1:authenticationData"
      <xs:element minOccurs="0" name="countryCode" type="xs:string"
      <xs:complexType name="getProvincesResponse"

      <xs:element maxOccurs="unbounded" minOccurs="0" name="province" type="ns3:item"

      <xs:complexType name="item
      <xs:element minOccurs="0" name="description" type="xs:string"
      <xs:attribute name="shortName" type="xs:string"
      <xs:attribute name="longName" type="xs:string"
      <xs:attribute name="code" type="xs:string"

    189. Jasir

      I attached soap request and response below..using this how can i request and get response using php.Please help me

      POST /TrafficInsurance/TrafficInsuranceServicesNew.asmx HTTP/1.1
      Content-Type: text/xml; charset=utf-8
      Content-Length: length
      SOAPAction: “”



      HTTP/1.1 200 OK
      Content-Type: text/xml; charset=utf-8
      Content-Length: length



    190. Nops

      Great work. And anyone try to connect the wsdl link, should point to this:

    191. Daniel Blythe

      Hi, do you know if the ‘allow_url_fopen’ setting needs to be set to yes/on in the php.ini file for SOAP calls to work?

    192. mayank gogia

      I am using royal mail wsdl and i got

      Fatal error: Uncaught SoapFault exception: [Client] SOAP-ERROR: Encoding: object has no ‘integrationHeader’ property in D:\xampp\htdocs\integrate\index.php:89
      Stack trace:
      #0 D:\xampp\htdocs\integrate\index.php(89): SoapClient->__soapCall(‘request1DRanges’, Array)
      #1 {main}
      thrown in D:\xampp\htdocs\integrate\index.php on line 89

    193. Patrick, your page is the best I have seen at giving a clear useable example of soap and php together, and I was able to replicate your example to get my list of top scores. PERFECT. However, I need to send data using soap rather than request it. DO you have an example that demonstrates that? I have an xml template and the wsdl for the client server, but I don’t know how to post the data.
      I have the soap envelope, I have the username and password to access their server. Do you know how would I send a simple xml form of the kind

    194. Corey

      I just wanted to let you know I was having some troubles using SOAP for the first time and had several hours into before finding this info and it helped me figure it out…I wanted to make sure I said thank you.

    195. Correct thinks

    196. Nice short soap examples. Thankyou very much

    197. Hi guys,

      I need to extract data from this WSDL file

      I’ve already following code but can’t figure out, any help will be nice


      <form method="post" action="”>


      $array = $result->SearchByCompanyNumberResult->SearchByCompanyNumber;

      echo “table border=’2’>

      Country Code


      foreach ($array as $k=>$v){
      echo ”
      ” . ($k+1) . ”
      ” . $v->Number . ”
      ” . $v->CountryCode . ”
      echo “”;


    198. Hi Kelvin,

      What is the output you get from that? Any errors?
      And what is in the $result variable?



    199. Hi Patrick,

      This is the connectgraydon.php file I’m trying to build, I made a Search box to be able to submit a Company Name and get the result. In the future I want to be able to search for a Company Name but first I need to figure this out.

      I get following error message when I search for a Company Number, as “406952018” for instance.

      Fatal error: Uncaught SoapFault exception: [soap:Server] Server was unable to process request. —> Object reference not set to an instance of an object. in C:\xampp\htdocs\graydon\connectgraydon.php:26 Stack trace: #0 C:\xampp\htdocs\graydon\connectgraydon.php(26): SoapClient->__soapCall(‘SearchByCompany…’, Array, Array) #1 {main} thrown in C:\xampp\htdocs\graydon\connectgraydon.php on line 26

      Thx for your help.


    200. Hi Patrick and other,

      Maybe this can help to help me out this:



    201. well explained thanks

    202. Very great effort your are awesome

    203. Augustine John

      Thanks for this simple and very useful post

    Leave a Reply

    Powered by WordPress & Theme by Anders Norén