-
February 4th, 2009, 11:19 AM
#1
[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????
-
February 4th, 2009, 01:03 PM
#2
Re: invoke WCF method using PHP
Since when did the SoapClient class obtain a method named TestString2?
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
February 5th, 2009, 03:15 AM
#3
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
-
February 6th, 2009, 06:58 AM
#4
Re: invoke WCF method using PHP
have u tried __soapCall function? I think it will resolve ur issue
Muhammad Waqas Badar
-
February 6th, 2009, 10:28 AM
#5
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) { }
-
February 9th, 2009, 07:57 AM
#6
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?
-
February 9th, 2009, 10:48 AM
#7
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.
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
February 9th, 2009, 10:54 AM
#8
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...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|