PHP5 Web Service(SOAP)標準範例
資料來源: https://www.youtube.com/watch?v=UEpdhxM1ikk
test.wsdl
targetNamespace=’urn:myTns’ xmlns:tns=’urn:myTns’ xmlns:wsdl=’http://schemas.xmlsoap.org/wsdl/’ xmlns:xsd=’http://www.w3.org/2001/XMLSchema’ xmlns:soap12=’http://schemas.xmlsoap.org/wsdl/soap12/’ xmlns=’http://schemas.xmlsoap.org/wsdl/’>
|
testclient.php
$client = new SoapClient(“HTTP的絕對路徑/test.wsdl”, array(‘soap_version’ => SOAP_1_2,’trace’ => 1 )); $a=200; $b=100; $return = $client->__soapCall(“SumData”,array(‘Sum_a’ => $a,’Sum_b’ =>$b)); print_r($return); echo ‘ $return1 = $client->__soapCall(“SubData”,array(‘Sub_a’ => $a,’Sub_b’ =>$b)); print_r($return1); ?> |
testserver.php
class TestClass { function SumData($a,$b) { return $a+$b; } function SubData($a,$b) { return $a-$b; } } ini_set(“soap.wsdl_cache_enabled”, “0”); // disabling WSDL cache $server = new SoapServer(‘HTTP的絕對路徑/test.wsdl’, array(‘soap_version’ => SOAP_1_2)); $server->setClass(‘TestClass’); $server->handle(); ?> |