Daniel
Daniel

Reputation: 2500

PHP SoapClient-exception, what am I doing wrong?

I´ve recently started looking a web service calls using PHP. I can´t get the following rather simple snippet to work, instead the web service returns an exception.

<?php
$client = new SoapClient("http://www.webservicex.net/geoipservice.asmx?wsdl");
print($client->__soapCall("GetGeoIP", array('IP' => '83.251.30.62')));
?>

I´ve also tried the simpler $client->GetGeoIP('83.251.30.62'); but they both yield the same result.

Is there something wrong with my code? Exception below:

Fatal error: Uncaught SoapFault exception: [soap:Server] 
System.Web.Services.Protocols.SoapException: Server was unable to process request. --->     System.ArgumentNullException: Value cannot be null. 
Parameter name: input at System.Text.RegularExpressions.Regex.IsMatch(String input) at 
WebserviceX.Service.Adapter.IPAdapter.CheckIP(String IP) at 
WebserviceX.Service.GeoIPService.GetGeoIP(String IPAddress) --- End of inner exception 
stack trace --- in C:\Program Files (x86)\Apache Software 
Foundation\Apache2.2\htdocs\isolda\test.php:16 Stack trace: #0 C:\Program Files 
(x86)\Apache Software Foundation\Apache2.2\htdocs\isolda\test.php(16): SoapClient-
>__soapCall('GetGeoIP', Array) #1 {main} thrown in C:\Program Files (x86)\Apache 
Software Foundation\Apache2.2\htdocs\isolda\test.php on line 16

Upvotes: 0

Views: 3961

Answers (1)

Alon Adler
Alon Adler

Reputation: 4024

You should write "IPAddress" instead of 'IP' (Inside the array) and it will work.

$client = new SoapClient("http://www.webservicex.net/geoipservice.asmx?wsdl"); 

$result = $client->GetGeoIP(array("IPAddress" => "83.251.30.62")); //change was made here

echo $result->GetGeoIPResult->CountryName;

Upvotes: 2

Related Questions