编程语言
首页 > 编程语言> > WCF 4.0与PHP 5客户端

WCF 4.0与PHP 5客户端

作者:互联网

我正在尝试为WCF Web服务创建一个PHP客户端.但是当我调用服务的功能时,我得到了一些错误.

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这样的东西?
或者有没有人知道很好的资源我可以查看如何获得正确的配置与我的服务进行通信?

解决方法:

问题解决了.

调用具有2个以上参数的方法时,需要将它们放在这样的数组中

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

而另一个问题是返回典型,这是通过解决的

....->AddiereResult;

不知道最后一部分意味着什么,但它的确有效我会想出来的.

标签:php,wcf,webservice-client
来源: https://codeday.me/bug/20190716/1482006.html