首先新建一个服务端wsdl文件类

<?php
class Model_Service_SoapClassSetTest {
 
    public function getUser($a,$b) {
        return array("test"=>array(12345,"唐先生"),$b=>array('a'=>$a));
    }
   
 
    public function getPass($a,$b) {
        return (object)array($a,$b);
    }
}

注意注释部分的写法:一定是/** 开头 @param为接收参数的描述,@return为返回值的结构类类描述

 

Zend_Soap_Autodiscover is not a Soap Server

It is very important to note, that the class Zend_Soap_AutoDiscover does not act as a SOAP Server on its own. It only generates the WSDL and serves it to anyone accessing the url it is listening on.

As the SOAP Endpoint Uri is uses the default 'http://' .$_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME'], but this can be changed with the setUri() function or the Constructor parameter of Zend_Soap_AutoDiscover class. The endpoint has to provide a Zend_Soap_Server that listens to requests.

 

for example :

用Zend_Soap轻松实现webservice (1)

@param和@return的值类型如下:

PHP strings <-> xsd:string.

PHP integers <-> xsd:int.

PHP floats and doubles <-> xsd:float.

PHP booleans <-> xsd:boolean.

PHP arrays <-> soap-enc:Array.

PHP object <-> xsd:struct.

PHP class <-> based on complex type strategy PHP void <-> empty type.

If type is not matched to any of these types by some reason, then xsd:anyType is used.

新建Controller文件:

<?php

class Soap_server_test {
  function indexAction(){
  if(isset($_GET['wsdl'])) {
      $autodiscover = new Zend_Soap_AutoDiscover();
      $autodiscover->setClass('Model_Service_SoapClassSetTest');
      $autodiscover->handle();
    
  } else {
      // pointing to the current file here
      $soap = new Zend_Soap_Server("
http://tj.test.com/default/soap_server_test/index?wsdl");
      $soap->setClass('Model_Service_SoapClassSetTest');
      $soap->handle();
  }  
 }
 
 function clientAction() {
  $options= array('encoding' => 'UTF-8','compression' => SOAP_COMPRESSION_ACCEPT );
  $client = new Zend_Soap_Client('http://tj.test.com/default/soap_server_test/index?wsdl',$options);
  $result=$client->getUser(array("tang"),"man");
  print_r($result);
  $result=$client->getPass("tang","man");
  print_r($result);
 }
 
}

 

其中$soap->setClass('Model_Service_SoapClassSetTest');中的Model_Service_SoapClassSetTest 是刚才新建的类名。

相关文章: