PHP5 en SOAP
March 12th, 2007 by TijsIk ben de laatste dagen aan het uitzoeken hoe ik een webservice kan maken. Na veel lezen, opzoeken, vragen stellen hebben de mannen van Openminds mij op het juiste pad gebracht (waarvoor dank), namelijk SOAP.
Omdat ik heel wat problemen ben tegengekomen zet ik hieronder even de code om anderen te helpen. Let wel, ik ben ook nieuw met SOAP. Dus sla mij niet dood als het niet direct werkt.
Eerst heb ik de "server geschreven".
PHP:
-
<?php
-
// require the class that will handle the calls
-
require_once 'classes/API.php';
-
-
// disable the soap.wsdl_cache
-
-
// get RAW_POST_DATA
-
-
// set options for the server
-
-
// init server
-
$server = new SoapServer(null, $options);
-
-
// set the class that will handle the SOAP-requests
-
$server->setClass('API');
-
-
// handle SOAP-requests
-
$server->handle();
-
?>
Dan de class die de SOAP-requests zal afhandelen.
PHP:
-
<?php
-
class API
-
{
-
/**
-
* returns 'Hello World'
-
*
-
* @return string
-
*/
-
public function sayHello()
-
{
-
return 'Hello World';
-
}
-
}
-
?>
Dan de "client".
PHP:
-
<?php
-
// set client options
-
$options = array('location' => 'http://localhost/SOAP/server.php', 'uri' => 'http://localhost/SOAP/');
-
-
try {
-
// init client
-
$client = new SoapClient(null, $options);
-
// make SOAP-request and print it
-
echo '<pre>';
-
echo '</pre>';
-
}
-
// catch SOAP-errors
-
catch(SoapFault $e)
-
{
-
// print error
-
}
-
?>
Opmerkingen zijn uiteraard welkom!
October 25th, 2007 at 12:09
Ik heb de scriptjes aangemaakt, en inderdaad, het werkt als een tierelier.
Leuke om te zien is dat de client daarna een HTTP POST van de data doet naar de server:
192.168.1.105 – - [25/Oct/2007:13:06:36 +0200] “GET /development/SOAP/client.php HTTP/1.1″ 200 23 “http://testing.local/development/SOAP/” “Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.8) Gecko/20071008 Firefox/2.0.0.8″
192.168.1.107 – - [25/Oct/2007:13:06:36 +0200] “POST /development/SOAP/server.php HTTP/1.1″ 200 544 “-” “PHP-SOAP/5.2.0-8+etch7″
January 24th, 2008 at 10:16
Hey ik had even een vraagje ik gebruik zelf
XAMPP en heb nu binnen htdoc’s een mapje aan gemaakt genaamd SOAP daar heb ik server.php aan gemaakt client.php aan gemaakt en een map gemaakt classes en daar in heb ik API.php aangemaakt als ik nu localhost/SOAP doe zie ik alleen die 3 files.. iemand enige idee hoe dit zou moeten of kunnen werken?
ik hoop van jullie te horen
groetjes
Marcel
June 2nd, 2009 at 22:24
Wat ben ik blij dit te vinden. Bedankt voor de big help!
Nuttige informatie over SOAP en PHP is niet zo makkelijk te vinden.
Bedankt
October 13th, 2009 at 01:09
fantastic code!
March 28th, 2010 at 08:13
Welcome to Free-VPN-Unlim.com
Even, if malefactors can intercept the information which you have transferred in a NETWORK, they cannot read it.
March 28th, 2010 at 16:28
How do people actually make money with porn?
April 4th, 2010 at 05:26
יבוא בקלות של מוצרים מסין? מוצרים תוצרת סין נעליים ביגוד מכונות תעשייה הו בכלל לייצר בסין אנחנו נעזור לך בכל התהליך ייצוג בקנטון פייר -1888- קטלוגים ופרטים
April 9th, 2010 at 12:06
How much money do i need to survive in Budapest as a foreign student?
August 26th, 2010 at 10:03
Hi , I have been using a excellent way to make lots and lots of money online blogging. I expect this is primaraly for the website administrator but there are probably lots more bloggers reading this. I’ve made thousands using the techniques detailed in the product and its only been 2 months. Auto Blog System X
August 31st, 2010 at 16:27
Sick of obtaining low numbers of useless visitors to your website? Well i want to let you know about a fresh underground tactic that produces me personally $900 each day on 100% AUTOPILOT. I possibly could be here all day and going into detail but why dont you just check their site out? There is really a excellent video that explains everything. So if your seriously interested in making hassle-free hard cash this is the website for you. Auto Traffic Avalanche
September 7th, 2010 at 14:01
Tired of getting low numbers of useless traffic to your site? Well i want to inform you of a brand new underground tactic that makes me personally $900 every day on 100% AUTOPILOT. I possibly could be here all day and going into detail but why dont you simply check their site out? There is really a excellent video that explains everything. So if your serious about producing easy cash this is the site for you. Auto Traffic Avalanche