php
  • zend-framework
  • soap
  • 2013-06-20 51 views 0 likes 
    0

    我想在PHP中獲得肥皂響應。它不斷作爲一個對象來到我的Web瀏覽器,但不是xml。 WSDL顯示爲XML,但不顯示收到的響應。以下是我的服務器端代碼。 SOAP服務器是使用Zend皁肥皂響應在陣列

    ini_set("soap.wsdl_cache_enabled", 0); 
        if (isset($_GET['wsdl'])){ 
         $wsdl = 'http://localhost/webservice/soap'; 
    
         $autoDiscover = new AutoDiscover(); 
         $autoDiscover->setOperationBodyStyle(
           array('use' => 'literal', 
             'namespace' => 'http://localhost/webservice/soap') 
         ); 
    
    
         $autoDiscover->setBindingStyle(
           array('style' => 'rpc', 
             'transport' => 'http://schemas.xmlsoap.org/soap/http') 
         ); 
    
         $autoDiscover->setComplexTypeStrategy(new ArrayOfTypeComplex()); 
    
         // $service is the class that does the handling of functions 
         $autoDiscover->setClass($service); 
         $autoDiscover->setUri($wsdl); 
    
         $response->getHeaders()->addHeaderLine('Content-Type', 'text/xml'); 
    
         $response->setContent($autoDiscover->toXml()); 
    
         } else { 
    
          $server = new Server('http://localhost/webservice/soap?wsdl' 
          ); 
           // $service is the class that does the handling of functions 
          $server->setObject($service); 
          $response->setContent($server->handle()); 
    
          } 
    
          return $response; 
          } 
    

    服務類

    class service 
        { 
    /** 
    * 
    * @param string $Email 
    * @return int $Credit 
    */ 
    
    public function checkCredits($Email) 
    
    { 
        $validator = new email(); 
    
        if (!$validator->isValid($Email)) 
        { 
    
         return new \SoapFault('5', 'Please Provide an Email'); 
    
    
        } 
        $rowset = $this->tableGateway->select(array('EMAIL'=>$Email)) 
    
        $row = $rowset->current(); 
        $credits = $row->CREDITS; 
        return $credits; 
    } 
    
        } 
    

    要求是:

    try{ 
    $sClient = new SoapClient('http://localhost/webservice/soap?wsdl'); 
        $params = "email"; 
        $response = $sClient->checkCredits($params); 
    var_dump($response); 
    } catch(SoapFault $e){ 
    
    var_dump($e); 
    } 
    
    +0

    哪裏是要求? – DevZer0

    +0

    $ client = new SoapClient(「wsdl」,array('trace'=> 1,'features'=> SOAP_SINGLE_ELEMENT_ARRAYS,'style'=> SOAP_DOCUMENT, 'use'=> SOAP_LITERAL)); $ result = $ client-> webservice('137'); $ rr = $ client-> getLastResponse(); print_r($ rr); – snab

    +0

    所以你有一個函數來處理這個特定的調用? – DevZer0

    回答

    0

    這是我如何處理我的功能與SoapClient的一個例子:

    $client = new SoapClient('http://url/Service.svc?wsdl'); 
    $var = array('arg' => 10, 
          'VA' => 48); 
    $varresponse = $client->Function($var); 
    print_r($varresponse->FunctionResult); 
    

    希望這會有助於y ou out。

    +0

    謝謝,但它仍然不工作。我的web服務在php中也不是.net。這可能是什麼造成它? – snab

    +0

    我認爲這不重要,如果它在PHP或.NET 你的錯誤是什麼? – Matheno

    +0

    沒有錯誤。它只是返回一個對象而不是xml – snab

    0

    你SoapServer的應該看起來有點像這樣:

    <?php 
    if(!extension_loaded("soap")){ 
        dl("php_soap.dll"); 
    } 
    
        ini_set("soap.wsdl_cache_enabled","0"); 
        $server = new SoapServer("hello.wsdl"); 
    
        function doHello($yourName){ 
         return "Hello, ".$yourName; 
        } 
    
        $server->AddFunction("doHello"); 
        $server->handle(); 
    
    ?> 
    

    你怎麼設置你的嗎?你還有什麼東西嗎?

    現在,你的客戶應該是這樣的:

    <?php 
    
    try{ 
        $sClient = new SoapClient('http://localhost/test/wsdl/hello.xml'); 
        $params = "Name"; 
        $response = $sClient->doHello($params); 
        var_dump($response); 
    } catch(SoapFault $e){ 
    
        var_dump($e); 
    } 
    ?> 
    
    +0

    謝謝。但是在Soap對象中,我有一個叫做service的類來處理函數。我是否需要單獨添加功能?我已經更新了我的問題,請看看 – snab

    相關問題