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:

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:

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

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:

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.

Code:

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.

Getagged , , , ,

210 reacties op “Simple PHP SOAP example

  1. asad schreef:

    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 schreef:

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

  3. Webchemie schreef:

    Patrick, thanks for this simple and clear example!

  4. Vanessa schreef:

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

  5. andrew schreef:

    is this a drupal site?

  6. Patrick schreef:

    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 schreef:

    Patrick,
    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. Patrick schreef:

    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 schreef:

    Excellent example! Helped me a lot

  10. Joseph schreef:

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

    Best wishes

  11. ADAM schreef:

    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
    ADAM

  12. GS schreef:

    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.

    Thanks
    GS

  13. Patrick schreef:

    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.

    Regards,

    Patrick

  14. Wilbo schreef:

    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?

  15. Tomas schreef:

    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:docsSOAPindex.php on line 14. Where I have to define class SoapClient.

    Thanks for your answer.

  16. Patrick schreef:

    Hi Tomas,

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

  17. Cybufex schreef:

    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.

  18. Ayaz Pasha schreef:

    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.

  19. Ayaz Pasha schreef:

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

  20. Ayaz Pasha schreef:

    Finally got it to work.

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

  21. Patrick schreef:

    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!

  22. Ayaz Pasha schreef:

    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.

  23. Patrick schreef:

    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?

  24. Ayaz Pasha schreef:

    Patrick,

    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.

  25. amolk schreef:

    🙂 nice sample code … thank you

  26. Deep C schreef:

    Simple and Awesome !!!! …. Thanks 🙂

  27. MockY schreef:

    Simple and to the point. SOAP demystified. Thanks.

  28. etangle schreef:

    excellent job… its awsome… 😉

  29. Jen schreef:

    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) …
    https://www.marionzoological.com/fedEx/track/index.php

    • Patrick schreef:

      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.

      Patrick

  30. Jen schreef:

    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…

    Thanks!

  31. Kiran schreef:

    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

    • Patrick schreef:

      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,

      Patrick

  32. qill schreef:

    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(“http://footballpool.dataaccess.eu/data/info.wso?wsdl”)

    but when I changed it to :
    require_once(‘nusoap-0.9.5/lib/nusoap.php’);
    $client = new nusoap_client(“http://footballpool.dataaccess.eu/data/info.wso?wsdl”);

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

    Sorry for the newbie question..
    thanks

  33. Patrick schreef:

    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);

    Cheers,

    Patrick

  34. qill schreef:

    the error is “Fatal error: Call to undefined method nusoap_client::TopGoalScorers() in C:xampphtdocsws_2fbtopscorer.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. (http://footballpool.dataaccess.eu/data/info.wso?op=Coaches)

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

    • Patrick schreef:

      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?

      Cheers,

      Patrick

  35. qill schreef:

    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 ???

    • Patrick schreef:

      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!
      Cheers,

      Patrick

  36. qill schreef:

    great…that works… thanks patrick

  37. nosebleed schreef:

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

  38. Patrick schreef:

    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.

    Cheers,

    Patrick

  39. ali schreef:

    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??

  40. Anthony schreef:

    Its nice job,
    Thanks,

    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..

  41. Chaitanya schreef:

    SOAP CONCEPTS.

  42. Pete schreef:

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

  43. AtReyU schreef:

    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.

  44. Ihsanullah khan schreef:

    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.

    Thanks,
    Regards,
    Ihsanullah

  45. Stephan schreef:

    Thanks, works great 🙂

  46. baljit schreef:

    great work

  47. Farooq schreef:

    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: http://ic2.infousa.com/InfoConnect2/2011.04.01/Description/BusinessProcess/WSDL/FlatBusinessProcessServiceType.wsdl

    Will be waiting for your response,

    Thank you.

    Farooq

  48. Patrick schreef:

    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!
    Cheers,

    Patrick

  49. Judhisthira schreef:

    Hi,

    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.

    Thanks,
    Judhisthira
    [removed e-mailaddress to reduce spam]

    • Patrick schreef:

      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.

      Cheers,

      Patrick

  50. Vishnu schreef:

    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.http://pastebin.com/W9uqssMm.
    This works perfectly.
    But for a web service i need to hit -an https link https://freeway.demo.lionbridge.com/vojo/FreewayAuth.asmx?wsdl 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

    • Patrick schreef:

      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.

      Cheers,

      Patrick

  51. Shahriar schreef:

    Thanks, great article for beginners.

  52. Casper schreef:

    Why don’t you just use ?

    Then the filename can be everything.

  53. M ZUBAIR schreef:

    good work! very helpful, thanks alot

  54. Mehul schreef:

    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?

  55. derjanni schreef:

    Nice article. I did a tutorial with NuSOAP in PHP in German as well … maybe someone’s interested in it: http://www.kammerath.net/php-und-soap.html

    Best regards,

    Jan

  56. Aashish schreef:

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

    how do handle this?

    • 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).

      Cheers,

      Patrick

  57. nitgreen schreef:

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

  58. Vas schreef:

    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:Inetpubvhostsmywebsite.comhttpdocswebservicews.php:68
    Stack trace: #0 [internal function]: SoapClient->__call(‘CityList’, Array)
    #1 C:Inetpubvhostsmywebsite.comhttpdocswebservicews.php(68): S
    oapClient->CityList(Array) #2 {main} thrown in
    C:Inetpubvhostsmywebsite.comhttpdocswebservicews.php on line 68

    Here is a list of function which I get from the server:
    array(16) {
    [0]=>
    string(53) “ShowBasicsResponse ShowBasics(ShowBasics $parameters)”
    [1]=>
    string(56) “ShowDetailsResponse ShowDetails(ShowDetails $parameters)”
    [2]=>
    string(59) “PerformancesResponse Performances(Performances $parameters)”
    [3]=>
    string(122) “PerformancesPOHPricesAvailabilityResponse PerformancesPOHPricesAvailability(PerformancesPOHPricesAvailability $parameters)”
    [4]=>
    string(59) “PremiumSeatsResponse PremiumSeats(PremiumSeats $parameters)”
    [5]=>
    string(47) “CityListResponse CityList(CityList $parameters)”
    [6]=>
    string(47) “NewOrderResponse NewOrder(NewOrder $parameters)”
    [7]=>
    string(50) “HeartbeatResponse Heartbeat(Heartbeat $parameters)”
    [8]=>
    string(53) “ShowBasicsResponse ShowBasics(ShowBasics $parameters)”
    [9]=>
    string(56) “ShowDetailsResponse ShowDetails(ShowDetails $parameters)”
    [10]=>
    string(59) “PerformancesResponse Performances(Performances $parameters)”
    [11]=>
    string(122) “PerformancesPOHPricesAvailabilityResponse PerformancesPOHPricesAvailability(PerformancesPOHPricesAvailability $parameters)”
    [12]=>
    string(59) “PremiumSeatsResponse PremiumSeats(PremiumSeats $parameters)”
    [13]=>
    string(47) “CityListResponse CityList(CityList $parameters)”
    [14]=>
    string(47) “NewOrderResponse NewOrder(NewOrder $parameters)”
    [15]=>
    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.

    Cheers,

    Vas

    • 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 object.at 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?

      Cheers,

      Patrick

  59. […] I have just Googled some tutorials: server and client. Cannot find any English tutorial for client and server. Just take care when googling, that the […]

  60. Pete schreef:

    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 http://opendap.co-ops.nos.noaa.gov/axis/ 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.

  61. an phong schreef:

    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!

  62. Vas schreef:

    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.

    Cheers,
    Vas

    • 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 pastie.org or pastebin and provide the link?

      Cheers,

      Patrick

  63. Outsouce Nepal schreef:

    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:wampwwwsoapclient.php:5 Stack trace: #0 [internal function]: SoapClient->__call(‘getUpdate’, Array) #1 F:wampwwwsoapclient.php(5): SoapClient->getUpdate(‘doggy’) #2 {main} thrown in F:wampwwwsoapclient.php on line 5

    Tired of it … can you help on this?

    • 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?)

      Cheers,

      Patrick

  64. Vas schreef:

    Hey Partric,

    Thanks a lot for getting back to me.
    Here is the link of the webservice http://qawebservices.broadwayinbound.com/BIWebService.asmx?wsdl

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

    Cheers,

    Vas

  65. Sitansu schreef:

    Nice example.Keep it up.

  66. Jan Møller schreef:

    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

  67. Jitendra schreef:

    very nice example for who don’t aware about soap

  68. Dave Joyce schreef:

    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

  69. soap newb schreef:

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

  70. Hannu-Pekka Heinäjärvi schreef:

    Thanks, really good article!

  71. Roshni schreef:

    Thanks for the good article

  72. Milap schreef:

    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 http://footballpool.dataaccess.eu/data/info.wso?wsdl ?

    Great Work ..
    God bless you..

  73. deepak bajpai schreef:

    thank you for your easiest example ever

  74. 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)

    Cheers,

    Patrick

  75. Dimitris schreef:

    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:

    UNF

    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[]=array();
    $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));

    $client->function($HeaderInfo,$PricingReq);

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

    myrequest with above php code:

    xxxxxxxxxxxxxxxxxxx201211010800TSTTTTT00002A1ADPV3

    service response:

    any help will be much appeciated

    thanks

    Dimitris

  76. Dimitris schreef:

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

    using soapui tests i get as request from service:

    ?
    ?
    ?
    ?

    and as result:

    UNF

    myrequest with above php code:

    xxxxxxxxxxxxxxxxxxx201211010800TSTTTTT00002A1ADPV3
    –>

    service response:

  77. david schreef:

    url does not open

  78. Max Qubit schreef:

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

    Brgds,
    Max Qubit

  79. Yusuf schreef:

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

  80. Aspirin schreef:

    Hi!
    Your example worked like a charm, BUT when using that with this link
    https://secure.incab.se/axis2/services/DTServerModuleService_v1?wsdl
    i got a “Extra content at the end of the document” Fatal Error.
    any suggestions or ideas how to connect?

  81. vinod palan schreef:

    Hi,
    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

    • 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?

      Cheers,

      Patrick

  82. Altaf Hussain schreef:

    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.

  83. tuba schreef:

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

  84. kittypunkz schreef:

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

  85. Daily1Game schreef:

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

  86. Sree schreef:

    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

  87. kchang808 schreef:

    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(“http://footballpool.dataaccess.eu/data/info.wso?wsdl”);

    as the URL in the file was

    $client = new SoapClient(“http://euro2008.dataaccess.eu/footballpoolwebservice.wso?WSDL”);

    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:ApachehtdocsSimplePHPSOAPExamplesoaptest.php on line 21

    which leads to this error

    Warning: Invalid argument supplied for foreach() in D:ApachehtdocsSimplePHPSOAPExamplesoaptest.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 127.0.0.1] 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 127.0.0.1] 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 127.0.0.1] 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.

    Regards…Ken

  88. frozeng schreef:

    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).

    http://footballpool.dataaccess.eu/data/info.wso 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 );

  89. kchang808 schreef:

    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 🙂

  90. IT-Consulting schreef:

    Thanks that was easy. Advanced Documentation you find on php.net:
    http://php.net/manual/de/class.soapclient.php

  91. Rasmus schreef:

    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?

  92. 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.

    Cheers,

    Patrick

  93. David schreef:

    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?

  94. Chester schreef:

    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,
    Chester

  95. Bill Zimmerly schreef:

    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.

  96. Nadeem schreef:

    Great! Its help me a lot, to understand.

  97. Mohamed schreef:

    Good job thank u

  98. supachoup schreef:

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

  99. toorup schreef:

    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

  100. Hi toorup,

    All code in the blogpost is basically all there is!

    Cheers,

    Patrick

  101. toorup schreef:

    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!

    TopGoalScorers(array(‘iTopN’=>5));

    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).

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

  103. behnam schreef:

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

    This is my wsdl
    https://smtpi.siteminder.com/siteconnect/services/siteconnect.wsdl

    They request data from me with this format:
    http://hotels2go.com.au/sm/receive.xml

    They expect my response to be this format:
    http://hotels2go.com.au/sm/OTA_HotelAvailRS.php

    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’, ‘http://www.opentravel.org/OTA/2003/05’);
    $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?

    Thanks

  104. Guillermo schreef:

    De gran ayuda tu artículo.

    Thank for article. I was helpful.

    Guillermo

  105. laeeq schreef:

    really usefull post…Thanks

  106. Rocky schreef:

    Can you please send me example of the code.

  107. Iulian schreef:

    Good post, well explained.

  108. Altaf Hussain schreef:

    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.

  109. Mahu schreef:

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

  110. Jashid schreef:

    Patrick,

    After running this code i got an error.

    Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn’t load from ‘http://footballpool.dataaccess.eu/data/info.wso?wsdl’ : failed to load external entity “http://footballpool.dataaccess.eu/data/info.wso?wsdl” 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

  111. Mohamed schreef:

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

  112. click here schreef:

    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) …

  113. Dhaval schreef:

    Hi,

    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.

    Thanks,
    Dhaval

  114. blackwolf schreef:

    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.

    thanks,

  115. Mikaelcom schreef:

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

    Regards

  116. pututik schreef:

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

  117. Cenital schreef:

    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.

  118. Cenital schreef:

    …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) 🙂

  119. monish schreef:

    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 ‘http://euro2008.dataaccess.eu/footballpoolwebservice.wso?WSDL’ : failed to load external entity “http://euro2008.dataaccess.eu/footballpoolwebservice.wso?WSDL” in /home/monish.george/project/soaptest.php:14 Stack trace: #0 /home/monish.george/project/soaptest.php(14): SoapClient->SoapClient(‘http://euro2008…’) #1 {main} thrown in /home/monish.george/project/soaptest.php 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…

  120. vish schreef:

    Hello,
    I passed this url to soapclient
    https://webservices-staging.toptable.com/Venue1.1/VenueService.svc?WSDL
    but i get soap parsing error,what could be the reason can you please help me?

    $client =
    new SoapClient(“https://webservices-staging.toptable.com/Venue1.1/VenueService.svc?WSDL”);

    print_r($client);

    i get error here.

  121. Devendra schreef:

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

  122. Daniel schreef:

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

  123. Hardik schreef:

    It is very nice great work

  124. Hardik schreef:

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

  125. WarGot schreef:

    Good article.Thanks

  126. charles schreef:

    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!!!!!!!

  127. Dimitris schreef:

    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 ”

    omada
    X
    Y

    “;

    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!

  128. Dimitris schreef:

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

    print ”

    omada
    X
    Y

    “;

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

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

    print “”;
    }
    else {

    ?>

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

    Sorry!! here is the correct code!

  129. Dimitris schreef:

    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 ”

    omada
    X
    Y

    “;

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

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

    print “”;
    }
    else {

    ?>

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

    <?php

    }

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

  130. Dimitris schreef:

    I cannot understand how to paste my code…

  131. Dimitris, you can also paste your code at http://pastebin.com and link to it 🙂

  132. aksh schreef:

    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 ‘http://euro2008.dataaccess.eu/footballpoolwebservice.wso?WSDL’ : failed to load external entity “http://euro2008.dataaccess.eu/footballpoolwebservice.wso?WSDL”

  133. Cobus schreef:

    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.

  134. WB schreef:

    If you are looking for a good start to a PHP SOAP Client generated directly from the WSDL file, take a look at http://www.apigenerator.com

    Includes some documentation with the generated classes.

    Hope it helps all of you somehow.

  135. Kuldeep Singh schreef:

    Nice short soap examples. Thankyou very much

  136. SD schreef:

    Hi Patrick,

    thanks for your nice article.
    im new in webservice.im 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?

    regards,
    SD

  137. SD schreef:

    Hi patrick,

    im new in webservice.im 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 :

    addfunction(“getCatalogEntry”);
    $server->handle();
    ?>

    Here is my soap-client.php :

    simple SOAP test

    getCatalogEntry($catalogId);

    } catch (SoapFault $fault) {

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

    }

    echo $response;
    var_dump(var_dump);
    ?>

  138. SD schreef:

    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.

  139. SD schreef:

    Dear Patrick,
    please find out my files :
    http://pastebin.com/fVbvw6hj

    appreciate your suggestion in this regard.

    regards,
    SD

  140. Joseph Kurt Leonardo schreef:

    Hi,

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

  141. Raja schreef:

    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:wampwwwmultichoicem_start.php
    [line:protected] => 16
    [trace:Exception:private] => Array
    (
    [0] => Array
    (
    [file] => C:wampwwwmultichoicem_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.

  142. Raja schreef:

    Data given is dummy data

  143. Louis schreef:

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

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

    Thanks

  145. alex schreef:

    Awesome guide. Really nice 🙂 Helped me quite a lot

  146. Sonu Sindhu schreef:

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

  147. gianluca schreef:

    thanks patrick

  148. Nazatul schreef:

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

    qwerty
    123456

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

  149. Nazatul schreef:

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

    <soapenv:Header>
    <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd&quot; soapenv:mustUnderstand="1">
    <wsse:UsernameToken xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd&quot; wsu:Id="UsernameToken-123">
    <wsse:Username>qwerty</wsse:Username>
    <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">123456</wsse:Password&gt;
    </wsse:UsernameToken>
    </wsse:Security>
    </soapenv:Header>

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

  150. Hannu schreef:

    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(“http://footballpool.dataaccess.eu/data/info.wso?wsdl”);

    So, what is the new wsdl adress exactly.
    Thanks!

  151. vinod schreef:

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

    • 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.

      Cheers,

      Patrick

  152. Badr schreef:

    Thank you so mush 😉

  153. Ed schreef:

    Patrick,

    I am trying to learn SOAP and came across you site. The link at http://footballpool.dataaccess.eu/data/info.wso?wsdl displays an image and not XML contents. Do you happen to have a link to the old data?

    Ed

  154. Marie Pizzer schreef:

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

  155. eMale schreef:

    Hi,

    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.

    Regards
    eMale

  156. eMale schreef:

    oopss.

    here is part of the WSDL again..

    operation name=”GetWebProducts”>

  157. eMale schreef:

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

    http://pastie.org/9346406

  158. Alok schreef:

    Hello Friends,
    After Registering function in wsdl file i got two parameters
    1-ForRequest
    2-ForResponse

    1-in response i can easily pass parameters

    /*——-Room Cat Function Call———-*/
    $getRoomCatObj=$client->call(“getRoomCat”,array(“Type”=>”TT”));
    if($getRoomCatObj==’updated’)
    {
    echo ‘    Room Category Updated’;
    }
    if($getRoomCatObj==’inserted’)
    {
    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

  159. AYepez schreef:

    Excelent , thanks for share Patrick.

    regards from MX

  160. Bartosz schreef:

    Hi,

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

    Greets from Poland 🙂

  161. Juan Carrillo schreef:

    Have a wonderful day Patrick,

    I am wondering if you can help me, I am trying to use this WS https://celcer.sri.gob.ec/comprobantes-electronicos-ws/RecepcionComprobantes?wsdl 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 https://github.com/jrcscarrillo/salgraf 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.

    • 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,

      Patrick

  162. TX schreef:

    Good job thank u!

  163. Charles schreef:

    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(
    array(
    ‘asParentFolderPath’ => array(‘Employment PoliciesEmployment 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.

    • 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(
      array(
      ‘asParentFolderPath’ =>‘Employment PoliciesEmployment Policies PDF’,
      ‘abUsePDF’ => ‘True’,
      ‘aiAuthenticationMode’ => 2,
      ‘asRole’ => ‘Administrator’
      ‘asServiceKey’ => ‘Key’,
      )
      );

      Cheers,

      Patrick

  164. Saroj schreef:

    Good one, simple and clear example
    Thanks a lot

  165. Almas schreef:

    Hello!

    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,
    Almas

  166. Pablo schreef:

    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

    $parametros=array(
    ‘user’=>’xxx’,’password’=>’xxx’,’locale’=>’xxx’,’domain’=>’xxx’);
    $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:xxxxpruebaws.php on line 43

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

    I agradeciria much your help and I’m locked

    thank you very much

  167. Pablo schreef:

    I send the code wsdl so you can view

  168. Pablo schreef:

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

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

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

  169. Jasir schreef:

    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
    Host: es.adpolice.gov.ae
    Content-Type: text/xml; charset=utf-8
    Content-Length: length
    SOAPAction: “http://adpolice.gov.ae/TrafficInsurance/TrafficInsuranceServices.asmx/VerifyInsuranceCompany”

    string
    string

    long

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

    int
    string
    string

    boolean

  170. Nops schreef:

    Great work. And anyone try to connect the wsdl link, should point to this: http://footballpool.dataaccess.eu/data/info.wso?WSDL

  171. Daniel Blythe schreef:

    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?

  172. mayank gogia schreef:

    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:xampphtdocsintegrateindex.php:89
    Stack trace:
    #0 D:xampphtdocsintegrateindex.php(89): SoapClient->__soapCall(‘request1DRanges’, Array)
    #1 {main}
    thrown in D:xampphtdocsintegrateindex.php on line 89

  173. Graeme Coulam schreef:

    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

  174. Corey schreef:

    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.

  175. Mohammed schreef:

    Nice short soap examples. Thankyou very much

  176. kelvin schreef:

    Hi guys,

    I need to extract data from this WSDL file
    WSDL: http://www.graydon.be/schemas/portal/1.0/wsdl/portal.wsdl

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

    GRAYDON

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

    SearchByCompanyNumber(array(‘Number’=>$ciaNumber));

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

    echo “table border=’2’>

    Number
    Country Code

    “;

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

    ?>

  177. kelvin schreef:

    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.

    https://drive.google.com/file/d/0B-pCOHYZNf6CMVNzLTU3VjgxUVU/view?usp=sharing

    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:xampphtdocsgraydonconnectgraydon.php:26 Stack trace: #0 C:xampphtdocsgraydonconnectgraydon.php(26): SoapClient->__soapCall(‘SearchByCompany…’, Array, Array) #1 {main} thrown in C:xampphtdocsgraydonconnectgraydon.php on line 26

    Thx for your help.

    Kelvin,

  178. kelvin schreef:

    Hi Patrick and other,

    Maybe this can help to help me out this:
    https://www.sitepoint.com/community/t/soap-wsdl-response-error-issue/211894

    Thx,

    Kelvin

  179. karamath schreef:

    well explained thanks

  180. karamath schreef:

    Very great effort your are awesome

  181. Augustine John schreef:

    Thanks for this simple and very useful post

  182. Michael Althoff schreef:

    Hi, I tried to use your example here but i have a problem to parse the resonse, but I can’t get it work.
    The Soap response look like:

    stdClann Object
    {
    [return] => Array
    (
    [0] => value1=”1″,vlaue2=”2″,value3=”3″,….
    [1] => value1=”4″,value2=”5″,value3=”6″,……
    )
    )
    Can you show me how I can parse this response to view it in a htmp table.
    Many thx
    regards
    Mike

Geef een reactie

Het e-mailadres wordt niet gepubliceerd. Vereiste velden zijn gemarkeerd met *