I’m trying to make an PHP Client for an WCF Webservice. But i get some Errors when i call the functions of the service.
App.config
<system.serviceModel>
<services>
<service behaviorConfiguration="MyServiceBehavior"
name="GSC.Wcf.Services.CartService">
<endpoint address=""
binding="basicHttpBinding"
contract="GSC.Wcf.Services.ICartService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding"
contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8731/CartService" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MyServiceBehavior">
<serviceMetadata httpGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>
Function:
> public int Addiere(int a, int b)
{
return a + b;
}
PHP-Request:
> $client = new SoapClient("http://localhost:8731/CartService?wsdl");
>
> $result = $client->Addiere(2,4);
for these function i get an Error like that:
“Uncaught SoapFault exception: [a:DeserializationFailed] the
Formatierer formatter has realeased an exception during the
deserilization of the message: Failed to deserialize the request body
of the message is intended for operation “Addiere”. The end-element
“Body” aus Namespace “http://schemas.xmlsoap.org/soap/envelope/” was
expected. Found was the element “param1″ of Namespace””.
In German:
Fatal error: Uncaught SoapFault exception: [a:DeserializationFailed]
Der Formatierer hat beim Deserialisieren der Nachricht eine Ausnahme
ausgelöst: Fehler beim Deserialisieren des Textkörpers der
Anforderungsnachricht für Vorgang “Addiere”. Es wurde das Endelement
“Body” aus Namespace “http://schemas.xmlsoap.org/soap/envelope/”
erwartet. Gefunden wurde “Element “param1” aus Namespace “””. Zeile 2,
Position 148. in C:\xampp\htdocs\TestClient\Client.php:6 Stack trace:
0 C:\xampp\htdocs\TestClient\Client.php(6): SoapClient->__call(‘Addiere’, Array) #1
C:\xampp\htdocs\TestClient\Client.php(6): SoapClient->Addiere(2, 4) #2
{main} thrown in C:\xampp\htdocs\TestClient\Client.php on line 6
But this function is working:
C#
> public string Message()
{
return "WORD";
}
PHP
> $result = $client->Message();
var_dump($result);
result
object(stdClass)#2 (1) { [“MessageResult”]=> string(4) “WORD” } WORD
the only problem is that the return type is no string.
Can anybody guess whats wrong, or shell i post some more stuff like wsdl ?
Or does anybody knows good sources where i can look up how i can get the right konfigurations to communicate with my service ?
Problem solved.
When calling a method with more than 2 Parameters you need to put them in an array like this
$result = $client->Addiere(array("a" => 2, "b" => 3))->AddiereResult;and the otherProblem was the return typ, this is solved with
not sure what the last part means but it works i will figure this out.