我正在尝试为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";
}
> $result = $client->Message();
var_dump($result);
结果
object(stdClass)#2 (1) { [“MessageResult”]=> string(4) “WORD” } WORD
唯一的问题是返回类型是没有字符串.
任何人都可以猜到什么是错的,或者我发布了更多像wsdl这样的东西?
或者有没有人知道很好的资源我可以查看如何获得正确的配置与我的服务进行通信?
解决方法:
问题解决了.
$result = $client-> Addiere(array(“a”=> 2,“b”=> 3)) – > AddiereResult;
....->AddiereResult;
不知道最后一部分意味着什么,但它的确有效我会想出来的.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。