Home  >  Article  >  Backend Development  >  Analysis of key points using PHP's built-in SOAP_PHP tutorial

Analysis of key points using PHP's built-in SOAP_PHP tutorial

WBOY
WBOYOriginal
2016-07-15 13:33:25894browse

For those who are new to

Since the text is only intended to talk about the usage of the client, you must first find some servers that can be used directly. Xmethods provides some interesting options , select the Map IP Address to Country service here, the function is very simple, it is to provide an IP address and then return the country name.

First create a client instance:

$client = new SoapClient
('http://www.ecubicle.net/
iptocountry.asmx?wsdl',
array('trace' =
> ; true));

By setting trace to true, we can later use __getLastRequest, __getLastRequestHeaders, __getLastResponse, __getLastResponseHeaders and other methods to get some information, in This information is useful during program debugging, but you do not need to use this parameter when the program is put into use. In addition to the trace parameters, you can also set the login and password parameters to implement the HTTP authentication function. In addition, there are many parameters, you can refer to the official documentation.

After creating the previous $client instance, we can first take a look at the methods provided by the service:

print_r($client->__getFunctions());

The information details of the service method can be checked by yourself in wsdl. Let's see how PHP's built-in SOAP calls an actual method, $ip='64.156.132.140′:

<ol class="dp-xml">
<li class="alt"><span><span>$</span><span class="attribute">result</span><span> = $client-</span><span class="tag">></span><span>__soapCall<br>(’FindCountryAsString’, array<br>(’FindCountryAsString’ =</span><span class="tag">></span><span> <br>array(’V4IPAddress’ =</span><span class="tag">></span><span> $ip)));  </span></span></li>
<li>
<span>print_r($result-</span><span class="tag">><br></span><span>FindCountryAsStringResult); </span>
</li>
</ol>

It can also be called like this:

<ol class="dp-xml">
<li class="alt"><span><span>$</span><span class="attribute">result</span><span> = $client-</span><span class="tag">><br></span><span>FindCountryAsString(array<br>(’V4IPAddress’ =</span><span class="tag">></span><span> $ip));  </span></span></li>
<li>
<span>print_r($result-</span><span class="tag">><br></span><span>FindCountryAsStringResult); </span>
</li>
</ol>

PHP built-in SOAP can also be called like this:

<ol class="dp-xml">
<li class="alt"><span><span>$</span><span class="attribute">params</span><span> = </span><span class="attribute-value">new</span><span> SoapParam(array(’V4IPAddress’ <br>=</span><span class="tag">></span><span> $ip), ‘FindCountryAsStringSoapIn’);  </span></span></li>
<li>
<span>$</span><span class="attribute">result</span><span> = $client-</span><span class="tag">></span><span>__soapCall<br>(’FindCountryAsString’, array($params));  </span>
</li>
<li class="alt">
<span>print_r($result-</span><span class="tag">></span><span>FindCountryAsStringResult); </span>
</li>
</ol>

It can also be called like this:

<ol class="dp-xml">
<li class="alt"><span><span>$</span><span class="attribute">params</span><span> = </span><span class="attribute-value">new</span><span> SoapParam(array(’V4IPAddress’ <br>=</span><span class="tag">></span><span> $ip), ‘FindCountryAsStringSoapIn’);  </span></span></li>
<li>
<span>$</span><span class="attribute">result</span><span> = $client-</span><span class="tag">></span><span>FindCountryAsString($params);  </span>
</li>
<li class="alt">
<span>print_r($result-</span><span class="tag">></span><span>FindCountryAsStringResult); </span>
</li>
</ol>

When using PHP’s built-in SOAP, it’s a bit hard to explain how parameters are passed. This requires studying the wsdl description document, but reading wsdl is really a boring thing, so I think you You can first take a rough look at the wsdl, and then try to pass the parameters based on your feeling, and cooperate with trace debugging. Generally speaking, you can find the correct transmission method after a few tries. If it still doesn't work, then use the information provided by __getLastRequest, __getLastRequestHeaders and other methods. Study carefully with the wsdl description document.


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/446064.htmlTechArticleFor those who are new to it, since the text only intends to talk about the usage of the client, you must first find some servers that can be used directly. , Xmethods provides some interesting options, here choose Map...
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