2011-10-24 18 views
3

私はWCF Webサービス用のPHPクライアントを作ろうとしています。しかし、私はサービスの機能を呼び出すときにいくつかのエラーが発生します。WCF 4.0 with PHP 5 Client

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> 

機能:

> public int Addiere(int a, int b) 
     { 
      return a + b; 
     } 

PHP-要求::私はそのようなエラーを取得し、これらの機能のための

> $client = new SoapClient("http://localhost:8731/CartService?wsdl"); 
> 
> $result = $client->Addiere(2,4); 

"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"".

ドイツ語で

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

しかし、この機能が働いている:

C#

> public string Message() 
     { 
      return "WORD"; 
     } 

PHP

> $result = $client->Message(); 
var_dump($result); 

結果

object(stdClass)#2 (1) { ["MessageResult"]=> string(4) "WORD" } WORD

唯一の問題は戻り値の型が文字列でないことです。

誰でも何が間違っていると推測できますか?シェルはwsdlのようなものをいくつか投稿できますか? 誰かが、私のサービスと通信するための正しい構成を得る方法を調べることができる良い情報源を知っていますか?

答えて

10

問題を解決しました。 2つの以上のパラメータを持つメソッドを呼び出す場合

は、あなたがこの

$result = $client->Addiere(array("a" => 2, "b" => 3))->AddiereResult;

のような配列にそれらを置く必要があるとotherProblemが戻り標準だった、これは

....->AddiereResult; 
で解決されます

最後の部分が何を意味するのかはっきりしていませんが、私はこれを理解します。

+1

溶液上でのお祝い。あなたができるときは、他の人があなたの成功から学ぶかもしれないようにあなたの答えを「受け入れ」とマークしてください。乾杯〜 –