ã€ãæè¿ãç§ã¯WebãµãŒãã¹ã®éçºãå§ããŸããã ããããä»æ¥ã®ãããã¯ã¯ç§ã«é¢ãããã®ã§ã¯ãªããSOAP 1.2ãããã³ã«ã«åºã¥ããŠXML WebãµãŒãã¹ãäœæããæ¹æ³ã«é¢ãããã®ã§ãã
ãããã¯ãèªãã åŸã次ã®ããšãã§ããããšãé¡ã£ãŠããŸãã
- Webã¢ããªã±ãŒã·ã§ã³ã®ç¬èªã®ãµãŒããŒå®è£ ãäœæããŸãã
- Webã¢ããªã±ãŒã·ã§ã³ã®ç¬èªã®ã¯ã©ã€ã¢ã³ãå®è£ ãäœæããŸãã
- ç¬èªã®WebãµãŒãã¹èšè¿°ïŒWSDLïŒãäœæããŸãã
- åãã¿ã€ãã®ããŒã¿ã®ã¯ã©ã€ã¢ã³ãé åã«ãã£ãŠãµãŒããŒã«éä¿¡ããŸãã
ãæ³åã®ãšããããã¹ãŠã®éæ³ã¯PHPãšSoapClientããã³SoapServerçµã¿èŸŒã¿ã¯ã©ã¹ã䜿çšããŠè¡ãããŸãã ããããšããŠãSMSã¡ãã»ãŒãžãéä¿¡ãããµãŒãã¹ããããŸãã
1åé¡æ
1.1å¢çç·
æåã«ããããã¯ã®æåŸã§éæããçµæã«å¯ŸåŠããããšãææ¡ããŸãã äžèšã§çºè¡šããããã«ãSMSã¡ãã»ãŒãžãéä¿¡ããããã®ãµãŒãã¹ãäœæããŸããããæ£ç¢ºã«ã¯ãSOAPãããã³ã«ãä»ããŠããŸããŸãªãœãŒã¹ããã¡ãã»ãŒãžãåä¿¡ããŸãã ãã®åŸãã©ã®åœ¢åŒã§ãµãŒããŒã«æ¥ãããæ€èšããŸãã æ®å¿µãªããããããã€ãã«ããã«éä¿¡ããããã«ã¡ãã»ãŒãžããã¥ãŒã«å ¥ããããã»ã¹ã¯ãå€ãã®çç±ã§ãã®æçš¿ã®ç¯å²å€ã§ãã
1.2ã©ã®ããŒã¿ãå€æŽãããŸããïŒ
ããŠãåœå¢ã決ããŸããïŒ æ¬¡ã®ã¹ãããã¯ããµãŒããŒãšã¯ã©ã€ã¢ã³ãéã§äº€æããããŒã¿ã決å®ããããšã§ãã ãã®ããŒãã«ã€ããŠãç§ã¯é·ãéé ãè¯ããªãããšãææ¡ããããã«èªåèªèº«ã®äž»èŠãªè³ªåã«çããŸãïŒ
- SMSã¡ãã»ãŒãžããµãã¹ã¯ã©ã€ããŒã«éä¿¡ããããã«ããµãŒããŒã«éä¿¡ããå¿ èŠãããæå°ããŒã¿ã¯äœã§ããïŒ
- ã¯ã©ã€ã¢ã³ãã®ããŒãºãæºããããã«ããµãŒããŒããã©ã®ãããªæå°ããŒã¿ãéä¿¡ããå¿ èŠããããŸããïŒ
ãã®ããã«ã¯ã次ã®æ å ±ãéä¿¡ããå¿ èŠãããããšãããããŸãã
- æºåž¯é»è©±çªå·ã
- SMSã¡ãã»ãŒãžããã¹ãã
ååãšããŠãããã2ã€ã®ç¹æ§ã¯éä¿¡ã«ååã§ãããèªçæ¥ãç¥ãSMSãåå3æãŸãã¯4æã«å±ãå Žåãããã«èããŸãïŒ ãã®ç¬éãç§ãå¿ããããªãããšãçã«æè¬ããŸãïŒ ãããã£ãŠããµãŒããŒã«ãéä¿¡ãã
- SMSãéä¿¡ãããæ¥ä»ã
次ã«ãµãŒããŒã«éä¿¡ãããã®ã¯
- ã¡ãã»ãŒãžã®ã¿ã€ãã
ãã®ãã©ã¡ãŒã¿ãŒã¯å¿ é ã§ã¯ãããŸãããããã¥ãŒã¹ããåãã§ãããã顧客ã®æ°ãäžåžã«ããã«äŒããå¿ èŠããããããã«é¢ããããã€ãã®è¯ãçµ±èšãæç»ããå¿ èŠãããå Žåãéåžžã«åœ¹ç«ã¡ãŸãã
ããã§ããç§ã¯äœããå¿ããŸããïŒ ããå°ãåå°ããå Žåãã¯ã©ã€ã¢ã³ãã¯äžåºŠã«1ã€ã®SMSã¡ãã»ãŒãžãšãã®äžéšããµãŒããŒã«éä¿¡ã§ããããšã«æ³šæããŠãã ããã ã€ãŸãã1ã€ã®ããŒã¿ãã±ããã«1ãç¡éã®ã¡ãã»ãŒãžãå«ããããšãã§ããŸãã
ãã®çµæãSMSã¡ãã»ãŒãžãéä¿¡ããã«ã¯æ¬¡ã®ããŒã¿ãå¿ èŠã«ãªããŸãã
- æºåž¯é»è©±çªå·
- SMSããã¹ãã¡ãã»ãŒãž
- SMSã¡ãã»ãŒãžãå å ¥è ã«éä¿¡ããæéã
- ã¡ãã»ãŒãžã®ã¿ã€ãã
æåã®è³ªåã«çããŸããããä»åºŠã¯2çªç®ã®è³ªåã«çããå¿ èŠããããŸãã ãããŠãããããç§ã¯èªåèªèº«ã«å°ãããã¯ãèš±å¯ããŸãã ãããã£ãŠããµãŒããŒããããŒã«å€ããŒã¿ã®ã¿ãéä¿¡ããŸãããã®å€ã®æå³ã¯æ¬¡ã®ãšããã§ãã
- TRUE-ãã±ããã¯ãµãŒããŒã«æ£åžžã«å°éããèªèšŒã«åæ ŒããSMSãããã€ããŒã«éä¿¡ããããã«ãã¥ãŒã«é 眮ãããŸãã
- FALSE-ä»ã®ãã¹ãŠã®å Žå
ããã§ãåé¡ã¹ããŒãã¡ã³ãã®èª¬æãçµãããŸããïŒ æåŸã«ã楜ããéšåã«åãæãããŸãããããã®SOAPãå¥åŠãªç£ã§ããããšãããããŸãã
2 SOAPãšã¯äœã§ããïŒ
äžè¬çã«ãæåã¯SOAPãšã¯äœããæžãã€ããã¯ãªãã£ãã®ã§ãå¿ èŠãªä»æ§ãåããw3.orgãŠã§ããµã€ããžã®ãªã³ã¯ãšWikipediaãžã®ãªã³ã¯ã«éå®ãããã£ãã ããããæåŸã«ç§ã¯ãã®ãããã³ã«ã«ã€ããŠçãã¡ã¢ãæžãããšã«ããŸããã
ãããŠããã®ããŒã¿äº€æãããã³ã«ã¯ãããããRPCïŒãªã¢ãŒãããã·ãŒãžã£ã³ãŒã«ïŒãã©ãã€ã ã«åºã¥ããããã³ã«ã®ãµãã»ãããåç §ãããšããäºå®ãã話ãå§ããŸãããã®ãã©ãããã¯RESTïŒRepresentational State Transferã代衚ç¶æ 転éïŒã§ãã ããã«ã€ããŠã®è©³çŽ°ã¯ãŠã£ãããã£ã¢ã§èªãããšãã§ããŸããèšäºãžã®ãªã³ã¯ã¯ãããã¯ã®æåŸã«ãããŸãã ãããã®èšäºããã次ã®ããšãæ確ã«ããå¿ èŠããããŸãããRPCã¢ãããŒãã䜿çšãããšãå€æ°ã®ã¡ãœãããšè€éãªãããã³ã«ã§å°éã®ãããã¯ãŒã¯ãªãœãŒã¹ã䜿çšã§ããŸãã RESTã¢ãããŒãã§ã¯ãã¡ãœããã®æ°ãšãããã³ã«ã®è€éããå³å¯ã«å¶éãããŠãããããåã ã®ãªãœãŒã¹ã®æ°ãå€ããªãå¯èœæ§ããããŸãã ã€ãŸããç§ãã¡ã«é¢ããŠã¯ãRPCã¢ãããŒãã®å Žåããµã€ãã«ã¯ãµãŒãã¹ãžã®å ¥åïŒãªã³ã¯ïŒãåžžã«1ã€ãããRESTã¢ãããŒãã§ã¯ãããŒã¿ãšäžç·ã«çä¿¡ããŒã¿ãåŠçããããã«åŒã³åºãæé ãåžžã«ååšãããšããããšã§ãããµã€ãã«ã¯å€ãã®å ¥åïŒãªã³ã¯ïŒãããããããããç¹å®ã®ããŒã¿ã®ã¿ãåä¿¡ããŠââåŠçããŸãã èªè ã®äžäººãããããã®ã¢ãããŒãã®éããããç°¡åã«èª¬æããæ¹æ³ãç¥ã£ãŠãããªããã³ã¡ã³ããæžããŠãã ããïŒ
SOAPã«ã€ããŠæ¬¡ã«åŠã¶å¿ èŠãããã®ã¯ããã®ãããã³ã«ããã©ã³ã¹ããŒããšåãXMLã䜿çšããããšã§ãã ããã«ããã®ããŒã¯ã¢ããèšèªã«åºã¥ããæè¡ã®ã¹ã¿ãã¯ã®ãã¹ãŠã®åãç§ãã¡ã®æŠåšãã€ãŸãXML-Schema-XMLããã¥ã¡ã³ãã®æ§é ãèšè¿°ããããã®èšèªã«ãªããŸãïŒWikipediaã®ãããïŒïŒãã¯ã©ã€ã¢ã³ããããµãŒããŒã«æ¥ãããŒã¿ã®èªåæ€èšŒãå¯èœã«ããŸãã
ãããã£ãŠãSOAPã¯ãªã¢ãŒãããã·ãŒãžã£ã³ãŒã«ã®å®è£ ã«äœ¿çšããããããã³ã«ã§ãããXMLããã©ã³ã¹ããŒããšããŠäœ¿çšããããšãããããŸããã Wikipediaã®èšäºãèªããšããããããHTTPãšã®ãã¢ãªã³ã°ã ãã§ãªããã¢ããªã±ãŒã·ã§ã³ã¬ãã«ã®ãããã³ã«ã§äœ¿çšã§ããããšãããããŸãïŒæ®å¿µãªããããã®ãããã¯ã§ã¯HTTPçµç±ã®SOAPã®ã¿ãæ€èšããŸãïŒã ãããŠãããªãã¯ç§ããã®ãã¹ãŠã«ã€ããŠæã奜ããªãã®ãç¥ã£ãŠããŸããïŒ æšæž¬ããªãå Žåã¯ããã³ãã衚瀺ããŸã-SOAPïŒ...æšæž¬ã衚瀺ãããŸããã§ãããïŒ... Wikipediaã®èšäºãééããªãèªã¿ãŸãããïŒ...äžè¬çã«ããã以äžè¿·æããããŸããã ãããã£ãŠãç§ã¯ããã«çãã«è¡ããŸãïŒãSOAPïŒè±èªãããSimple Object Access Protocol-ãªããžã§ã¯ãã«ã¢ã¯ã»ã¹ããããã®åçŽãªãããã³ã« ã ä»æ§1.2ãŸã§ ïŒãã ãã®è¡ã§æã泚ç®ãã¹ãã¯æäœã§ãïŒ ãã®ãã¹ãŠããããªããã©ã®ãããªçµè«ãåºããã®ãããããŸãããã次ã®ããã«èŠããŸã-ãã®ãããã³ã«ã¯æ±ºããŠãã·ã³ãã«ããšåŒã¶ããšã¯ã§ããªãããïŒãããŠæããã«w3ãããã«åæããŸãïŒãããŒãžã§ã³1.2ããäžè¬çã«äœããã®æ¹æ³ã§è§£èªãåæ¢ããŸããïŒ ãããŠãããã¯SOAPãšåŒã°ããåã«SOAPãšåŒã°ããŸããã
ããŠã倧äžå€«ããã¿ãŸãããå°ã暪ã«æ»ããŸããã åã«æžããããã«ãXMLã¯ãã©ã³ã¹ããŒããšããŠäœ¿çšãããã¯ã©ã€ã¢ã³ããšãµãŒããŒéã§å®è¡ããããã±ããã¯SOAPãšã³ãããŒããšåŒã°ããŸãã ãšã³ãããŒãã®äžè¬åãããæ§é ãèæ ®ãããšãéåžžã«éŠŽæã¿ãããããã«æããŸãã HTMLããŒãžã®æ§é ã«äŒŒãŠããŸãã ã¡ã€ã³ã»ã¯ã·ã§ã³-Envelopããã ãããã«ã¯Headerã»ã¯ã·ã§ã³ãšBodyã»ã¯ã·ã§ã³ããŸãã¯Faultã»ã¯ã·ã§ã³ãå«ãŸããŸãã ããŒã¿ã¯ããã£ã«è»¢éããããšã³ãããŒãã®å¿ é ã»ã¯ã·ã§ã³ã§ããã ããããŒã¯ãªãã·ã§ã³ã§ãã Headerã§ã¯ãèš±å¯ããŸãã¯WebãµãŒãã¹ããã·ãŒãžã£ã®å ¥åããŒã¿ã«çŽæ¥é¢é£ããªããã®ä»ã®ããŒã¿ã転éã§ããŸãã ãšã©ãŒã«ã€ããŠè©±ãããç¹å¥ãªããšã¯ãããŸãããããšã©ãŒãçºçããå Žåã«ãµãŒããŒããã¯ã©ã€ã¢ã³ãã«éç¥ãããç¹ãç°ãªããŸãã
ããã§ãSOAPãããã³ã«ã®æŠèŠãçµäºãïŒã¯ã©ã€ã¢ã³ããšãµãŒããŒãçžäºã«å®è¡ããæ¹æ³ãæçµçã«åŠç¿ãããšãã«ããšã³ãããŒãèªäœãšãã®æ§é ãããã«è©³ãã調ã¹ãŸãïŒã WSDL ïŒWebãµãŒãã¹èšè¿°èšèªïŒãšåŒã°ããSOAPã³ã³ãããªã³ã«ã€ããŠã ã¯ããã¯ããããã¯ãŸãã«ãã®ãããã³ã«ã§APIãååŸããŠå®è£ ããããšããè©Šã¿ããç§ãã¡ã®ã»ãšãã©ãæãããããã®ã§ãã ãã®çµæãéåžžãJSONããã©ã³ã¹ããŒããšããŠäœ¿çšããŠèªè»¢è»ãçºæããŸãã ããã§ã¯ãWSDLãšã¯äœã§ããïŒ WSDLã¯ãWikipediaã®XMLïŒcïŒèšèªã«åºã¥ããWebãµãŒãã¹èšè¿°ããã³ã¢ã¯ã»ã¹èšèªã§ãã ãã®å®çŸ©ããããã®ãã¯ãããžãŒã®ç¥èãªæå³å šäœãç解ããŠããªãå Žåã¯ãèªåã®èšèã§èª¬æããããšæããŸãïŒ
WSDLã¯ãã¯ã©ã€ã¢ã³ãããµãŒããŒãšæ£åžžã«éä¿¡ã§ããããã«èšèšãããŠããŸãã ãããè¡ãããã«ãæ¡åŒµåã* .wsdlã®ãã¡ã€ã«ã«æ¬¡ã®æ å ±ãèšè¿°ãããŠããŸãã
- 䜿çšãããåå空éã
- 䜿çšãããããŒã¿ã¹ããŒã ã
- WebãµãŒãã¹ã顧客ã«æåŸ ããã¡ãã»ãŒãžã®çš®é¡ã¯ã
- ã©ã®ããŒã¿ãã©ã®WebãµãŒãã¹ããã·ãŒãžã£ã«å±ããŠãããã
- WebãµãŒãã¹ã«ã¯ã©ã®ãããªæé ãå«ãŸããŠããŸããïŒ
- ã¯ã©ã€ã¢ã³ãã¯ã©ã®ããã«WebãµãŒãã¹ããã·ãŒãžã£ãåŒã³åºãå¿ èŠããããŸããã
- ã¯ã©ã€ã¢ã³ãåŒã³åºãã®éä¿¡å ã¢ãã¬ã¹ã
ã芧ã®ãšããããã®ãã¡ã€ã«ã¯WebãµãŒãã¹å šäœã§ãã ã¯ã©ã€ã¢ã³ãã§WSDLãã¡ã€ã«ã®ã¢ãã¬ã¹ãæå®ãããšãWebãµãŒãã¹ã«é¢ãããã¹ãŠãããããŸãã ãã®çµæãWebãµãŒãã¹èªäœã®å Žæã«ã€ããŠçµ¶å¯Ÿã«ç¥ãå¿ èŠã¯ãããŸããã WSDLãã¡ã€ã«ã®å Žæã¢ãã¬ã¹ãç¥ãã ãã§ååã§ãïŒ SOAPã¯ããã·ã¢ã®ããšããïŒcïŒã§æãããŠããã»ã©ã²ã©ããªãããšãããã«ããããŸãã
3 XMLã¹ããŒãã®æŠèŠ
ããã§ãSOAPãäœã§ããããSOAPãäœã§ãããã«ã€ããŠå€ãã®ããšãç解ããSOAPããããåãå·»ããã¯ãããžãŒã¹ã¿ãã¯ã®æŠèŠãææ¡ã§ããŸããã ãŸããSOAPã¯ã¯ã©ã€ã¢ã³ããšãµãŒããŒéã®ããåãã®æ¹æ³ã§ãããXMLããŒã¯ã¢ããèšèªããã®ãã©ã³ã¹ããŒããšããŠäœ¿çšãããããããã®ã»ã¯ã·ã§ã³ã§ã¯ãXMLã¹ããŒã ãä»ããèªåããŒã¿æ€èšŒãã©ã®ããã«çºçããããå°ãèŠãŠãããŸãã
ã¹ããŒã ã®äž»ãªã¿ã¹ã¯ã¯ãåŠçããããŒã¿ã®æ§é ãèšè¿°ããããšã§ãã XMLã¹ããŒãã®ãã¹ãŠã®ããŒã¿ã¯ã åçŽ ïŒã¹ã«ã©ãŒïŒåãšè€é ïŒæ§é ïŒåã«åããããŸãã åçŽåã«ã¯æ¬¡ã®ãããªåãå«ãŸããŸãã
- ã²ã
- æ°
- ããŒã«å€
- æ¥ä»
å éšã«æ¡åŒµæ©èœããªãéåžžã«åçŽãªãã®ã ãããã®å¯Ÿæäœã¯è€éãªè€ååã§ãã 誰ããæãæµ®ãã¶è€éãªã¿ã€ãã®æãåçŽãªäŸã¯ãªããžã§ã¯ãã§ãã ããšãã°ãæ¬ã ãã®æ¬ã¯ã èè ã ã¿ã€ãã« ã äŸ¡æ Œ ã ISBNçªå·ãªã©ã®ããããã£ã§æ§æãããŠããŸãã ãããŠããããã®ããããã£ã¯ãåçŽãªã¿ã€ãã§ãè€éãªã¿ã€ãã§ãããŸããŸããã ãããŠãXMLã¹ããŒãã®ã¿ã¹ã¯ã¯ãããèšè¿°ããããšã§ãã
SMSã¡ãã»ãŒãžçšã«XMLã¹ããŒããäœæããããšããå§ãããŸãã 以äžã¯ãSMSã¡ãã»ãŒãžã®xmlã®èª¬æã§ãã
<message> <phone>71239876543</phone> <text> </text> <date>2013-07-20T12:00:00</date> <type>12</type> </message>
è€éãªã¿ã€ãå³ã¯æ¬¡ã®ããã«ãªããŸãã
<element name="message" type="Message" /> <complexType name="Message"> <sequence> <element name="phone" type="string" /> <element name="text" type="string" /> <element name="date" type="dateTime" /> <element name="type" type="decimal" /> </sequence> </complexType>
ãã®ãšã³ããªã¯ã次ã®ããã«èªã¿åãããŸããã Message ãã¿ã€ãã®å€æ°ã message ããšãã Message ããšããè€åã¿ã€ãããããã string ãã¿ã€ãã®èŠçŽ ã phone ããã string ãã¿ã€ãã®ã text ããã dateTime ãã¿ã€ãã®ã date ã ãã¿ã€ã10é²æ°ã® " ã¿ã€ã "ã ãããã®ã¿ã€ãã¯åçŽã§ãã¹ããŒãã®èª¬æã§ãã§ã«å®çŸ©ãããŠããŸãã ããã§ãšãããããŸãïŒ æåã®XMLã¹ããŒããäœæããŸããïŒ
èŠçŽ ã element ããšã complexType ãã®æå³ã¯å€ããå°ãªããæ確ã«ãªã£ããšæãã®ã§ããããã«çŠç¹ãåããããããã«èŠçŽ ã³ã³ããŒã¶ãŒã sequence ãã«åãæ¿ããŸãã composerèŠçŽ ã sequence ãã䜿çšããå Žåãããã«å«ãŸããèŠçŽ ã¯åžžã«å³ã«ç€ºãããŠããé åºã§é 眮ããå¿ èŠãããããããã¯ãã¹ãŠå¿ é ã§ãã ãããã絶æããªãã§ãã ããïŒ XMLã¹ããŒãã«ã¯ãããã«2ã€ã®composerèŠçŽ ããããŸãïŒ choiceãšallã§ãã äœæ²å®¶ã choice ãã¯ããªã¹ããããŠããèŠçŽ ã®ãããã1ã€ãååšããå¿ èŠãããããšãšãäœæ²å®¶ã all ã-ãªã¹ããããèŠçŽ ã®ä»»æã®çµã¿åãããå ±åããŸãã
èŠããŠããããã«ããããã¯ã®æåã®ã»ã¯ã·ã§ã³ã§ã¯ããã±ããã§smsã¡ãã»ãŒãžã1ããç¡éã«éä¿¡ã§ããããšã«åæããŸããã ãããã£ãŠããã®ãããªããŒã¿ãXMLã¹ããŒãã§ã©ã®ããã«å®£èšãããŠããããç解ããããšãææ¡ããŸãã å šäœçãªããã±ãŒãžæ§é ã¯æ¬¡ã®ããã«ãªããŸãã
<messageList> <message> <phone>71239876543</phone> <text> 1</text> <date>2013-07-20T12:00:00</date> <type>12</type> </message> <!-- ... --> <message> <phone>71239876543</phone> <text> N</text> <date>2013-07-20T12:00:00</date> <type>12</type> </message> </messageList>
ãã®è€ååã®ã¹ããŒãã¯æ¬¡ã®ããã«ãªããŸãã
<complexType name="Message"> <sequence> <element name="phone" type="string" minOccurs="1" maxOccurs="1" /> <element name="text" type="string" minOccurs="1" maxOccurs="1" /> <element name="date" type="dateTime" minOccurs="1" maxOccurs="1" /> <element name="type" type="decimal" minOccurs="1" maxOccurs="1" /> </sequence> </complexType> <element name="messageList" type="MessageList" /> <complexType name="MessageList"> <sequence> <element minOccurs="1" maxOccurs="unbounded" name="message" type="Message"/> </sequence> </complexType>
æåã®ãããã¯ã«ã¯ãè€ååã Message ãã®ããç¥ããã宣èšãå«ãŸããŠããŸãã ãæ°ã¥ãã®æ¹ã¯ãã ã¡ãã»ãŒãž ãã«å«ãŸããååçŽåã«ãæ°ãã修食å±æ§ã minOccurs ããšã maxOccurs ããè¿œå ãããŸããã ååããæšæž¬ããã®ã¯é£ããããšã§ã¯ãªããããæåïŒ minOccurs ïŒã¯ããã®ã·ãŒã±ã³ã¹ã«ãã¿ã€ãã phone ããã text ããã date ããããã³ã type ãã®å°ãªããšã1ã€ã®èŠçŽ ãããããšãå ±åããŸãããæ¬¡ïŒ maxOccurs ïŒãã®å±æ§ã¯ãã·ãŒã±ã³ã¹ã«ãã®ãããªèŠçŽ ãæ倧ã§1ã€ããããšã宣èšããŸãã ãã®çµæãä»»æã®ããŒã¿ã®ã¹ããŒã ãèšè¿°ãããšããããããã»ããã¢ããããããã®æãå¹ åºãéžæè¢ãäžããããŸãïŒ
åè·¯ã®2çªç®ã®ãããã¯ã¯ãã¿ã€ãMessageListã® messageListèŠçŽ ã宣èšããŸã ã MessageListã¯å°ãªããšã1ã€ã®ã¡ãã»ãŒãžèŠçŽ ãå«ãè€ååã§ããããã®ãããªèŠçŽ ã®æ倧æ°ã¯ç¡å¶éã§ãïŒ
ããã«ã€ããŠã¯ãã¹ããŒã ã«åŸã£ãŠLikBezãå®äºããå¥ã®ãšããµã€ãã£ã³ã°ãªåéºãåŸ ã£ãŠãããšä»®å®ããŸããç¬èªã®WSDLãäœæããŸãã
4 WSDLãäœæããŸã
WSDLãWebãµãŒãã¹ã§ããããšãèŠããŠããŸããïŒ èŠããŠãããŠãã ããïŒ ãããäœæãããšãå°ããªWebãµãŒãã¹ãæµ®ãã³äžãããŸãã ãããã£ãŠããããã³ã°ããªãããšãææ¡ããŸãã
äžè¬ã«ããã¹ãŠãæ£ããæ©èœããããã«ã¯ãæ£ããMIMEã¿ã€ãã®WSDLãã¡ã€ã«ãã¯ã©ã€ã¢ã³ãã«è»¢éããå¿ èŠããããŸãã ãããè¡ãã«ã¯ãããã«å¿ããŠWebãµãŒããŒãæ§æããå¿ èŠããããŸããã€ãŸããæ¡åŒµåã* .wsdlã®ãã¡ã€ã«ã®MIMEã¿ã€ãã次ã®è¡ã«èšå®ããå¿ èŠããããŸãã
application/wsdl+xml
ãããå®éã«ã¯ãPHPãä»ããŠã text / xml ãHTTPããããŒãéåžžéä¿¡ããŸããã
header("Content-Type: text/xml; charset=utf-8");
ãããŠãã¹ãŠãããŸããããŸããïŒ
ããã«èŠåãããã®ã§ãããã·ã³ãã«ãªWebãµãŒãã¹ã®èª¬æã¯éåžžã«å°è±¡çã§ããæãããªãã§ãã ããã ããã¹ãã®å€§éšåã¯æ°Žãå¿ èŠãšãããã®ã§ãããäžåºŠæžãã°ãããWebãµãŒãã¹ããå¥ã®WebãµãŒãã¹ã«åžžã«ã³ããŒã§ããŸãã
WSDLã¯XMLã§ãããããæåã®è¡ã§ããã«ã€ããŠçŽæ¥èšè¿°ããå¿ èŠããããŸãã ãã¡ã€ã«ã®ã«ãŒãèŠçŽ ã¯ãåžžã«ã å®çŸ© ããšåŒã°ããå¿ èŠããããŸãã
<?xml version="1.0" encoding="utf-8"?> <definitions> </definitions>
éåžžãWSDLã¯4ã5åã®ã¡ã€ã³ãããã¯ã§æ§æãããŸãã æåã®ãããã¯ã¯ãWebãµãŒãã¹ã®å®çŸ©ãã€ãŸããšã³ããªãã€ã³ãã§ãã
<?xml version="1.0" encoding="utf-8"?> <definitions> <!â --> <service name="SmsService"> <port name="SmsServicePort" binding="tns:SmsServiceBinding"> <soap:address location="http://localhost:80/smsservice.php" /> </port> </service> </definitions>
ããã§ã¯ãã SmsService ããšãããµãŒãã¹ãããããšã瀺ããŠããŸãã ååãšããŠãWSDLãã¡ã€ã«å ã®ãã¹ãŠã®ååã¯ãä»»æã®ååã«å€æŽã§ããŸãã ãããã¯ãŸã£ãã圹å²ãæãããŸããã
ãã®åŸã SmsService WebãµãŒãã¹ã«ã SmsServicePort ããšãããšã³ããªãã€ã³ãïŒãããŒããïŒãããããšãçºè¡šããŸãã ãã®ãšã³ããªãã€ã³ãã§ãã¯ã©ã€ã¢ã³ããããµãŒããŒãžã®ãã¹ãŠã®èŠæ±ãéä¿¡ãããŸãã ãããŠãã address ãèŠçŽ ã§ããªã¯ãšã¹ããåä¿¡ãããã¡ã€ã«ãã³ãã©ãžã®ãªã³ã¯ã瀺ããŸãã
WebãµãŒãã¹ã決å®ãããã®ãšã³ããªãã€ã³ããæå®ãããããµããŒããããŠããæé ãããã«ãã€ã³ãããå¿ èŠããããŸãã
<?xml version="1.0" encoding="utf-8"?> <definitions> <!â - --> <binding name="SmsServiceBinding" type="tns:SmsServicePortType"> <soap:binding style=ârpcâ transport="http://schemas.xmlsoap.org/soap/http" /> <operation name="sendSms"> <soap:operation soapAction="" /> <input> <soap:body use="literal" /> </input> <output> <soap:body use="literal" /> </output> </operation> </binding> <!â --> <service name="SmsService"> <port name="SmsServicePort" binding="tns:SmsServiceBinding"> <soap:address location="http://localhost:80/smsservice.php" /> </port> </service> </definitions>
ãããè¡ãããã«ãã©ã®æäœãã©ã®åœ¢åŒã§åŒã³åºããããããªã¹ãããŸãã ã€ãŸã SmsServicePortããŒãã®å Žåããã€ã³ãã£ã³ã°ã¯SmsServiceBindingãšããååã§å®çŸ©ãããŸãããã®ååã¯rpcåŒã³åºãã¿ã€ããæã¡ããã©ã³ã¹ããŒãïŒãã©ã³ã¹ããŒãïŒãããã³ã«ãšããŠHTTPã䜿çšããŸãã ãããã£ãŠãããã§ã¯HTTPçµç±ã§RPCåŒã³åºããè¡ãããšã瀺ããŸããã ãã®åŸãWebãµãŒãã¹ã§ãµããŒããããæé ïŒ operation ïŒã«ã€ããŠèª¬æããŸãã ã sendSms ããšãã1ã€ã®æé ã®ã¿ããµããŒãããŸãã ãã®æé ã«ããããã°ãããã¡ãã»ãŒãžããµãŒããŒã«éä¿¡ãããŸãïŒ æé ãçºè¡šãããåŸãããŒã¿ãéä¿¡ãã圢åŒãæå®ããå¿ èŠããããŸãã ãã®å Žåãæšæºã®SOAPãšã³ãããŒãã䜿çšãããããšã瀺ãããŠããŸãã
ãã®åŸãããã·ãŒãžã£ãã¡ãã»ãŒãžã«ãã€ã³ãããå¿ èŠããããŸãã
<?xml version="1.0" encoding="utf-8"?> <definitions> <!â --> <portType name="SmsServicePortType"> <operation name="sendSms"> <input message="tns:sendSmsRequest" /> <output message="tns:sendSmsResponse" /> </operation> </portType> <!â - --> <binding name="SmsServiceBinding" type="tns:SmsServicePortType"> <soap:binding style=ârpcâ transport="http://schemas.xmlsoap.org/soap/http" /> <operation name="sendSms"> <soap:operation soapAction="" /> <input> <soap:body use="literal" /> </input> <output> <soap:body use="literal" /> </output> </operation> </binding> <!â --> <service name="SmsService"> <port name="SmsServicePort" binding="tns:SmsServiceBinding"> <soap:address location="http://localhost:80/smsservice.php" /> </port> </service> </definitions>
ãããè¡ãã«ã¯ããã€ã³ãã£ã³ã°ã®ã¿ã€ããã SmsServicePortType ãã§ããããšã瀺ããåãã¿ã€ãåã®ã portType ãèŠçŽ ã§ãããã·ãŒãžã£ãã¡ãã»ãŒãžã«ãã€ã³ãããããšã瀺ããŸãã ãã®ãããçä¿¡ã¡ãã»ãŒãžïŒã¯ã©ã€ã¢ã³ããããµãŒããŒãžïŒã¯ã sendSmsRequest ããšåŒã°ããçºä¿¡ã¡ãã»ãŒãžïŒãµãŒããŒããã¯ã©ã€ã¢ã³ããžïŒã¯ã sendSmsResponse ããšåŒã°ããŸãã WSDLã®ãã¹ãŠã®ååãšåæ§ã«ãçä¿¡ã¡ãã»ãŒãžãšçºä¿¡ã¡ãã»ãŒãžã®ååã¯ä»»æã§ãã
ããã§ãã¡ãã»ãŒãžèªäœãã€ãŸã çä¿¡ããã³çºä¿¡ïŒ
<?xml version="1.0" encoding="utf-8"?> <definitions> <!-- sendSms --> <message name="sendSmsRequest"> <part name="Request" element="tns:Request" /> </message> <message name="sendSmsResponse"> <part name="Response" element="tns:Response" /> </message> <!-- --> <portType name="SmsServicePortType"> <operation name="sendSms"> <input message="tns:sendSmsRequest" /> <output message="tns:sendSmsResponse" /> </operation> </portType> <!-- - --> <binding name="SmsServiceBinding" type="tns:SmsServicePortType"> <soap:binding style=ârpcâ transport="http://schemas.xmlsoap.org/soap/http" /> <operation name="sendSms"> <soap:operation soapAction="" /> <input> <soap:body use="literal" /> </input> <output> <soap:body use="literal" /> </output> </operation> </binding> <!-- --> <service name="SmsService"> <port name="SmsServicePort" binding="tns:SmsServiceBinding"> <soap:address location="http://localhost:80/smsservice.php" /> </port> </service> </definitions>
ãããè¡ãã«ã¯ãããããsendSmsRequestããã³sendSmsResponseãšããååã®ã¡ãã»ãŒãžèŠçŽ ãè¿œå ããŸã ã ãããã«ãããŠããšã³ãããŒãã¯å ¥åã§åä¿¡ãããã¹ãã§ããããã®æ§é ã¯ã ãªã¯ãšã¹ã ãããŒã¿åã«å¯Ÿå¿ããããšã瀺ããŸãã ãã®åŸãããŒã¿ã¿ã€ãã Response ããå«ããšã³ãããŒãããµãŒããŒããè¿ãããŸãã
ããã§å°ãããå¿ èŠããããŸã-ãããã®ã¿ã€ãã®èª¬æãWSDLãã¡ã€ã«ã«è¿œå ããŠãã ããïŒ ãŸããåä¿¡ããŒã¿ãšéä¿¡ããŒã¿ã¯WSDLã§ã©ã®ããã«èšè¿°ãããŠãããšæããŸããïŒ ããªãã¯é·ãéãã¹ãŠãç解ããŠãããXMLã¹ããŒãã®å©ããåããŠãããèªåèªèº«ã«èªã£ããšæããŸãïŒ ãããŠãããªãã¯çµ¶å¯Ÿã«æ£ããã§ãããïŒ
<?xml version="1.0" encoding="utf-8"?> <definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:tns="http://localhost/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" name="SmsWsdl" xmlns="http://schemas.xmlsoap.org/wsdl/"> <types> <xs:schema xmlns:tns="http://schemas.xmlsoap.org/wsdl/" xmlns="http://www.w3.org/2001/XMLSchema" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="http://localhost/"> <complexType name="Message"> <sequence> <element name="phone" type="string" minOccurs="1" maxOccurs="1" /> <element name="text" type="string" minOccurs="1" maxOccurs="1" /> <element name="date" type="dateTime" minOccurs="1" maxOccurs="1" /> <element name="type" type="decimal" minOccurs="1" maxOccurs="1" /> </sequence> </complexType> <complexType name="MessageList"> <sequence> <element minOccurs="1" maxOccurs="unbounded" name="message" type="Message"/> </sequence> </complexType> <element name="Request"> <element name="messageList" type="MessageList" /> </element> <element name="Response"> <complexType> <sequence> <element name="status" type="boolean" /> </sequence> </complexType> </element> </xs:schema> </types> <!-- sendSms --> <message name="sendSmsRequest"> <part name="Request" element="tns:Request" /> </message> <message name="sendSmsResponse"> <part name="Response" element="tns:Response" /> </message> <!-- --> <portType name="SmsServicePortType"> <operation name="sendSms"> <input message="tns:sendSmsRequest" /> <output message="tns:sendSmsResponse" /> </operation> </portType> <!-- - --> <binding name="SmsServiceBinding" type="tns:SmsServicePortType"> <soap:binding style=ârpcâ transport="http://schemas.xmlsoap.org/soap/http" /> <operation name="sendSms"> <soap:operation soapAction="" /> <input> <soap:body use="literal" /> </input> <output> <soap:body use="literal" /> </output> </operation> </binding> <!-- --> <service name="SmsService"> <port name="SmsServicePort" binding="tns:SmsServiceBinding"> <soap:address location="http://localhost:80/smsservice.php" /> </port> </service> </definitions>
ããã§ãšãããããŸãïŒ æåã®WSDLãäœæãããŸããïŒ ãããŠãç§ãã¡ã¯ç®æšãéæããããã®äžæ©ã§ãã
次ã«ãPHPãç¬èªã®åæ£ã¢ããªã±ãŒã·ã§ã³ãéçºããããã«æäŸãããã®ãæ±ããŸãã
5æåã®SOAPãµãŒããŒ
SoapServerçµã¿èŸŒã¿ã¯ã©ã¹ã䜿çšããŠPHPã§SOAPãµãŒããŒãäœæããããšã以åã«æžããŸããã ãã以éã®ãã¹ãŠã®ã¢ã¯ã·ã§ã³ãç§ã®ãã®ãšåæ§ã«çºçããããã«ã¯ãPHPãå°ã調æŽããå¿ èŠããããŸãã ããæ£ç¢ºã«ããã«ã¯ãæ¡åŒµæ©èœãphp-soapããã€ã³ã¹ããŒã«ãããŠããããšã確èªããå¿ èŠããããŸãã WebãµãŒããŒã«é 眮ããæ¹æ³ã¯ãPHPã®å ¬åŒWebãµã€ãã§èªãã®ãæé©ã§ãïŒåèæç®ãåç §ïŒã
ãã¹ãŠãã€ã³ã¹ããŒã«ããŠæ§æãããããã¹ãã£ã³ã°ã®ã«ãŒããã©ã«ããŒã«æ¬¡ã®å 容ã®ãã¡ã€ã«ã smsservice.php ããäœæããå¿ èŠããããŸãã
<?php /** * smsservice.php */ header("Content-Type: text/xml; charset=utf-8"); header('Cache-Control: no-store, no-cache'); header('Expires: '.date('r')); /** * - */ set_include_path(get_include_path() .PATH_SEPARATOR.'classes' .PATH_SEPARATOR.'objects'); /** * */ const CONF_NAME = "config.ini"; /** ** */ function __autoload($class_name){ include $class_name.'.class.php'; } ini_set("soap.wsdl_cache_enabled", "0"); // WSDL- // SOAP- $server = new SoapServer("http://{$_SERVER['HTTP_HOST']}/smsservice.wsdl.php"); // $server->setClass("SoapSmsGateWay"); // $server->handle();
ini_seté¢æ°ã®è¡ã®äžã«ãããã®ã¯ã説æããå¿ èŠããªãããšãé¡ã£ãŠããŸãã ãªããªã ãµãŒããŒããã¯ã©ã€ã¢ã³ãã«éä¿¡ããHTTPããããŒã決å®ããç°å¢ãæ§æãããŸãã ãini_setãã®è¡ã§ã¯ãWSDLãã¡ã€ã«ã®ãã£ãã·ã¥ãç¡å¹ã«ããŠãã¯ã©ã€ã¢ã³ãã§ã®å€æŽãããã«æå¹ã«ãªãããã«ããŸãã
ããã§ãµãŒããŒã«æ¥ãŸããïŒ ã芧ã®ãšãããSOAPãµãŒããŒå šäœã§å¿ èŠãªã®ã¯3è¡ã ãã§ãïŒ æåã®è¡ã§ã¯ãSoapServerãªããžã§ã¯ãã®æ°ããã€ã³ã¹ã¿ã³ã¹ãäœæããWebãµãŒãã¹ã®WSDLèšè¿°ã®ã¢ãã¬ã¹ãã³ã³ã¹ãã©ã¯ã¿ãŒã«æž¡ããŸãã ããã§ãã smsservice.wsdl.php ããšããååã®ãã¡ã€ã«ã®ãã¹ãã£ã³ã°ã®ã«ãŒãã«é 眮ãããããšãããããŸããã 2è¡ç®ã§ã¯ãã¯ã©ã€ã¢ã³ãããåä¿¡ãããšã³ãããŒããåŠçããå¿çãšãšãã«ãšã³ãããŒããè¿ãããã«ãã«ããã¯ã©ã¹ãSOAPãµãŒããŒã«æ瀺ããŸãã ãæ³åã®ãšãããsendSmsã¡ãœããã®ã¿ã説æããã®ã¯ãã®ã¯ã©ã¹ã§ãã 3è¡ç®ã§ã¯ããµãŒããŒãèµ·åããŸãïŒ ããã§ãµãŒããŒã¯æºåå®äºã§ãïŒ ããã§ç§ãã¡å šå¡ãç¥çŠããŸãïŒ
次ã«ãWSDLãã¡ã€ã«ãäœæããå¿ èŠããããŸãã ãããè¡ãã«ã¯ãåã®ã»ã¯ã·ã§ã³ãããã®å 容ãåã«ã³ããŒããããèªåèªèº«ã«èªç±ãäžããŠå°ãããã³ãã¬ãŒãåãããããšãã§ããŸãã
<?php /** * smsservice.wsdl.php */ header("Content-Type: text/xml; charset=utf-8"); echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>"; ?> <definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:tns="http://<?=$_SERVER['HTTP_HOST']?>/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" name="SmsWsdl" xmlns="http://schemas.xmlsoap.org/wsdl/"> <types> <xs:schema elementFormDefault="qualified" xmlns:tns="http://schemas.xmlsoap.org/wsdl/" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://<?=$_SERVER['HTTP_HOST']?>/"> <xs:complexType name="Message"> <xs:sequence> <xs:element name="phone" type="xs:string" minOccurs="1" maxOccurs="1" /> <xs:element name="text" type="xs:string" minOccurs="1" maxOccurs="1" /> <xs:element name="date" type="xs:dateTime" minOccurs="1" maxOccurs="1" /> <xs:element name="type" type="xs:decimal" minOccurs="1" maxOccurs="1" /> </xs:sequence> </xs:complexType> <xs:complexType name="MessageList"> <xs:sequence> <xs:element name="message" type="Message" minOccurs="1" maxOccurs="unbounded" /> </xs:sequence> </xs:complexType> <xs:element name="Request"> <xs:complexType> <xs:sequence> <xs:element name="messageList" type="MessageList" /> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="Response"> <xs:complexType> <xs:sequence> <xs:element name="status" type="xs:boolean" /> </xs:sequence> </xs:complexType> </xs:element> </xs:schema> </types> <!-- sendSms --> <message name="sendSmsRequest"> <part name="Request" element="tns:Request" /> </message> <message name="sendSmsResponse"> <part name="Response" element="tns:Response" /> </message> <!-- --> <portType name="SmsServicePortType"> <operation name="sendSms"> <input message="tns:sendSmsRequest" /> <output message="tns:sendSmsResponse" /> </operation> </portType> <!-- - --> <binding name="SmsServiceBinding" type="tns:SmsServicePortType"> <soap:binding transport="http://schemas.xmlsoap.org/soap/http" /> <operation name="sendSms"> <soap:operation soapAction="" /> <input> <soap:body use="literal" /> </input> <output> <soap:body use="literal" /> </output> </operation> </binding> <!-- --> <service name="SmsService"> <port name="SmsServicePort" binding="tns:SmsServiceBinding"> <soap:address location="http://<?=$_SERVER['HTTP_HOST']?>/smsservice.php" /> </port> </service> </definitions>
ãã®æ®µéã§ã¯ãçµæã®ãµãŒããŒã¯å®å šã«ç§ãã¡ã«åãã¯ãã§ãã å°çãããšã³ãããŒãããã°ã«èšé²ããçä¿¡ããŒã¿ãéãã«åæã§ããŸãã ãµãŒããŒã§äœããåä¿¡ã§ããããã«ããã«ã¯ãã¯ã©ã€ã¢ã³ããå¿ èŠã§ãã ãã£ãŠã¿ãŸãããïŒ
6éäžã®SOAPã¯ã©ã€ã¢ã³ã
ãŸããã¯ã©ã€ã¢ã³ããæžã蟌ããã¡ã€ã«ãäœæããå¿ èŠããããŸãã ãã€ãã®ããã«ããã¹ãã®ã«ãŒãã«äœæããã client.php ããšåŒã³ãå éšã«æ¬¡ã®ããã«èšè¿°ããŸãã
<?php /** * /client.php */ header("Content-Type: text/html; charset=utf-8"); header('Cache-Control: no-store, no-cache'); header('Expires: '.date('r')); /** * - */ set_include_path(get_include_path() .PATH_SEPARATOR.'classes' .PATH_SEPARATOR.'objects'); /** ** */ function __autoload($class_name){ include $class_name.'.class.php'; } ini_set('display_errors', 1); error_reporting(E_ALL & ~E_NOTICE); // class Message{ public $phone; public $text; public $date; public $type; } class MessageList{ public $message; } class Request{ public $messageList; } // $req = new Request(); $req->messageList = new MessageList(); $req->messageList->message = new Message(); $req->messageList->message->phone = '79871234567'; $req->messageList->message->text = ' 1'; $req->messageList->message->date = '2013-07-21T15:00:00.26'; $req->messageList->message->type = 15; $client = new SoapClient( "http://{$_SERVER['HTTP_HOST']}/smsservice.wsdl.php", array( 'soap_version' => SOAP_1_2)); var_dump($client->sendSms($req));
ãªããžã§ã¯ãã«ã€ããŠèª¬æããŸãã WSDLãèšè¿°ãããšãã«ããµãŒããŒã«å ¥ããšã³ãããŒãã®3ã€ã®ãšã³ãã£ãã£ã Request ã MessageList ãããã³Messageãèšè¿°ãããŸããã ãããã£ãŠã Request ã MessageListãããã³Messageã¯ã©ã¹ã¯ãPHPã¹ã¯ãªããã®ãããã®ãšã³ãã£ãã£ãåæ ããŠããŸãã
ãªããžã§ã¯ããå®çŸ©ããã ããµãŒããŒã«éä¿¡ãããªããžã§ã¯ãïŒ $ req ïŒãäœæããå¿ èŠããããŸãã ãã®åŸãç§ãã¡ã®ããã«2ã€ã®æã倧åãªè¡ãæ¥ãŸãïŒ SOAPã¯ã©ã€ã¢ã³ãïŒ ä¿¡ããããªããããããŸããããããã¯ã¯ã©ã€ã¢ã³ããããµãŒããŒãžã®ã¡ãã»ãŒãžã®éä¿¡ãéå§ãããµãŒããŒãã¡ãã»ãŒãžãæ£åžžã«åä¿¡ããŠåŠçã§ããããã«ããã®ã«ååã§ãïŒ æåã®äŸã§ã¯ãSoapClientã¯ã©ã¹ã®ã€ã³ã¹ã¿ã³ã¹ãäœæããWSDLãã¡ã€ã«ã®å Žæã¢ãã¬ã¹ãã³ã³ã¹ãã©ã¯ã¿ãŒã«æž¡ããŸãããã©ã¡ãŒã¿ãŒã§ã¯ãSOAPãããã³ã«ããŒãžã§ã³1.2ã䜿çšããŠäœæ¥ããããšãæ瀺çã«ç€ºããŸãã 次ã®è¡ã§ã¯ã $ clientãªããžã§ã¯ãã®sendSmsã¡ãœãããåŒã³åºããããã«çµæããã©ãŠã¶ãŒã«åºåããŸãã
å®è¡ããŠãæçµçã«åŸããã®ãèŠãŠã¿ãŸãããïŒ
次ã®ãªããžã§ã¯ãããµãŒããŒããè¿ãããŸããïŒ
object(stdClass)[5] public 'status' => boolean true
ãããŠããã¯çŽ æŽãããããªããªã ããã§ããµãŒããŒãæ£åžžã«æ©èœããŠããã ãã§ãªãæ©èœããŠããããšã確å®ã«ããããŸããããã¯ã©ã€ã¢ã³ãã«å€ãè¿ãããšãã§ããŸãïŒ
ããã§ã¯ããµãŒããŒåŽã§æ éã«ä¿æãããã°ãèŠãŠã¿ãŸãããã æåã®éšåã§ã¯ããµãŒããŒã«éãããçããŒã¿ã確èªããŸãã
<?xml version="1.0" encoding="UTF-8"?> <env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:ns1="http://sms-service/"> <env:Body> <ns1:Request> <ns1:messageList> <message> <phone>79871234567</phone> <text> 1</text> <date>2013-07-21T15:00:00.26</date> <type>15</type> </message> </ns1:messageList> </ns1:Request> </env:Body> </env:Envelope>
ãããå°çã§ãã ããã§ãã©ã®ããã«èŠããããããããŸããïŒ ãããã絶ãã圌ãè³è³ããããšã¯ç§ãã¡ã«ãšã£ãŠèå³æ·±ãããšã§ã¯ãªãã®ã§ããã°ãã¡ã€ã«ãããªããžã§ã¯ãããã·ãªã¢ã©ã€ãºãããã¹ãŠãããŸããããã©ããã確èªããŸãããã
object(stdClass)[4] public 'messageList' => object(stdClass)[5] public 'message' => object(stdClass)[6] public 'phone' => string '79871234567' (length=11) public 'text' => string ' 1' (length=37) public 'date' => string '2013-07-21T15:00:00.26' (length=22) public 'type' => string '15' (length=2)
ã芧ã®ãšããããªããžã§ã¯ãã¯æ£ãããã·ãªã¢ã©ã€ãºãããŸãããããã§ç§ãã¡å šå¡ãç¥çŠããããšæããŸãã ãããããã£ãšé¢çœããã®ãåŸ ã£ãŠããŸãïŒ ã€ãŸãã1ã€ã®SMSã¡ãã»ãŒãžã§ã¯ãªãããµãŒããŒå šäœã«ã¯ã©ã€ã¢ã³ããéä¿¡ããŸãïŒããæ£ç¢ºã«ã¯3ã€ïŒã
7è€éãªãªããžã§ã¯ããéä¿¡ããŸã
1ã€ã®ããã±ãŒãžã§å€§éã®ã¡ãã»ãŒãžããµãŒããŒã«è»¢éããæ¹æ³ãèããŠã¿ãŸãããã ããããæãç°¡åãªæ¹æ³ã¯ãmessageListèŠçŽ å ã§é åãæŽçããããšã§ãã ãã£ãŠã¿ãŸãããïŒ
// $req = new Request(); $req->messageList = new MessageList(); $msg1 = new Message(); $msg1->phone = '79871234567'; $msg1->text = ' 1'; $msg1->date = '2013-07-21T15:00:00.26'; $msg1->type = 15; $msg2 = new Message(); $msg2->phone = '79871234567'; $msg2->text = ' 2'; $msg2->date = '2014-08-22T16:01:10'; $msg2->type = 16; $msg3 = new Message(); $msg3->phone = '79871234567'; $msg3->text = ' 3'; $msg3->date = '2014-08-22T16:01:10'; $msg3->type = 17; $req->messageList->message[] = $msg1; $req->messageList->message[] = $msg2; $req->messageList->message[] = $msg3;
ç§ãã¡ã®ãã°ã¯ã次ã®ããã±ãŒãžãã¯ã©ã€ã¢ã³ãããæ¥ããšèšã£ãŠããŸãïŒ
<?xml version="1.0" encoding="UTF-8"?> <env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:enc="http://www.w3.org/2003/05/soap-encoding" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="http://sms-service/"> <env:Body> <ns1:Request> <ns1:messageList> <message> <SOAP-ENC:Struct> <phone>79871234567</phone> <text> 1</text> <date>2013-07-21T15:00:00.26</date> <type>15</type> </SOAP-ENC:Struct> <SOAP-ENC:Struct> <phone>79871234567</phone> <text> 2</text> <date>2014-08-22T16:01:10</date> <type>16</type> </SOAP-ENC:Struct> <SOAP-ENC:Struct> <phone>79871234567</phone> <text> 3</text> <date>2014-08-22T16:01:10</date> <type>17</type> </SOAP-ENC:Struct> </message> </ns1:messageList> </ns1:Request> </env:Body> </env:Envelope>
, ? , .. , , . , sms- XML , â message , Struct . sendSms :
object(stdClass)[6] public 'messageList' => object(stdClass)[7] public 'message' => object(stdClass)[8] public 'Struct' => array (size=3) 0 => object(stdClass)[9] public 'phone' => string '79871234567' (length=11) public 'text' => string ' 1' (length=37) public 'date' => string '2013-07-21T15:00:00.26' (length=22) public 'type' => string '15' (length=2) 1 => object(stdClass)[10] public 'phone' => string '79871234567' (length=11) public 'text' => string ' 2' (length=37) public 'date' => string '2014-08-22T16:01:10' (length=19) public 'type' => string '16' (length=2) 2 => object(stdClass)[11] public 'phone' => string '79871234567' (length=11) public 'text' => string ' 3' (length=37) public 'date' => string '2014-08-22T16:01:10' (length=19) public 'type' => string '17' (length=2)
? , â « ?». :
$req->messageList->message = (object)$req->messageList->message;
, :
<?xml version="1.0" encoding="UTF-8"?> <env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:ns1="http://sms-service/"> <env:Body> <ns1:Request> <ns1:messageList> <message> <BOGUS> <phone>79871234567</phone> <text> 1</text> <date>2013-07-21T15:00:00.26</date> <type>15</type> </BOGUS> <BOGUS> <phone>79871234567</phone> <text> 2</text> <date>2014-08-22T16:01:10</date> <type>16</type> </BOGUS> <BOGUS> <phone>79871234567</phone> <text> 3</text> <date>2014-08-22T16:01:10</date> <type>17</type> </BOGUS> </message> </ns1:messageList> </ns1:Request> </env:Body> </env:Envelope>
sendSms :
object(stdClass)[7] public 'messageList' => object(stdClass)[8] public 'message' => object(stdClass)[9] public 'BOGUS' => array (size=3) 0 => object(stdClass)[10] public 'phone' => string '79871234567' (length=11) public 'text' => string ' 1' (length=37) public 'date' => string '2013-07-21T15:00:00.26' (length=22) public 'type' => string '15' (length=2) 1 => object(stdClass)[11] public 'phone' => string '79871234567' (length=11) public 'text' => string ' 2' (length=37) public 'date' => string '2014-08-22T16:01:10' (length=19) public 'type' => string '16' (length=2) 2 => object(stdClass)[12] public 'phone' => string '79871234567' (length=11) public 'text' => string ' 3' (length=37) public 'date' => string '2014-08-22T16:01:10' (length=19) public 'type' => string '17' (length=2)
, « â » (). BOGUS , Struct â ! , message . , . , â . , , message BOGUS ! :
// $req = new Request(); $msg1 = new Message(); $msg1->phone = '79871234567'; $msg1->text = ' 1'; $msg1->date = '2013-07-21T15:00:00.26'; $msg1->type = 15; $msg2 = new Message(); $msg2->phone = '79871234567'; $msg2->text = ' 2'; $msg2->date = '2014-08-22T16:01:10'; $msg2->type = 16; $msg3 = new Message(); $msg3->phone = '79871234567'; $msg3->text = ' 3'; $msg3->date = '2014-08-22T16:01:10'; $msg3->type = 17; $req->messageList[] = $msg1; $req->messageList[] = $msg2; $req->messageList[] = $msg3; $req->messageList = (object)$req->messageList;
? :
<?xml version="1.0" encoding="UTF-8"?> <env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:ns1="http://sms-service/"> <env:Body> <ns1:Request> <ns1:messageList> <BOGUS> <phone>79871234567</phone> <text> 1</text> <date>2013-07-21T15:00:00.26</date> <type>15</type> </BOGUS> <BOGUS> <phone>79871234567</phone> <text> 2</text> <date>2014-08-22T16:01:10</date> <type>16</type> </BOGUS> <BOGUS> <phone>79871234567</phone> <text> 3</text> <date>2014-08-22T16:01:10</date> <type>17</type> </BOGUS> </ns1:messageList> </ns1:Request> </env:Body> </env:Envelope>
ã¯ããå¥è·¡ã¯èµ·ãããŸããã§ããïŒããŒã¬ã¹ -åãŠãªãïŒãã®å Žåã«sendSmsã«å°éãããªããžã§ã¯ãã¯æ¬¡ã®ããã«ãªããŸãã
object(stdClass)[6] public 'messageList' => object(stdClass)[7] public 'BOGUS' => array (size=3) 0 => object(stdClass)[8] public 'phone' => string '79871234567' (length=11) public 'text' => string ' 1' (length=37) public 'date' => string '2013-07-21T15:00:00.26' (length=22) public 'type' => string '15' (length=2) 1 => object(stdClass)[9] public 'phone' => string '79871234567' (length=11) public 'text' => string ' 2' (length=37) public 'date' => string '2014-08-22T16:01:10' (length=19) public 'type' => string '16' (length=2) 2 => object(stdClass)[10] public 'phone' => string '79871234567' (length=11) public 'text' => string ' 3' (length=37) public 'date' => string '2014-08-22T16:01:10' (length=19) public 'type' => string '17' (length=2)
圌ããèšãããã«-ãã»ãŒãïŒãã®ïŒå°ãæ²ããïŒã¡ã¢ã§ãç§ã¯éãã«ãŸãšããŠãèªåã®ããã«çµè«ãåºãããšãææ¡ããŸãã
8çµè«
ã€ãã«ããã«æ¥ãŸããïŒä»äœãã§ãããã決ããŸãããïŒ
- WebãµãŒãã¹ã«å¿ èŠãªWSDLãã¡ã€ã«ãäœæã§ããŸãã
- åé¡ãªããSOAPãä»ããŠãµãŒããŒãšéä¿¡ã§ããç¬èªã®ã¯ã©ã€ã¢ã³ããäœæã§ããŸãã
- SOAPãä»ããŠå€éšãšéä¿¡ããç¬èªââã®ãµãŒããŒãäœæã§ããŸãã
- ã¯ã©ã€ã¢ã³ãããåãã¿ã€ãã®ãªããžã§ã¯ãã®é åããµãŒããŒã«éä¿¡ã§ããŸãïŒããã€ãã®å¶éããããŸãïŒã
, :
- SoapClient XML;
- XML Struct ;
- XML BOGUS ;
- BOGUS Struct - , ( namespace' XML );
- , SoapServer XML- (, ).
9
- www.w3.org/XML/Schema â XML-
- www.w3.org/TR/soap â SOAP
- ru.wikipedia.org/wiki/Remote_Procedure_Call â RPC
- ru.wikipedia.org/wiki/REST â REST
- ru.wikipedia.org/wiki/XML â XML
- ru.wikipedia.org/wiki/XML_Schema â XML-
- ru.wikipedia.org/wiki/WSDL â WSDL
- www.php.net/manual/ru/book.soap.php â SOAP PHP
- github.com/hats/soap-sms-service â
PS SOAP , SoapServer SoapClient. , SOAP PHP, , :)
PPS Mikaz
ArrayObject SoapVar .
:
$req = new Request(); $req->messageList = new \ArrayObject(); $msg1 = new Message(); $msg1->phone = '79871234567'; $msg1->text = ' 1'; $msg1->date = '2013-07-21T15:00:00.26'; $msg1->type = 15; $soap_msg1 = new \SoapVar($msg1, SOAP_ENC_OBJECT, null, null, 'Message'); $msg2 = new Message(); $msg2->phone = '79871234567'; $msg2->text = ' 2'; $msg2->date = '2014-08-22T16:01:10'; $msg2->type = 16; $soap_msg2 = new \SoapVar($msg2, SOAP_ENC_OBJECT, null, null, 'Message'); $msg3 = new Message(); $msg3->phone = '79871234567'; $msg3->text = ' 3'; $msg3->date = '2014-08-22T16:01:10'; $msg3->type = 17; $soap_msg3 = new \SoapVar($msg3, SOAP_ENC_OBJECT, null, null, 'Message'); $req->messageList->append($soap_msg1); $req->messageList->append($soap_msg2); $req->messageList->append($soap_msg3);
$req = new Request(); $req->messageList = new \ArrayObject(); $msg1 = new Message(); $msg1->phone = '79871234567'; $msg1->text = ' 1'; $msg1->date = '2013-07-21T15:00:00.26'; $msg1->type = 15; $soap_msg1 = new \SoapVar($msg1, SOAP_ENC_OBJECT, null, null, 'Message'); $msg2 = new Message(); $msg2->phone = '79871234567'; $msg2->text = ' 2'; $msg2->date = '2014-08-22T16:01:10'; $msg2->type = 16; $soap_msg2 = new \SoapVar($msg2, SOAP_ENC_OBJECT, null, null, 'Message'); $msg3 = new Message(); $msg3->phone = '79871234567'; $msg3->text = ' 3'; $msg3->date = '2014-08-22T16:01:10'; $msg3->type = 17; $soap_msg3 = new \SoapVar($msg3, SOAP_ENC_OBJECT, null, null, 'Message'); $req->messageList->append($soap_msg1); $req->messageList->append($soap_msg2); $req->messageList->append($soap_msg3);