2013-01-07 53 views
0

我想構建一個簡單的web服務,並且正在運行情況。 我不知道我在做什麼錯,所以我不能抓住肥皂服務器返回的值。PHP SoapClient也不返回Zend_Soap_client

我有一個Zend_Soap_Server和我indexController的內Zend_Soap_Client:

class IndexController 
extends Zend_Controller_Action 
{ 

    public function init() 
    { 
     $this->getHelper('viewRenderer')->setNoRender(true); 
     Zend_loader::loadFile(APPLICATION_PATH . '/../library/Web/Service.php'); 
    } 

    public function indexAction() {} 

    public function serverAction() 
    { 

     if(isset($_GET['wdsl'])) { 
      $server = new Zend_Soap_AutoDiscover(); 
      $server->setClass('Web_Service'); 
      $server->handle(); 
     } else { 
      $options = array(
       'soap_version' => SOAP_1_1 , 
       'uri' => 'http://webservices.localhost/index/server?wdsl=1' 
      ); 
      $server = new Zend_Soap_Server(null, $options); 
      $server->setClass('Web_Service'); 
      $server->handle(); 
     } 
    } 

    public function testAction() 
    { 
     $client = new Zend_Soap_Client(
      'http://webservices.localhost/index/server?wdsl' 
     ); 

     print($client->getMessage()) ; 
    } 

} 

,並傳遞給SOAP服務器一個非常簡單的服務類:

class Web_Service 
{ 

    public function getMessage() 
    { 
     return 'ok'; 
    } 

} 

當我請求URL我的Soap服務器它返回我認爲應該返回的內容:

<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://webservices.misterprint.com.br/index/server" 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="Web_Service" targetNamespace="http://webservices.misterprint.com.br/index/server"> 
<types> 
<xsd:schema targetNamespace="http://webservices.misterprint.com.br/index/server"/> 
</types> 
<portType name="Web_ServicePort"> 
<operation name="getMessage"> 
<documentation>getMessage</documentation> 
<input message="tns:getMessageIn"/> 
</operation> 
</portType> 
<binding name="Web_ServiceBinding" type="tns:Web_ServicePort"> 
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/> 
<operation name="getMessage"> 
<soap:operation soapAction="http://webservices.misterprint.com.br/index/server#getMessage"/> 
<input> 
<soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://webservices.misterprint.com.br/index/server"/> 
</input> 
</operation> 
</binding> 
<service name="Web_ServiceService"> 
<port name="Web_ServicePort" binding="tns:Web_ServiceBinding"> 
<soap:address location="http://webservices.misterprint.com.br/index/server"/> 
</port> 
</service> 
<message name="getMessageIn"/> 
</definitions> 

但是wh我訪問客戶端的測試,它不打印任何東西!

如果我改變getMessage方法的名字的getMessages例如Zend公司拋出了我的異常:

Message: Function ("getMessages") is not a valid method for this service 

我不知道我做錯了。

在此先感謝!

回答

1

嗨,你可能想先檢查一些事情,但我很感謝你可能已經知道這件事/已經做到了。

開發SOAP服務時,除非您更改了任何默認設置,否則WSDL可能會被緩存。

您可能希望在相關環境設置下(例如在開發中)將此添加到您的application.ini中。

phpSettings.soap.wsdl_cache_enabled = 0 

這意味着您的WSDL將不會被緩存,可以排除任何問題,在這一方面 - 雖然說你的WSDL似乎是看你想使用的方法。

此外,當使用ZF自動生成WSDL時,您會希望爲該方法添加基本註釋,以便ZF WSDL生成器可以拾取基本註釋,例如添加任何@參數和@返回信息。就像這樣:

/**  
    * @return string 
    */ 
public function getMessage() 
{ 
    return 'ok'; 
} 

所以做完這些嘗試做一些與你的服務器的方法不同....嘗試

public function serverAction() 
{ 
    $baseUrl = 'http://webservices.localhost/index/server'; 

    if(isset($_GET['wdsl'])) { 
     $strategy = new Zend_Soap_Wsdl_Strategy_AnyType(); 
     $server = new Zend_Soap_AutoDiscover($strategy); 
     $server->setUri($baseUrl); 
     $server->setClass('Web_Service'); 
     $server->handle(); 
    } else {    
     $server = new Zend_Soap_Server($baseUrl . '?wsdl'); 
     $server->setClass('Web_Service'); 
     $server->handle(); 
    } 
} 
+0

只是爲了澄清,如果添加評論,我建議再做確保WSDL緩存肯定是關閉,否則Zend_Soap_Client可能會使用舊版本,你不會進一步前進...... – dkcwd

+0

所以@Dave Clark,我遵循你的提示,但我仍然無法打印出'ok'字符串。 –

+0

不用擔心,只需添加一個快速代碼示例,以便您嘗試....現在可以工作了嗎? – dkcwd

相關問題