简体   繁体   中英

Calling an ASP.Net web service using php

I'm trying to consume an ASP.Net web service using a php client. The php method recieves one double parameter and returns a value based on it.

This is my client.php code:

$wsdl_url = "url";
$client = new SoapClient($wsdl_url);
$params = array('value'=>200);
$response  = $client->kilogramsToPounds($params);
echo "<pre>";
var_dump($response);
echo "</pre>";
echo "$response->kilogramsToPoundsResult";

When I run the code I get the following error:

Fatal error: Uncaught SoapFault exception: [Client] SOAP-ERROR: Encoding: object has no 'kilograms' property in /var/www/student/oce1bct/CourseWork/Scenario3/TestFolder/convertersTest.php:23 Stack trace: #0 /var/www/student/oce1bct/CourseWork/Scenario3/TestFolder/convertersTest.php(23): SoapClient->__call('kilogramsToPoun...', Array) #1 /var/www/student/oce1bct/CourseWork/Scenario3/TestFolder/convertersTest.php(23): SoapClient->kilogramsToPounds(Array) #2 {main} thrown in /var/www/student/oce1bct/CourseWork/Scenario3/TestFolder/convertersTest.php on line 23 

The excerpt from the web service to be consumed is also below

[WebMethod]

public double kilogramsToPounds(double kilograms)

{

double pounds = 0;

pounds = kilograms * 2.204;

return pounds;

}

I am 90% certain that I am not passing the values to the web service call correctly but have been unable to rectify the problem. Any help would be appreciated. Thanks.

Instead of this

$params = array('value'=>200); 

use

$params = array('kilograms'=>200); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM