ã¯ããã«
ãæ¬ç¨¿ã§ã¯ãNuSOAPã©ã¤ãã©ãªã使ç¨ãã¦PHP Webãµã¼ãã¹ãæ§ç¯ããæ¹æ³ã¨ãAJAXæè¡ããã³SOAPãããã³ã«ã使ç¨ãã¦PHP Webãµã¼ãã¹ãå©ç¨ããJavaScriptã¯ã©ã¤ã¢ã³ããæ§ç¯ããæ¹æ³ãä¸å¿ã«èª¬æãã¾ããã¾ãã¯ãWebãµã¼ãã¹ã®ç¨èªã«ã¤ãã¦å°ã説æãã¾ãããã
SOAPããã³Webãµã¼ãã¹ã«é¢ããæ¦ç¥
ãSOAPï¼Simple Object Access Protocolï¼ã¯ãXMLãã¼ã¹ã®è¦æ±ï¼å¿çã¡ãã»ã¼ã¸ã³ã°ãããã³ã«ã§ããSOAPã®éè¦ãªç¹å¾´ã¯ãç¹å®ã®ãã©ã³ã¹ãã¼ããããã³ã«ã«ä¾åããï¼æãé »ç¹ã«ä½¿ç¨ãããã®ã¯HTTPã§ãããSMTPãMIMEãªã©ã使ç¨ã§ãã¾ãï¼ãç¹å®ã®ãªãã¬ã¼ãã£ã³ã°ã·ã¹ãã ãããã°ã©ãã³ã°è¨èªã«ãä¾åããªãã¨ããç¹ã§ãããã®ããããã¾ãã¾ãªã½ããã¦ã§ã¢ã¢ã¼ããã¯ãã£ä¸ã§é«ãæè»æ§ãçºæ®ããã ãã§ã¯ãªããé常ã«ä½¿ãããããªã£ã¦ãã¾ãã
ãWebãµã¼ãã¹ã¨ã¯ããããã¯ã¼ã¯ä¸ã§ãªã¢ã¼ãã«å¼ã³åºãããããè¨è¨ãããã½ããã¦ã§ã¢ã·ã¹ãã ã®ä¸è¬çãªå称ã§ãããããã®ãµã¼ãã¹ã§å®è¡ãããã¿ã¹ã¯ã¯å¤å²ã«ããããå®è£ ãããããã«ç°ãªãã¾ãããä¸è¬çãªWebãµã¼ãã¹ã¯æ¬¡ã®ãã¨ãåæã¨ãã¦ãã¾ãã
- Webãµã¼ãã¹ã¯ãä¸é£ã®æä½ã«åºã¥ãã¦åãåãããåãããµã¼ãã¨ãã¦å ¬éããã¾ãã
- å©ç¨å¯è½ãªæä½ããWSDLï¼Webãµã¼ãã¹è¨è¿°è¨èªï¼ããã¥ã¡ã³ãã¨å¼ã°ããXMLããã¥ã¡ã³ãã使ç¨ãã¦ããããªãã·ã¥ããã¾ããé常ããã®ããã¥ã¡ã³ãã¯ã人éã®æã§ã¯ãªãæ©æ¢°ã«ãã£ã¦çæããã解æï¼åæï¼ããã¾ãã
- Webãµã¼ãã¹ã«ã¢ã¯ã»ã¹ããã¨ã³ãã£ãã£ã¯ãWebãµã¼ãã¹ã¯ã©ã¤ã¢ã³ãã¨å¼ã°ãã¾ãã
- ã¯ã©ã¤ã¢ã³ãã¨ãµã¼ãéã®éä¿¡ãããã³ã«ã¯SOAPã§ãã
PHPã§SOAPã使ç¨ãã
ãWebãµã¼ãã¹ã¯ã¾ãããéã«ãã¾ãã¾ãªåéã§å©ç¨ãããããã«ãªã£ããããä¸è¬çãªããã°ã©ãã³ã°è¨èªã®ã»ã¨ãã©ã¯ãWebãµã¼ãã¹ã®æ§ç¯ã¨å©ç¨ã«å¯¾ãããµãã¼ããæä¾ããããå¼·åãã¹ãåãçµãã§ãã¾ãããä¾ãã°ãPHPã«ã¯ãWebãµã¼ãã¹ã®ãµãã¼ãã追å ããããã¤ãã®æ¡å¼µæ©è½ï¼PEARã¨ã©ã¤ãã©ãªï¼ãããã¾ããPHP5以éã¯ããã®ãããªãµãã¼ãã¯NuSOAPã¨å¼ã°ããã©ã¤ãã©ãªã¨ãã¦ãPHPã«æ¨æºè£ åããã¦ãã¾ãã
ãNuSOAPã©ã¤ãã©ãªã¯æä½æ§ã¨æ§è½ã«åªãã¦ãããããæ¬ç¨¿ã§ã¯ããã®ã©ã¤ãã©ãªã使ç¨ãã¦å®å ¨ãªWebãµã¼ãã¹ãéçºããæ¹æ³ã説æãã¾ããããèªè ãä»ã®æ¡å¼µæ©è½ï¼ã©ã¤ãã©ãªã«ç²¾éãã¦ãã¦ãæ¬ç¨¿ã®å¾åé¨åï¼JavaScript AJAXã¯ã©ã¤ã¢ã³ãã®éçºæ¹æ³ï¼ã«ã®ã¿é¢å¿ãããå ´åã¯ãã好ã¿ã®æè¡ã使ç¨ãã¦ããµã¼ãå´Webãµã¼ãã¹ãåæ§ç¯ãããã¨ããã¡ããå¯è½ã§ãã
ãNuSOAPã©ã¤ãã©ãªã¯ãHTTPãããã³ã«ã使ç¨ãã¦SOAPã¡ãã»ã¼ã¸ã®éåä¿¡ããµãã¼ãããPHPã¯ã©ã¹ã®éåã§ããNuSOAPã©ã¤ãã©ãªã¯ãå¥åãSOAPx4ãã¨ãå¼ã°ããNuSphere社ã®è£½åã§ãå ¬å¼ãµã¤ããããã¦ã³ãã¼ãã§ãã¾ããNuSOAPã¯ã©ã¹ã使ç¨ããã«ã¯ãPHPã½ã¼ã¹ãã¡ã¤ã«å ã«æ¬¡ã®ã³ã¼ãã¹ãããããå«ãã¾ãã
require_once('{NuSOAPãã©ã«ããã¹ããã³ãã©ã«ãå}/lib/nusoap.php');
ãæ¬ç¨¿ã§ããããNuSOAPã使ã£ã¦éçºãããµã¼ãã¯ãTriangleArea
ã¨RectangleArea
ã¨ãã2ã¤ã®ã¡ã½ãããå
¬éãã¾ãããããã®ã¡ã½ããã¯ããã®åã®ã¨ãããããããä¸è§å½¢ã¨é·æ¹å½¢ã®é¢ç©ãæ±ãã¾ãã次ã«ãWebãµã¼ãã¹ãéçºããæé ãç´¹ä»ãã¾ãã
1ãã¡ã½ããã®è¨è¿°
ãã¾ãã2ã¤ã®ã¡ã½ãããè¨è¿°ãã¾ãããåããã®ããã«åç´ãªä½æ¥ã§ãã
// Define the TriangleArea method as a PHP function function TriangleArea($b, $h) { return 'The triangle area is:' .((b*h)/2); } // Define the RectangleArea method as a PHP function function RectangleArea($L, $l) { return 'The rectangle area is:' .($L*$l);
ãããããã®ã¡ã½ããã¯2ã¤ã®ãã©ã¡ã¼ã¿ãåãã¾ããTriangleArea
ã¡ã½ããã¯ä¸è§å½¢ã®åºè¾ºã¨é«ãã®æ´æ°å¤ãRectangleArea
ã¡ã½ããã¯é·æ¹å½¢ã®å¹
ã¨é«ãã§ããã©ã¡ãã®ã¡ã½ããããè¨ç®ã«ããã¦æ±ããããé¢ç©ã®å¤ãå«ãæååãè¿ãã¾ãã
ãããã2ã¤ã®ã¡ã½ãããè¨è¿°ããããã¡ã½ãããå ¬éããããã®Webãµã¼ãã¹ãå¿ è¦ã«ãªãã¾ãã
2ãWebãµã¼ãã¹ã¤ã³ã¹ã¿ã³ã¹ãåå¾
ãNuSOAPã¯ãWebãµã¼ãã¹ã®è©³ç´°ã1ã¤ã®ã¯ã©ã¹ã«ã«ãã»ã«åãã¦ããã®ã§ã次ã®ããã«ç©ºã®ã³ã³ã¹ãã©ã¯ã¿soap_server
ãå¼ã³åºãã ãã§ãWebãµã¼ãã¹ã¤ã³ã¹ã¿ã³ã¹ãåå¾ã§ãã¾ãã
// Create the server instance $server = new soap_server();
3ãWSDLãã¡ã¤ã«ã®ååã¨åå空éãæå®
ãWebãµã¼ãã¹ãµã¼ãã«å¯¾å¿ããWSDLãã¡ã¤ã«ã®ååã¨åå空éãæå®ãã¾ãããããè¡ãã«ã¯ãååã¨åå空éã®ã¿ãå¿
è¦ã¨ããnusoap.php
ã¯ã©ã¹ã®configureWSDL
ã¡ã½ãããå¼ã³åºãã¾ãã
// Initialize WSDL support $server->configureWSDL('mathwsdl', 'urn:mathwsdl');
4ãã¡ã½ãããç»é²
ã次ã«ãã¡ã½ãããç»é²ãã¾ãï¼ãã®ä¾ã§ã¯2ã¤ããã¾ãï¼ãã¡ã½ãããç»é²ãããã¨ã§ããã®ã¡ã½ããã®ååãå¼æ°ãæ»ãå¤ã®åãSOAPã¢ã¯ã·ã§ã³ãã¹ã¿ã¤ã«ãã¨ã³ã³ã¼ãã£ã³ã°ã説æãWebãµã¼ãã¹ãµã¼ãã«èªèããã¾ãããããã®ããããã£ã¯ãã¹ã¦ãregister
ã¨ãã1ã¤ã®ã¡ã½ããã§æå®ã§ãã¾ããä¾ãã°ãTriangleArea
ã¨RectangleArea
ã¡ã½ãããç»é²ããã«ã¯ã次ã®ããã«è¡ãã¾ãã
// Register the TriangleArea method $server->register('TriangleArea', // method name array('b' => 'xsd:int', 'h' => 'xsd:int'), // input parameters array('area_t' => 'xsd:string'), // output parameters 'urn:mathwsdl', // namespace 'urn:mathwsdl#TriangleArea', // soapaction 'rpc', // style 'encoded', // use 'Calculate a triangle area as (b*h)/2' // documentation ); // Register the RectangleArea method to expose $server->register('RectangleArea', // method name array('L' => 'xsd:int', 'l' => 'xsd:int'), // input parameters array('area_r' => 'xsd:string'), // output parameters 'urn:mathwsdl', // namespace 'urn:RectangleAreawsdl#RectangleArea', // soapaction 'rpc', // style 'encoded', // use 'Calculate a rectangle area as (L*l)' // documentation );
ããã®ç»é²å 容ã¯ãNuSOAPåºæã®ãã®ã§ãã
5ãWebãµã¼ãã¹ãèµ·å
ãæå¾ã«ã次ã®ããã«ãã¦NuSOAPã®service
ã¡ã½ãããå¼ã³åºããWebãµã¼ãã¹ãèµ·åãã¾ãã
// Use the request to (try to) invoke the service $HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : ''; $server->service($HTTP_RAW_POST_DATA);
ããã®ã·ã³ãã«ãª5ã¤ã®ã¹ããããå®è¡ããã¨ããªã¹ã1ã®Webãµã¼ãã¹ã®ãããªã³ã¼ããå¾ããã¾ãï¼ãããwebserviceã¨ããååã®ãã©ã«ãã«ä¿åãã¦ããã¾ãï¼ã
<?php // Pull in the NuSOAP code require_once('./nusoap-php5-0.9/lib/nusoap.php'); // Create the server instance $server = new soap_server(); // Initialize WSDL support $server->configureWSDL('mathwsdl', 'urn:mathwsdl'); // Register the TriangleArea method to expose it $server->register('TriangleArea', // method name array('b' => 'xsd:int', 'h' => 'xsd:int'), // input parameters array('area_t' => 'xsd:string'), // output parameters 'urn:mathwsdl', // namespace 'urn:mathwsdl#TriangleArea', // soapaction 'rpc', // style 'encoded', // use 'Calculate a triangle area as (b*h)/2' // documentation ); // Register the RectangleArea method to expose it $server->register('RectangleArea', // method name array('L' => 'xsd:int', 'l' => 'xsd:int'), // input parameters array('area_r' => 'xsd:string'), // output parameters 'urn:mathwsdl', // namespace 'urn:RectangleAreawsdl#RectangleArea', // soapaction 'rpc', // style 'encoded', // use 'Calculate a rectangle area as (L*l)' // documentation ); // Define the TriangleArea method as a PHP function function TriangleArea($b, $h) { return 'The triangle area is: ' .((b*h)/2); } // Define the RectangleArea method as a PHP function function RectangleArea($L, $l) { return 'The rectangle area is: ' .($L*$l); } // Use the request to (try to) invoke the service $HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : ''; $server->service($HTTP_RAW_POST_DATA); ?>