zend_soapのwebserviceの使い方

12274 ワード

zend_にのみ使用SOapパッケージのZend_Soap_Server,Zend_Soap_AutoDiscoverとZend_Soap_Clientの3つのクラス
まずZFはphpを呼び出すsoap拡張であることに注意して、phpを確認してください.ini(;extension=php_soap.dllはセミコロンを除く)でsoap拡張を開き、phpの構成に注意する.iniのsoapセグメントのwsdlキャッシュです.デバッグ時にキャッシュを閉じてください.そうしないと、modelを変更しても効果が表示されません.パブリッシュ時にキャッシュを開くことができます.それからサーバースイートを使う問題で、APMServ 5を使ってみました.2.6、完全に正しいコードは、使用することです.
Zend_Soap_Clientではサービス側が提供するサービス関数を取得できず、最後にwapmserverに変更しても問題ありません...
基本的な流れはZend_を使うことですSoap_Server,Zend_Soap_AutoDiscoverはサービス・エンドを構築し、Zend_を使用します.Soap_Clientはサービス側が提供する機能を呼び出す
    
(1) , controller
/modules/services/controllers/WapSearchControllers.php
<?php
// model
require_once realpath(APPLICATION_PATH).'/modules/services/models/WapArticle.php';
class Services_WapSearchController extends Zend_Controller_Action
{
private $_WSDL_URI = "http://192.168.1.100/kktapp/public/services/wapsearch/index?wsdl";
private function handleWSDL() {
$autodiscover = new Zend_Soap_AutoDiscover();
//
$autodiscover->setClass('WapArticle');
$autodiscover->handle();
}
private function handleSOAP() {
$soap = new Zend_Soap_Server($this->_WSDL_URI);
$soap->setClass('WapArticle');
$soap->handle();
}
// layout,
public function init(){
$this->_helper->viewRenderer->setNoRender();
$this->_helper->layout()->disableLayout();
}

public function indexAction(){
// wsdl wsdl uri soap
if(isset($_GET['wsdl'])) {
$this->handleWSDL();
} else {
$this->handleSOAP();
}
}
//
public function clientAction(){
$client = new Zend_Soap_Client($this->_WSDL_URI);
//
$res = $client->getArticle(31);
var_dump($res);
}

}
, setClass ,

controllers model
// ,
/modules/services/models/models/WapArticle.php
<?php
//
require_once realpath(APPLICATION_PATH).'/modules/news/models/FrontDbTable/Article.php';

class WapArticle{

/**
* getArticles ,operate database example
*
* @param Int $id
* @return String
*/
public function getArticle($id)
{
//
$dbtable = new News_Model_FrontDbTable_Article();
$s = $dbtable->getArticle($id);

// xml json ,
$d = json_encode($s);
return $d;
}

/**
* Simple array sort
*
* @param Array $array
* @return Array
*/
public function simple_sort($array) {
asort($array);
return $array;
}
/**
* Adds method
*
* @param Int $param1
* @param Int $param2
* @return Int
*/
public function math_addx($param1, $param2) {
return $param1+$param2;
}

}
?>


WapArticle Zend_Db_Table_Abstract , WapArticle , , ,

,google , , ZF , , ,

Zend_Registry::get('db') , , , ,

(modules/news/models/FrontDbTable/Article.php), 。 !

。 , , , , , 。


, ( , , 。。。)
/**
* Adds method
*
* @param Int $param1
* @param Int $param2
* @return Int
*/
public function math_addx($param1, $param2) {
return $param1+$param2;
}

"@param "
"@return "

/modules/news/models/FrontDbTable/Article.php
class News_Model_FrontDbTable_Article extends Zend_Db_Table_Abstract
{
protected $_name = 'custom_article';

public function getArticle($id)
{
$id = (int)$id;
$where = array('id='.$id, 'isshow=1');
$row = $this->fetchRow($where);
if(!$row){
return 0;
}
return $row->toArray();
}
}



http://192.168.1.100/kktapp/public/services/wapsearch/index?wsdl server wsdl,uri ,


http://192.168.1.100/kktapp/public/services/wapsearch/index

<?xml version="1.0" encoding="UTF-8" ?>
- <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
- <SOAP-ENV:Body>
- <SOAP-ENV:Fault>
<faultcode>Sender</faultcode>
<faultstring>Invalid XML</faultstring>
</SOAP-ENV:Fault>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
http://192.168.1.100/kktapp/public/services/wapsearch/client , ( java,.net )
getArticle($id), , json

-----------------------------------------------------------------------------

java , ,

axis1.4

import org.apache.axis.client.Call;
import org.apache.axis.client.Service;

public class Testserver {

public static void main(String[] args) {
try {
String endpoint = "http://192.168.1.100/kktapp/public/services/wapsearch/index";
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(endpoint);
call.setOperationName("getArticle");
int temp = 31;
String result = (String) call.invoke(new Object[] { temp });
System.out.println("result is " + result);
}
catch (Exception e) {
System.err.println(e.toString());
}
}

}