php와 zend 프레임 워크로 웹 서비스를 만들고 싶습니다.PHP로 웹 서비스 빌드에서 빈 응답 받기
csiService.php :
<?php
require_once 'Zend/Loader.php';
require_once 'CSI.php';
$WSDL_URI="http://csi.chemicalseeker.com/csiService.php?WSDL";
if(isset($_GET["WSDL"]))
{
Zend_Loader::loadClass('Zend_Soap_AutoDiscover');
Zend_Loader::loadClass('Zend_Soap_Wsdl_Strategy_ArrayOfTypeSequence');
$autodiscover = new Zend_Soap_AutoDiscover('Zend_Soap_Wsdl_Strategy_ArrayOfTypeSequence');
$autodiscover->setBindingStyle(array('style' => 'document'));
$autodiscover->setOperationBodyStyle(array('use' => 'literal'));
$autodiscover->setClass('CSI');
$autodiscover->handle();
}
else
{
Zend_Loader::loadClass('Zend_Soap_Server');
$server = new Zend_Soap_Server($WSDL_URI);
$server->setClass('CSI');
$server->handle();
}
?>
CSI.php을 포함 서버 측 코드는 다음과 같다
내가 호스트 파일을 편집 *<?php
class CSI {
/**
* @return string
*/
function helloWorld()
{
return("Hello");
}
}
?>
, 도메인 "csi.chemicalseeker.com"을 127.0.0.1로 바인딩하려면 WSDL은 다음과 같이 잘 작동합니다. 내 브라우저에서 "http://csi.chemicalseeker.com/csiService.php?WSDL"방문 :
<?xml version="1.0"?>
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:tns="http://csi.chemicalseeker.com/csiService.php" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap-enc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" name="CSI"
targetNamespace="http://csi.chemicalseeker.com/csiService.php">
<types>
<xsd:schema targetNamespace="http://csi.chemicalseeker.com/csiService.php">
<xsd:element name="helloWorld">
<xsd:complexType />
</xsd:element>
<xsd:element name="helloWorldResponse">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="helloWorldResult" type="xsd:string" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
</types>
<portType name="CSIPort">
<operation name="helloWorld">
<documentation>@return string</documentation>
<input message="tns:helloWorldIn" />
<output message="tns:helloWorldOut" />
</operation>
</portType>
<binding name="CSIBinding" type="tns:CSIPort">
<soap:binding style="document"
transport="http://schemas.xmlsoap.org/soap/http" />
<operation name="helloWorld">
<soap:operation
soapAction="http://csi.chemicalseeker.com/csiService.php#helloWorld" />
<input>
<soap:body use="literal" />
</input>
<output>
<soap:body use="literal" />
</output>
</operation>
</binding>
<service name="CSIService">
<port name="CSIPort" binding="tns:CSIBinding">
<soap:address location="http://csi.chemicalseeker.com/csiService.php" />
</port>
</service>
<message name="helloWorldIn">
<part name="parameters" element="tns:helloWorld" />
</message>
<message name="helloWorldOut">
<part name="parameters" element="tns:helloWorldResponse" />
</message>
</definitions>
가 나는 또한 CSIClient.php라는 PHP 클라이언트 파일을 작성하고 브라우저에서 방문 :
CSIClient.php 결과는 "안녕하세요"의 내용에 문자열 것으로 예상하지만, 빈 stdObject 보여줍니다
<?php
require_once 'Zend/Loader.php';
require_once 'CSI.php';
Zend_Loader::loadClass('Zend_Soap_Client');
$WSDL_URI="http://csi.chemicalseeker.com/csiService.php?WSDL";
$client = new Zend_Soap_Client($WSDL_URI);
echo('<pre>');
var_dump($client->helloWorld());
echo('</pre>');
?>
:
을
"$ client-> getFunctions()"및 "$ client-> getTypes()"를 통해 함수 목록 및 유형 목록을 가져올 수 있습니다. 이는 "CSI"클래스가 웹 서비스에 성공적으로 연결되었음을 의미합니다. 그러나 결과를 올바르게 반환 할 수는 없습니다.
나는 또한 웹 서비스를 호출하는 다른 방법을 시도했다. 내가 helloWorld() 함수를 호출 플래시 빌더를 사용하여, 서버의 응답은 다음과 같다 :
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://csi.chemicalseeker.com/csiService.php">
<SOAP-ENV:Body>
<ns1:helloWorldResponse/>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
우리가 예상 된 결과 "안녕하세요"이 중 하나를 SOAP 봉투에 포함되지 않은 것을 볼 수있다. 중요한 코드를 놓치거나 코드에서 실수를 한 적이 있습니까? 단서가 있으면 제발 도와주세요. 고맙습니다!
나는이 대답은 너무 fortunated되어 죄송합니다. Soap Server가 함수 반환을 처리하지 못합니다. – xsubira