devxlogo

Web Service using PHP with SOAP

Web Service using PHP with SOAP

web service is used for how to consum it using PHP code. Basically this example of very simple and beginner level web service example. So please learnt step by step and easily can use in your browser.Q1. What is SOAP ?Ans- SOAP is xml mean it based on xml language that is considered human read. It is a protocol for accessing a web services and sent or exchange information via HTTP.Q2 Why SOAP ?ans- Many applications exchange information or data communication between system by remote procedure calls but HTTP not designed for this. HTTP support all browser and server so that’s why it is preferable to SOAP.Creating a Web Service:-step 1:- make server.php file and put that code in this file and save this file to server or local server in root folderif you are using wamp server then you need to place this file on www/ folder or if you using xampp local server then you need to place this file into htdocs/ folder.code- server.php -register(‘get_message’); // create the function function get_message($your_name) { if(!$your_name){ return new soap_fault(‘Client’,”,’Put Your Name!’); } $result = “Welcome to “.$your_name .”. Thanks for Your First Web Service Using PHP with SOAP”; return $result; } // create HTTP listener $server-service($HTTP_RAW_POST_DATA); exit(); ? now for accessing this code we make a client.php file.code – client.php ‘Shreyansh Sethia’); //Create object that referer a web services $client = new soapclient(‘http://localhost/WebServiceSOAP/server.php’); //Call a function at server and send parameters too $response = $client-call(‘get_message’,$param); //Process result if($client-fault) { echo “FAULT:

Code: (“.$client-faultcode.”

“; echo “String: “.$client-faultstring; } else { echo $response; } ? Save this file also in root folder.now run client.php file on your server and then you output is-Result: Welcome to Shreyansh Sethia. Thanks for Your First Web Service Using PHP with SOAPso from this way we make a web service in php.Thanks

devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist