Creating Web Service Using PHP Within 10 Minutes - CodeProject
Creating Web Service Using PHP Within 10 Minutes - CodeProject
Introduction
Today, I am trying to write up on web service functionality and also how to consume it using PHP code. Basically, it is a very beginner level web service tip but you will gather knowledge step by step & easily run it on your server.
Contents
1. 2. 3. 4. What is SOAP? Why SOAP? Create web service method Consume web service
Background
What is SOAP?
SOAP is based on XML so it is considered human read. It is a protocol for accessing a Web Service. It is a simple XML-based protocol to let applications exchange information over HTTP.
Why SOAP?
In real field, so many applications are required for data communication between systems by Remote Procedure Calls (RPC) between objects like DCOM and CORBA but HTTP was not designed for this. RPC represents compatibility Security problem
Firewalls and proxy servers will normally block this kind of traffic. A better way to communicate between applications is over HTTP as HTTP is supported by all Internet browsers and servers. That's why it is preferable to SOAP Service. We can collaborate with other programmers building big size and complex applications in multiple platforms.
Step 7: After creating server.php file, now we will test this server function. Please go to URL & type http://localhost/WebServiceSOAP/server.php?wsdl. Step 8: Create "client.php" file into WebServiceSOAP folder location. Please find the following code lines:
< ? p h p r e q u i r e _ o n c e( ' l i b / n u s o a p . p h p ' ) ; / / G i v ei tv a l u ea tp a r a m e t e r $ p a r a m=a r r a y (' y o u r _ n a m e '= >' M o n o t o s hR o y ' ) ; / / C r e a t eo b j e c tt h a tr e f e r e raw e bs e r v i c e s $ c l i e n t=n e ws o a p c l i e n t ( ' h t t p : / / l o c a l h o s t / W e b S e r v i c e S O A P / s e r v e r . p h p ' ) ; / / C a l laf u n c t i o na ts e r v e ra n ds e n dp a r a m e t e r st o o
$ r e s p o n s e=$ c l i e n t > c a l l ( ' g e t _ m e s s a g e ' , $ p a r a m ) ; / / P r o c e s sr e s u l t i f ( $ c l i e n t > f a u l t ) { e c h o" F A U L T :< p > C o d e :( " . $ c l i e n t > f a u l t c o d e . " < / p > " ; e c h o" S t r i n g :" . $ c l i e n t > f a u l t s t r i n g ; } e l s e { e c h o$ r e s p o n s e ; } ? >
Step 9: Save all codes, then please go to URL and type http://localhost/WebServiceSOAP/client.php.
R e s u l t :W e l c o m et oM o n o t o s hR o y .T h a n k sf o rY o u rF i r s tW e bS e r v i c eU s i n gP H Pw i t hS O A P
So, today I have shown you how to use simple SOAP web service and to get message from service at client end. Hope this post will help you to create a simple web service using SOAP. Post your queries if you have any or if there is anything else, please share. Keep visiting for new posts here. Have a good day!
History
21 st October, 2013: Initial post - Step by step understanding of web service functionality
License
This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)
My Name is Monotosh Roy (Mon), Completed Bachelor In Computer Science from West Bengal University of Technology, India & M.Sc. In Computer Science & Engineering from United International University. I have lots of experience on core software development with API service integration more than 8 years using tools- ASP.Net, C#, PL/SQL, WCF, SAP, SugerCRM, Salesforce, VBA Excel Export, Web Service, PHP, and MVC 2/3/4 etc. I had successfully implemented more