需要帮助调试PHP 5 SOAP Hello世界应用程序
问题描述:
我一直试图让PHP 5的SOAP扩展工作后阅读每一个教程有在网上,但无济于事。这非常令人沮丧,如果有人能指出我出错的地方以及为什么,我会非常感激。需要帮助调试PHP 5 SOAP Hello世界应用程序
感谢您提前给予的帮助,以及我需要的任何更多细节。
的WSDL如下:
<?xml version="1.0" encoding="utf-8"?>
<wsdl:definitions name="test"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
xmlns:tns="http://tempuri.org/"
xmlns:s1="http://microsoft.com/wsdl/types/"
xmlns:s="http://www.w3.org/2001/XMLSchema"
xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"
xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
targetNamespace="http://tempuri.org/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
<wsdl:types>
<s:schema elementFormDefault="qualified" targetNamespace="http://tempuri.org/">
<s:import namespace="http://microsoft.com/wsdl/types/" />
<s:element name="getUser">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="username" type="s:string" />
<s:element minOccurs="0" maxOccurs="1" name="password" type="s:string" />
</s:sequence>
</s:complexType>
</s:element>
<s:element name="getUserResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="getUserResult" type="tns:bookUser" />
</s:sequence>
</s:complexType>
</s:element>
<s:complexType name="bookUser">
<s:sequence>
<s:element minOccurs="1" maxOccurs="1" name="ID" type="s:int" />
<s:element minOccurs="1" maxOccurs="1" name="GUID" type="s1:guid" />
<s:element minOccurs="0" maxOccurs="1" name="login" type="s:string" />
<s:element minOccurs="0" maxOccurs="1" name="pass" type="s:string" />
</s:sequence>
</s:complexType>
</s:schema>
</wsdl:types>
<wsdl:message name="getUserSoapIn">
<wsdl:part name="parameters" element="tns:getUser" />
</wsdl:message>
<wsdl:message name="getUserSoapOut">
<wsdl:part name="parameters" element="tns:getUserResponse" />
</wsdl:message>
<wsdl:portType name="test">
<wsdl:operation name="getUser">
<wsdl:input message="tns:getUserSoapIn" />
<wsdl:output message="tns:getUserSoapOut" />
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="testBinding" type="tns:test">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="getUser">
<soap:operation soapAction="http://tempuri.org/getUser" />
<wsdl:input>
<soap:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="testService">
<wsdl:port name="testPort" binding="tns:testBinding">
<soap:address location="http://127.0.0.1/index.php" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
服务器的代码:
<?php
function getUser($param) {
return array(
'bookUser'=>array
(
'ID'=>1,
'GUID'=>2,
'login'=>$param->username,
'pass'=>$param->password
)
);
}
ini_set("soap.wsdl_cache_enabled", "0"); // disabling WSDL cache
$server = new SoapServer("http://127.0.0.1/1.wsdl");
$server->addFunction("getUser");
$server->handle();
?>
和代码为客户端:
$client = new SoapClient("http://127.0.0.1/index.php?wsdl", array('exceptions' => 0));
try {
$arr_data = array
(
array
(
'username'=>'xyz',
'password'=>'abc'
)
);
print_r($client->__soapCall("getUser",$arr_data));
}
catch (SoapFault $result) {
print_r($result);
}
答
尝试改变的下面的行wsdl:
<s:schema elementFormDefault="qualified" targetNamespace="http://tempuri.org/">
添加到您的开发服务器的实际主机名/ IP地址。例如。如果你的开发服务器是在192.168.0.100在本地网络上:
<s:schema elementFormDefault="qualified" targetNamespace="http://192.168.0.100/">
我用你的代码从上面我的dev的服务器上,这是造成错误,直到我固定的线的WSDL。
你收到什么样的错误? – powtac 2010-05-05 10:08:11
输出是:stdClass对象() 我不明白是不是SOAP应该可以互操作? stdClass对象是PHP特定的结构。我怎样才能找回XML? 即使在查看源代码,我看到相同的输出stdClass对象()。 我不应该看到 xml结构的类型吗? 另外,我从服务器返回的数据在哪里? ID,GUID等?为什么在结构中不可见? AM我做错了什么? –
2010-05-05 10:44:58