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:
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"> <documentation> Returns an array with the top N goal scorers and their current score. Pass 0 as TopN and you get them all. </documentation> <input message="tns:TopGoalScorersSoapRequest"/> <output message="tns:TopGoalScorersSoapResponse"/> </operation>
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" /> </message>
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:complexType>
<xs:sequence>
<xs:element name="iTopN" type="xs:int" />
</xs:sequence>
</xs:complexType>
</xs:element>
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("http://footballpool.dataaccess.eu/data/info.wso?wsdl");
$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.
Code:
<?php
if ($_POST['topn'] > 0 && (int) $_POST['topn'] <= 20){
$topn = (int) $_POST['topn'];
$client = new SoapClient("http://footballpool.dataaccess.eu/data/info.wso?wsdl");
$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'>
<tr>
<th>Rank</th>
<th>Name</th>
<th>Goals</th>
</tr>
";
foreach($array as $k=>$v){
print "
<tr>
<td align='right'>" . ($k+1) . "</td>
<td>" . $v->sName . "</td>
<td align='right'>" . $v->iGoals . "</td>
</tr>";
}
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" />
</form>
<?php
}
?>
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.

this is great work done but i want to work on it do send me example of the code that you use
Thanks this help me a lot…. you’re great
Patrick, thanks for this simple and clear example!
This code is great…. You’ve done a really good job
is this a drupal site?
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!
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…
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.
Excellent example! Helped me a lot
Thank you very much!
Finally I have found an example that is clear and understandable.
Best wishes
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
ADAM,
Perhaps it’s more useful to discuss such things here. This way more people can benefit from the knowledge..
Patrick
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
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
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?
Wilbo,
I’ve added the source file here.
On my machine it works with this script.. (php_soap should be enabled of course).
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.
Hi Tomas,
SoapClient is a php extension which can be enabled in the php (ini) config of the web server.
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.
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.
Any idea? Still stuck with the same issue from past 2 days. Any comment regarding this issue will be of greater help.
Finally got it to work.
$client = new SoapClient(“http://someaddress?WSDL”, array(‘proxy_host’ => “example.proxy.com”,’proxy_port’ => portnumber));
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!
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.
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?
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.
Simple and Awesome !!!! …. Thanks
Simple and to the point. SOAP demystified. Thanks.
excellent job… its awsome…
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
and … https://www.marionzoological.com/fedEx/track/soaptest.php
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
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!
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
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
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
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
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
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. (http://footballpool.dataaccess.eu/data/info.wso?op=Coaches)
It works, but I want to display their team info too.. can you help me ??
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
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 ???
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
great…that works… thanks patrick
Hey, I have a question. How do you connect actually to the database to get the results? Thanks.
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
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??
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..
SOAP CONCEPTS.
Hey great example, works out of the box. Thanks very much (edited the latter part, Patrick)
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.
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
Ihsanullah,
Is there any output? Have you checked the error_log for messages? This could help you solve the problem faster.
Cheers,
Patrick
Thanks, works great
great work
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
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
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]
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
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
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
Thanks, great article for beginners.
Why don’t you just use ?
Then the filename can be everything.
good work! very helpful, thanks alot
A great PHP SOAP example here http://plutov.by/post/web_service_soap
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?
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
hi
in my case the operation is getProductDetails, which takes parameter of type
productinfo as shown below!
how do handle this?
This is nice example with considerabl information, I was learning SOAP from W3Schools but this is more practical.
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\mywebsite.com\httpdocs\webservice\ws.php:68
Stack trace: #0 [internal function]: SoapClient->__call(‘CityList’, Array)
#1 C:\Inetpub\vhosts\mywebsite.com\httpdocs\webservice\ws.php(68): S
oapClient->CityList(Array) #2 {main} thrown in
C:\Inetpub\vhosts\mywebsite.com\httpdocs\webservice\ws.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
[...] 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 [...]
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
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
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.
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!
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
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?
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
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
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
Nice example.Keep it up.
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
very nice example for who don’t aware about soap
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
This is such a great article, simple yet get the point across of what SOAP does, and how to use it with php. nice!
Thanks, really good article!
Thanks for the good article
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..
thank you for your easiest example ever
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
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
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:
url does not open
Great article for beginners with PHP SOAP. Just what I needed. Thx!
Brgds,
Max Qubit
hi great article…could you send me an email as i will need your help for a project.thanks
Hi Yusuf,
You can reach me trough here, or Twitter, if it’s short
Cheers,
Patrick
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?
Nice part of code mate.
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
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.
Cheers,
Patrick
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.
Thank you for the tutorial , let me try. I need to create somethng where user can check user/pass and return correct xml.
Thanks for your sharing! it’s great tutorial and i can do it!