我尝试使用soapServer构建一个简单的WebService,但是我遇到了属性问题。 我构建了最简单的服务器:
server.php
$request = file_get_contents("php://input");
$soapServer = new SoapServer(NULL, array('uri' => $wsdlPath));
$soapServer->addFunction('TestFunction');
$soapServer->handle($request);
function TestFunction($request){
return $request;
}
我使用SoapUi在处理soapServer后检查$ request。
请求:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header>
<ind:Authorization>
<Username>testUser</Username>
<Password>testPass</Password>
</ind:Authorization>
</soapenv:Header>
<soapenv:Body>
<TestFuntion>
<TestFuntionRQ>
<Books>
<Book Quantity="2">This is a test Book</Book>
</Books>
</TestFuntionRQ>
</TestFuntion>
</soapenv:Body>
</soapenv:Envelope>
我得到回复作为回应(处理soapServer后的请求):
<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<TestFunctionResponse>
<return xsi:type="SOAP-ENC:Struct">
<Books xsi:type="SOAP-ENC:Struct">
<Book xsi:type="xsd:string">This is a test Book</Book>
</Books>
</return>
</TestFunctionResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
制作vardump我得到:
object(stdClass)#5 (1) {
["Books"]=>
object(stdClass)#6 (1) {
["Book"]=>
string(19) "This is a test Book"
}
}
我有两个问题:
1)为什么soapServer在处理后没有保留属性的信息?
2)有没有办法在$ soapServer-&gt;句柄($ request)之后保持$ request'不变'。我的意思是在处理之后有没有选择在另一种类型(例如普通字符串)而不是对象(stdClass)中获取$ request?
提前谢谢。