PHP-SOAP web service with out a WSDL
This article is going to describe how to create a simple web service with php-soap step by step.
Requirements
Server to run php (apache, xampp , wamp)
PHP-SOAP extension
Steps
Let's write a simple web service to find the length of a given string.
So here is the code for StringLengthServer.php
<?php
Run this StringLengthClient.php to receive the service.
So the output will be:
Requirements
Server to run php (apache, xampp , wamp)
PHP-SOAP extension
Steps
Let's write a simple web service to find the length of a given string.
So here is the code for StringLengthServer.php
<?php
# StringLengthServer.php
# Copyright (c) 2011 by Lakmali Baminiwatta
#
function findLength($string) {
return "Length of the string " . $string . "is : ".strlen($string);
}
$server = new SoapServer(null,
array('uri' => "urn://www.lakmali.lk"));
$server->addFunction("findLength");
$server->handle();
# Copyright (c) 2011 by Lakmali Baminiwatta
#
function findLength($string) {
return "Length of the string " . $string . "is : ".strlen($string);
}
$server = new SoapServer(null,
array('uri' => "urn://www.lakmali.lk"));
$server->addFunction("findLength");
$server->handle();
?>
- First thing done here is to write a function to perform the action done by the service. So here function findLength($string) takes a string as the argument and prints back the length of it.
- Then SoapServer is created. First argument null which means no WSDL used. Second argument is uri value is just a unique string as the namespace.
- Then we have to add the function findLength to the server.
- Now copy the file StringLengthServer.php to the server to run. Here it is assumed the url which service run is http://localhost/simple_server/StringLengthServer.php.
- Now let's write a simple client program to get the service from the webservice.
So here is the code for StringLengthClient.php
<?php
StringLengthClient.php
# Copyright (c) 2011 by Lakmali Baminiwatta
#
$client = new SoapClient(null, array(
'location' => "http://localhost/simple_server/StringLengthServer.php",
'uri' => "urn:urn://www.lakmali.lk",
'trace' => 1 ));
$return = $client->__soapCall("findLength",array("lakmali"));
echo("\nReturning value of __soapCall() call: ".$return);
echo("\nDumping request headers:\n"
.$client->__getLastRequestHeaders());
echo("\nDumping request:\n".$client->__getLastRequest());
echo("\nDumping response headers:\n"
.$client->__getLastResponseHeaders());
echo("\nDumping response:\n".$client->__getLastResponse());
?># Copyright (c) 2011 by Lakmali Baminiwatta
#
$client = new SoapClient(null, array(
'location' => "http://localhost/simple_server/StringLengthServer.php",
'uri' => "urn:urn://www.lakmali.lk",
'trace' => 1 ));
$return = $client->__soapCall("findLength",array("lakmali"));
echo("\nReturning value of __soapCall() call: ".$return);
echo("\nDumping request headers:\n"
.$client->__getLastRequestHeaders());
echo("\nDumping request:\n".$client->__getLastRequest());
echo("\nDumping response headers:\n"
.$client->__getLastResponseHeaders());
echo("\nDumping response:\n".$client->__getLastResponse());
In here the location argument of the SoapClient must be the URL to server program which we wrote above and added to run. Make sure it is correct.
Run this StringLengthClient.php to receive the service.
So the output will be:
Returning value of __soapCall() call: Length of the string lakmali is : 7 Dumping request headers: POST /simple_server/StringLengthServer.php HTTP/1.1 Host: localhost Connection: Keep-Alive User-Agent: PHP-SOAP/5.2.9 Content-Type: text/xml; charset=utf-8 SOAPAction: "urn:urn://www.lakmali.lk#findLength" Content-Length: 510 Dumping request: <soap-env:envelope soap-env:encodingstyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="urn:urn://www.lakmali.lk" xmlns:soap-enc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <soap-env:body><ns1:findLength> <param0 xsi:type="xsd:string">lakmali</param0> </ns1:findLength></soap-env:body></soap-env:envelope> Dumping response headers: HTTP/1.1 200 OK Date: Tue, 07 Jun 2011 13:24:06 GMT Server: Apache/2.2.10 (Fedora) X-Powered-By: PHP/5.2.9 Content-Length: 550 Connection: close Content-Type: text/xml; charset=utf-8 Dumping response: <soap-env:envelope soap-env:encodingstyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="urn://www.lakmali.lk" xmlns:soap-enc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <soap-env:body><ns1:findLengthResponse> <return xsi:type="xsd:string">Length of the string lakmali is : 7</return> </ns1:findLengthResponse></soap-env:body></soap-env:envelope>Here the client program is written to display SOAP messages exchanged. But for a real client ony you need is return value from soapCall.
<?php
# StringLengthClient.php
# Copyright (c) 2011 by Lakmali Baminiwatta
#
$client = new SoapClient(null, array(
'location' => "http://localhost/simple_server/StringLengthServer.php",
'uri' => "urn:urn://www.lakmali.lk",
'trace' => 1 ));
$return = $client->__soapCall("findLength",array("lakmali"));
echo("\nResult: ".$return);
# Copyright (c) 2011 by Lakmali Baminiwatta
#
$client = new SoapClient(null, array(
'location' => "http://localhost/simple_server/StringLengthServer.php",
'uri' => "urn:urn://www.lakmali.lk",
'trace' => 1 ));
$return = $client->__soapCall("findLength",array("lakmali"));
echo("\nResult: ".$return);
?>
Awesome post Lakmali! This really helped me in debug mode. Also rare to find any documentation with no WSDL
ReplyDeleteThanks Matt!
ReplyDeleteHi lakmali
ReplyDeleteDont u hv PHP-SOAP web service with a WSDL example because we try to access wsdl web service in DSS using PHP.
Check this link, you'll find what you need.
Deletehttp://wso2.com/library/1060
Thank you sharing this kind of noteworthy information. Nice Post.
ReplyDeleteopencu
Education
This comment has been removed by a blog administrator.
ReplyDeleteThis comment has been removed by a blog administrator.
ReplyDeleteThis comment has been removed by a blog administrator.
ReplyDelete
ReplyDeleteThis content of information has
helped me a lot. It is very well explained and easy to understand.
seo training classes
seo training course
seo training institute in chennai
seo training institutes
seo courses in chennai
seo institutes in chennai
seo classes in chennai
seo training center in chennai
ReplyDeleteYou write this post very carefully I think, which is easily understandable to me. Not only this, but another post is also good. As a newbie, this info is really helpful for me. Thanks to you.
Tally ERP 9 Training
tally classes
Tally Training institute in Chennai
Tally course in Chennai
Thanks for sharing this valuable information to our vision. You have posted a worthy blog keep sharing.
ReplyDeleteDigital Marketing Course In Kolkata
Web Design Course In Kolkata
SEO Course In Kolkata
Nice post, I like to read this blog. It is very interesting to read.
ReplyDeletefibonacci in python
python class inheritance
adana escort - adıyaman escort - afyon escort - aksaray escort - antalya escort - aydın escort - balıkesir escort - batman escort - bitlis escort - burdur escort - bursa escort - diyarbakır escort - edirne escort - erzurum escort - eskişehir escort - eskişehir escort - eskişehir escort - eskişehir escort - gaziantep escort - gebze escort - giresun escort - hatay escort - ısparta escort - karabük escort - kastamonu escort - kayseri escort - kilis escort - kocaeli escort - konya escort - kütahya escort - malatya escort - manisa escort - maraş escort - mardin escort - mersin escort - muğla escort - niğde escort - ordu escort - osmaniye escort - sakarya escort - samsun escort - siirt escort - sincan escort - tekirdağ escort - tokat escort - uşak escort - van escort - yalova escort - yozgat escort - urfa escort - zonguldak escort
ReplyDeletetakipçi satın al
ReplyDeletetakipçi satın al
takipçi satın al
takipçi satın al
takipçi satın al
takipçi satın al
takipçi satın al
takipçi satın al
takipçi satın al
takipçi satın al
takipçi satın al
takipçi satın al
takipçi satın al
takipçi satın al
takipçi satın al
takipçi satın al
takipçi satın al
takipçi satın al
takipçi satın al
takipçi satın al
takipçi satın al
instagram takipçi satın al
instagram takipçi satın al
takipçi satın al
takipçi satın al
instagram takipçi satın al
instagram takipçi satın al
instagram takipçi satın al
instagram takipçi satın al
takipçi satın al
instagram takipçi satın al
takipçi satın al
ReplyDeleteinstagram takipçi satın al
https://www.takipcikenti.com
As I apply more and more of these insights to my daily life I can see how your education has transformed you into a top expert in this industry. I talked about these very points to my professor today and she couldn’t argue any of these points. After seeing this I know I will not be the same. Be cool if you were close to me so we could hang. I don’t know why but this site takes almost a minute to fully load on my friends laptop. Reading your content is way better than snuggles.
ReplyDeleteAlso visit my homepage ☛ 야설
Don’t be afraid to spread your thoughts 오피헌터 . You have just made my year a great one! You are clearly an influence in this field so I'm sure many of these concepts probably come easily to someone like yourself however, I am still not understanding some things you’ve written here. What a highly descriptive and well written post. Any more feedback? It would be greatly appreciated.
ReplyDeleteGood web site! I really love how it is simple on my eyes and the data are well written. I am wondering how I might be notified when a new post has been made. I have subscribed to your RSS feed which must do the trick! Have a nice day!
ReplyDeletePlease Visit My homepage ➤ 마사지블루
Do you have a spam problem on this blog; I also am a blogger, and I was wanting to know your situation; many of us have created some nice practices and we are looking to exchange solutions with other folks, be sure to shoot me an e-mail if interested. 건마탑
ReplyDeletethanks admin great article HDE Bilişim
ReplyDeleteAlışveriş
Compo Expert
Multitek
Seokoloji
Vezir Sosyal Medya
Adak
Maltepe Adak
Thank you for providing a good quality article.
ReplyDelete바카라사이트
It is very well written, and your points are well-expressed. I request you warmly, please, don’t ever stop writing.
ReplyDelete카지노사이트
I really enjoy your web’s topic. Very creative and friendly for users. Definitely bookmark this and follow it everyday.
ReplyDelete온라인카지노
It is really a great and helpful piece of information. I am glad that you shared this useful info with us. Please keep us informed like this.
ReplyDelete룰렛
Уour blog providеd us useful information to work on. Үou have done a marvelous job! 바카라사이트
ReplyDeleteYou were great and everyone received so much from your experience and knowledge. Absolutely amazing 스포츠토토
ReplyDeleteThis is perfect blog for anyone who is looking for topics like this. It has got it all, information, benefits and overview. A perfect piece of writing. Good job.
ReplyDeleteMiracle II Soap Hygiene Products
This is one of the best website I have seen in a long time thank you so much, thank you for let me share this website to all my friends. 블랙잭사이트
ReplyDeleteSuch a great blog.Thanks for sharing......... 경마
ReplyDeleteGreat site. A lot of helpful info here. 스포츠토토
ReplyDeleteI have been looking for articles on these topics for a long time. 카지노사이트 I don't know how grateful you are for posting on this topic. Thank you for the numerous articles on this site, I will subscribe to those links in my bookmarks and visit them often. Have a nice day
ReplyDeleteHurrah! Finally I got a website from where I be capable of truly take helpful facts regarding my study and knowledge. 바카라사이트
ReplyDeleteWe stumbled over here from a different web address and thought I should check things out. 온라인바둑이
ReplyDeleteYour post is very interesting to me. Reading was so much fun. I think the reason reading is fun is because it is a post related to that I am interested in. Articles related to 온카지노 you are the best. I would like you to write a similar post about !
ReplyDelete
ReplyDeleteSuch a great blog.Thanks for sharing.........
php training in hyderabad
PHP Training in Gurgaon
Great Post!!! thanks for sharing this information with us.
ReplyDeletewhat is net framework
what is net framework used for
Excellent read, Positive site, I have read a few of the articles on your website now, and I really like your style.
ReplyDeleteecommerce catalogue management services
ecommerce services provider in india
Hi there, I simply hopped over in your website by way of StumbleUpon. Now not one thing I’d typically learn, but I favored your emotions none the less. Thank you for making something worth reading. 먹튀검증업체
ReplyDeleteSMM PANEL
ReplyDeleteSmm Panel
https://isilanlariblog.com/
İnstagram takipçi satın al
Hirdavatci Burada
Beyazesyateknikservisi.com.tr
servis
Tiktok para hilesi
Nice Post!!! gratitude for imparting this post to us.
ReplyDeleteAndroid Course in Chennai
Android Online Course
Android Course in Bangalore