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

PHP method to call .Net's WebService asmx file through soap

墨辰丷
墨辰丷Original
2018-05-25 13:51:392060browse

This article mainly introduces the WebService asmx file of php calling .Net through soap, and analyzes the calling skills of php using soap to implement the WebService interface in the form of examples. Friends in need can refer to the examples of this article

It describes how PHP can call .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, and the C# call passed. Now I need to test the call of the PHP version to it. After various explorations, 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(" http://192.168.3.178:8080/ChkWelePsw.asmx?WSDL");
//本行测试不可行 $client = new SoapClient(" http://192.168.3.178: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,看看是什么类型。
?>

Note that when calling After a certain method, its soap object will automatically generate a Result method to facilitate the display of the call result. For example, the "ChkWele" method of the WebService on the called side above,

The calling side has the corresponding "ChkWeleResult" "method.

Things to pay attention to in some .NET webservices

/*
 *  <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;
}

The above is the entire content of this article, I hope it will be helpful to everyone Learning helps.


Related recommendations:

PHP Class SoapClient not found handling method

php5 .5.12 Debugging SOAP error message

PHP Class SoapClient not found How to solve

The above is the detailed content of PHP method to call .Net's WebService asmx file through soap. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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