Explanation of PHP link WEBSERVICE class_php tutorial

Source: Internet
Author: User
A detailed explanation of the WEBSERVICE class linked to PHP. PHP link WEBSERVICE code instance: communication class starts classwebserv {webservice address parameter var $ webaddarray (publclient. asmx? Wsdl, clientClient. asmx? Wsdl, bann); call

PHP links to a web service code instance:

  1. // Start the communication class
  2. Class webserv
  3. {
  4. // Webservice address parameters
  5. Var $ webadd = array (
  6. "Publ" =>"Client. asmx? Wsdl ",
  7. "Client" =>"Client. asmx? Wsdl ",
  8. "Bann" =>"");
  9. // Call webservice
  10. Function soap ($ class, $ function, $ par = array ()){
  11. // Link
  12. Web service
  13. $ Client = new SoapClient ($ this->Webadd [$ class]);
  14. $ Require = $ client->$ Function ($ par );
  15. // Call information debug
  16. If (is_soap_fault ($ require )){
  17. Echo "remote interface". $ function. "failed to call! ";
  18. Exit ();
  19. }
  20. // Obtain the returned value
  21. $ Function_result = $ function. "Result ";
  22. $ Str = $ require->$ Function_result;
  23. // Parse XML
  24. $ Row = @ simplexml_load_string ($ str );
  25. // If XML parsing is not supported, return directly
  26. If ($ row = false ){
  27. If (is_string ($ str )){
  28. Return $ str;
  29. } Else {
  30. $ Require = (get_object_vars ($ str ));
  31. $ Str = $ require ['string'];
  32. Return $ str;
  33. }
  34. }
  35. // Convert the result to an array
  36. $ Row_arr = get_object_vars ($ row );
  37. Print_r ($ row_arr); exit ();
  38. $ Row_return = $ row_arr ['table'];
  39. // Determine whether multiple feedback records exist.
  40. If (is_array ($ row_arr ['table']) {
  41. Foreach ($ row_return as $ key =>$ Vlaues ){
  42. $ Rows [$ key] = get_object_vars ($ vlaues );
  43. }
  44. } Else {
  45. $ Rows [0] = get_object_vars ($ row_arr ['table']);
  46. }
  47. // Communication record
  48. // $ This->Soap_log ($ class, $ function, $ par, $ rows );
  49. Return $ rows;
  50. }
  51. // Interface communication record
  52. Function soap_log ($ class, $ function, $ in, $ out ){
  53. $ Log = date ("Y-m-d H: I: s ");
  54. $ Log. = "". $ class ."->". $ Function." input :";
  55. $ Input = "";
  56. If ($ in! = Array ()){
  57. Foreach ($ in as $ key =>$ Vlaue ){
  58. $ Input. = $ key. "=". $ vlaue;
  59. }
  60. $ Log. = $ input. "output:". var_export ($ rows). "n ";
  61. }
  62. }
  63. }


The above is the communication content. Easy to use

Include PHP links to web service files

 
 
  1. <?
  2. Include "./webserv. class. php ";
  3. $ Webserv = new webserv;
  4. // Here is the parameter passed by the call method.
  5. $ A = array ("aa" => "aaaa ");
  6. Print_r ($ webser-> soap ("function_name", $ ));
  7. ?>

The above describes how to use PHP to link the web service class.


Consumer SERVICE Code instance: // The communication class starts classwebserv {// webservice address parameter var $ webadd = array (publ = client. asmx? Wsdl, client = Client. asmx? Wsdl, bann =); // call...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.