Search code examples
phpweb-servicesasmx

Call asp.net web service from PHP with multiple parameters


I'm using a method using SoapClient class in a php page to call a web service in an asp.net site.

Here is the php code.

$client = new SoapClient("http://testurl/Test.asmx?WSDL");

$params = array( 'Param1'  => 'Hello', 
                'Param2' => 'World!');

$result = $client->TestMethod($params)->TestMethodResult;

echo $result;

The problem is, I'm only getting the first parameter (Param1) "Hello" back and seems like there is an issue with Param2. Here is the asp.net method.

[WebMethod]
public string TestMethod(string Param1, string Param2) 
{
    return Param1 + " " +  Param2; 
}

What am I missing to get Hello World! in the response?


Solution

  • Try like this:

    $client = new SoapClient("http://testurl/Test.asmx?WSDL");
    $params->Param1 = 'Hello';
    $params->Param2 = 'World!';    
    $result = $client->TestMethod($params)->TestMethodResult;