2012-09-04 4 views
2

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 봉투에 포함되지 않은 것을 볼 수있다. 중요한 코드를 놓치거나 코드에서 실수를 한 적이 있습니까? 단서가 있으면 제발 도와주세요. 고맙습니다!

답변

0

테스트하는 동안 PHP 오류 로그를보십시오.

http://php.net/manual/de/function.error-reporting.php

그리고 soapUI에 더 많은 확장 성 테스트를 수행 할 수 있습니다 :

당신은 또한 더 많은 정보 오류 힌트를 얻을 수 E_STRICT 또는 E_NOTICE을 error_reporting를 활성화 할 수 있습니다

2

나뿐만 아니라이 함께 고군분투를하지만, 비 WSDL 모드로 전환하여 위에있는 문제를 해결할 수있었습니다.

필자가 시도한 것과 상관없이 필자는 항상 내 자신의 자동 검색 생성 WSDL에서 WSDL을로드하려고 할 때와 동일한 빈 응답을 받았다. (재귀 문제가있는 것 같지만 지금 당장은 볼 수 없다)

비 WSDL 모드로 전환하면 적절한 응답을 얻을 수있다.다음과 같이 서버를 생성

시도 :

$server = new Zend_Soap_Server(null, array('uri' => $WSDL_URI)); 
+0

나는이 대답은 너무 fortunated되어 죄송합니다. Soap Server가 함수 반환을 처리하지 못합니다. – xsubira