Home > Backend Development > PHP Tutorial > PHP implements soap to call .Net's WebService asmx file

PHP implements soap to call .Net's WebService asmx file

高洛峰
Release: 2023-03-06 08:20:02
Original
1594 people have browsed it

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
Copy after login

2.php code is as follows:

<?php
header("content-type:text/html;charset=utf-8");
$client = new SoapClient(" http://www.php.cn/:8080/ChkWelePsw.asmx?WSDL");
//本行测试不可行 $client = new SoapClient(" http://www.php.cn/:8080/chkwelepsw.asmx?WSDL/ChkWele?username=test3&psw=123");
//参数这样传递 先包装一下
$param = array(&#39;username&#39;=>&#39;test3&#39;,&#39;psw&#39;=>&#39;123&#39;);
//调用必须用__soapCall
$p = $client->__soapCall(&#39;ChkWele&#39;,array(&#39;parameters&#39; => $param));
print_r($p->ChkWeleResult); //这里先输出一下变量$p,看看是什么类型。
?>
Copy after login

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;
}
Copy after login

For more articles about php implementing soap to call .Net's WebService asmx file, please pay attention to the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template