Several methods of PHP calling WebService

Source: Internet
Author: User
Tags soap wsdl

Text: Several methods of PHP calling WebService

1.WSDL mode:

$soap = new SoapClient ("http://192.168.6.69:8899/Service1.asmx?wsdl"), $result 2 = $soap->helloworld (' MyName ' + ' aaa ', ' youname ' = ' bbb ');p Rint_r ($result 2);


2.NON-WSDL mode:

2.1 Passing parameters using Soapparam:

$soap = new SoapClient (' null,array ' = ' http://192.168.6.72:8036/Service1.asmx ', ' uri ' = '/' tempuri.org/'); $result 2 = $soap->__soapcall ("HelloWorld", Array (New Soapparam ("AAA", "MyName"), New Soapparam (" BBB "," Youname ")),//array (New Soapparam (" AAA "," Ns1:myname "), New Soapparam (" BBB "," Ns1:youname "), Array (' SOAPAction ' = ' Http://tempuri.org/HelloWorld '));p Rint_r ($result 2);

2.2 Passing parameters using Soapvar

$ns = ' http://tempuri.org/'; $soap = new SoapClient (Null,array (' location ' = ' http://192.168.6.72:8036/ Service1.asmx ', ' uri ' = $ns)); $result 2 = $soap->__soapcall ("HelloWorld", Array (New Soapvar ("AAA", xsd_string, NULL, $ns, "MyName", $ns), New Soapvar ("gbbb", xsd_string, NULL, $ns, "Youname", $ns)), Array (' soapaction ' = Tempuri.org/helloworld '));p Rint_r ($result 2);


3. Add a security header

$soap = new SoapClient (' null,array ' = ' http://192.168.6.47/onvif/device_service ', ' uri ' = '/' www.onvif.org/ver10/device/wsdl/'));//ws$ns_wsse = "http://docs.oasis-open.org/wss/2004/01/ Oasis-200401-wss-wssecurity-secext-1.0.xsd ";//ws-security namespace$ns_wsu =" http://docs.oasis-open.org/wss/2004 /01/oasis-200401-wss-wssecurity-utility-1.0.xsd ";//ws-security Namespace$usert = new SoapVar (' admin ', XSD_STRING, NULL, $ns _wsse, NULL, $ns _wsse), $passwT = new Soapvar (' nnyze7od81kd8qrs4tumze/2cus= ', xsd_string, NULL, $ns _wsse, NULL, $  Ns_wsse); $createdT = new Soapvar (Time (), xsd_datetime, NULL, $ns _WSU, NULL, $ns _WSU); class UsernameT1 {private $Username; Name must is identical to corresponding XML tag in SOAP headerprivate $Password;  Name must is identical to corresponding XML tag in SOAP header private $Created;     function __construct ($username, $password, $created) {$this->username= $username;     $this->password= $password;    $this->created= $created; }} $tmp = new UsernameT1 ($userT, $passwT, $createdT); $uuT = new Soapvar ($tmp, Soap_enc_object, NULL, $ns _wsse, ' Usernametoke  N ', $ns _wsse); class UserNameT2 {private $UsernameToken; Name must bes identical to corresponding XML tag in SOAP headerfunction __construct ($innerVal) {$this->usernametoken = $innerVal;}} $tmp = new UsernameT2 ($uuT), $userToken = new Soapvar ($tmp, Soap_enc_object, NULL, $ns _wsse, ' UsernameToken ', $ns _wsse); $s  Echeadervalue=new Soapvar ($userToken, Soap_enc_object, NULL, $ns _wsse, ' Security ', $ns _wsse); $secHeader = new SoapHeader ($ns _wsse, ' Security ', $secHeaderValue); $result 2 = $soap->__soapcall (" Getdeviceinformation ", array (), NULL, $secHeader); Echo $result 2;




Several methods of PHP calling WebService

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.