[RESOLVED] invoke WCF method using PHP
I made a WCF service using C#. My colleague wants to consume this service.
I my service I have to methods, 'Test' wich returns a simple string and 'TestString2', which needs a parameter and mulitplies this value bij 2 and returns this as a string
We're using the next code to invoke a the Test method
Code:
//trying to connect
echo("<br/>Trying to connect<br />");
$client = new SoapClient($SOAP_BASE);
$data = $client->Test();
var_dump($data);
This works fine and $data has the string that is returned.
But when we try to call the method with parameter we get an exception:
Code:
//trying to connect
echo("<br/>Trying to connect<br />");
$client = new SoapClient($SOAP_BASE);
$data = $client->TestString2(10);
var_dump($data);
Fatal error: Uncaught SoapFault exception: [Client] Function ("TestString2") is not a valid method for this service in <url>/test.php:29 Stack trace: #0 [internal function]: SoapClient->__call('TestString2', Array) #1 <url>/test.php(29): SoapClient->TestString2(Array) #2 {main} thrown in <url>/test.php on line 29
It looks like it needs an array as parameter
Code:
//trying to connect
echo("<br/>Trying to connect<br />");
$client = new SoapClient($SOAP_BASE);
//parameter name is 'i'
$params= array("i"=> 10);
$data = $client->TestString2($params);
var_dump($data);
But it won't work, anyone any idea????
Re: invoke WCF method using PHP
Since when did the SoapClient class obtain a method named TestString2?
Re: invoke WCF method using PHP
'Test' and 'TestString2' are the 2 methods in my WCF service
Code:
[OperationContract]
string Test();
[OperationContract]
string TestString2(int i);
And method 'Test' works just fine
Re: invoke WCF method using PHP
have u tried __soapCall function? I think it will resolve ur issue
Re: invoke WCF method using PHP
we tried the next:
Code:
$testarray = array("i"=> "9");
$data = $client->__soapCall("Test",$testarray);
Works just fine. When I vardump $data:
object(stdClass)#2 (1) { ["TestResult"]=> string(11) "Hello there"
But again having problems with the method with parameter
Code:
$testarray = array("i"=> "9");
$data = $client->__soapCall("TestString2",$testarray);
Now, it does not give any error, but the result that is recieved is empty. When I now vardump data:
object(stdClass)#2 (0) { }
Re: invoke WCF method using PHP
We don't know why, but after the weekend we are a step closer of getting it to work.
The method with parameter returns now "0", and it is supposed to return "18" (9 x 2). After debugging my C# project, the method recieves as parameter the value 0, but in the $testarray we set the value to 9.
Why does the method recieve the wrong paramater value?
Re: invoke WCF method using PHP
Are you sure this is a PHP problem and not something in the C# service? If it is part of C#, then I can move this thread to C# for you. Just let me know.
Re: invoke WCF method using PHP
Yes it was a PHP problem. We just solved it
Code:
$parameters = array("i"=> "0");
$data = $client->__soapCall("TestString2", array('parameters' => $parameters));
Thus, the parameters needs to be in array, and that array again needs to be in an array. Makes sense...