Home >Backend Development >PHP Tutorial >PHP implements soap to call .Net's WebService asmx file
The example of this article describes the implementation of php calling .Net's WebService asmx file through soap. Share it with everyone for your reference. The details are as follows:
Recently, I helped a colleague test the WebService interface written in .net. The C# call passed. Now I need to test the call of the PHP version. After various For exploration, the related process of calling webservice by PHP is as follows:
1. Open PHP related extensions:
Find the configuration file php.ini file and open the following extension
extension = php_soap.dll extension = php_curl.dll extension = php_openssl.dll
2.php code is as follows:
<?php header("content-type:text/html;charset=utf-8"); $client = new SoapClient(" //m.sbmmt.com/:8080/ChkWelePsw.asmx?WSDL"); //本行测试不可行 $client = new SoapClient(" //m.sbmmt.com/:8080/chkwelepsw.asmx?WSDL/ChkWele?username=test3&psw=123"); //参数这样传递 先包装一下 $param = array('username'=>'test3','psw'=>'123'); //调用必须用__soapCall $p = $client->__soapCall('ChkWele',array('parameters' => $param)); print_r($p->ChkWeleResult); //这里先输出一下变量$p,看看是什么类型。 ?>
Note, After php calls a method, its soap object will automatically generate a Result method to facilitate the display of the call result, such as the "ChkWele" method of the WebService on the called side above,
The calling side has the corresponding The "ChkWeleResult" method.
.NET part webservice should pay attention to things
/* * <system.web>在这个节点中加入如下内容 <webServices> <protocols> <add name="HttpSoap"/> <add name="HttpPost"/> <add name="HttpGet"/> <add name="Documentation"/> </protocols> </webServices> */ [WebMethod(Description = "This......", EnableSession = false)] public string ChkWele(string username, string psw) { string ret = ""; return ret; }
For more articles about php implementing soap to call .Net's WebService asmx file, please pay attention to the PHP Chinese website!