这个问题重复
我正在尝试 使用 zend Framework 1.9.6 和 php 5.3.1 来使用 Zend_Soap。
Soap.php(wsdl 生成器)
<?php
require_once('Zend/Soap/Server.php');
require_once('Zend/Soap/AutoDiscover.php');
require_once('Soaping.php');
$_WSDL_URI="http://server/soap/soap.php?wsdl";
if(isset($_GET['wsdl'])) {
hadleWSDL();
} else {
handleSOAP();
}
function hadleWSDL() {
$autodiscover = new Zend_Soap_AutoDiscover();
$autodiscover->setClass('Soaping');
$autodiscover->handle();
}
function handleSOAP() {
global $_WSDL_URI;
$soap = new Zend_Soap_Server($_WSDL_URI);
$soap->setClass('Soaping');
$soap->handle();
}
Soaping.php(Web 服务类)
<?php
class Soaping {
/**
*
* @param string $str
* @return string
*/
function doString($str) {
return $str;
}
}
client.php - 客户端
<?php
require_once('Zend/Soap/Client.php');
$_WSDL_URI="http://server/soap/soap.php?wsdl";
$client = new Zend_Soap_Client($_WSDL_URI);
$client->doString('aaa');
当我执行 client.php 文件时,出现错误:
致命错误:未捕获的 SoapFault 异常:[Sender] 函数(“do_math”)不是 /usr/local/ZendFramework-1.9.6/library/Zend/Soap/Client.php:1090 中此服务的有效方法堆栈跟踪:#0 /usr/local/ZendFramework-1.9.6/library/Zend/Soap/Client.php(1090): SoapClient->__soapCall('do_math', Array, NULL, NULL, Array) #1 [内部函数]: Zend_Soap_Client->__call('do_math', Array) #2 /home/ufk/Projects/xpogames-development/xpo/soap/client.php(6): Zend_Soap_Client->do_math(1, 1) #3 {main} 抛出在 /usr/local/ZendFramework-1.9.6/library/Zend/Soap/Client.php 的第 1090 行
xml 中,该 XML 是通过链接 http://server/soap/ 创建的Soap.php?wsdl
<定义 xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://xpogames/soap/soap.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="Soaping" targetNamespace="http://xpogames/soap/soap.php"><类型><操作名称="doString"><文档>do string< ;输入消息=“tns:doStringIn”/><输出消息=“tns:doStringOut”/> <绑定名称=“SoapingBinding”类型=“tns:SoapingPort” ><操作名称=“doString”> <服务名称="SoapingService"<端口name =“SoapingPort”绑定=“tns:SoapingBinding”><消息name="doStringIn"><部分名称="str" type="xsd:string"/><消息名称="doStringOut"><部分名称="return" type= "xsd:string"/>
我看到该函数存在于 xml 中,为什么我不能使用它?
请更新
如果我将以下函数添加到类中, :
/**
* 添加方法
*
* @param Int $param1
* @param Int $param2
* @return Int
*/
公共函数 math_add($param1, $param2) {
返回$param1+$param2;
}
这个功能得到认可。但即使我将其更改为 add_math2(),该函数也不会再次被识别。
Duplicate of this question
I'm trying to work with Zend_Soap using zend framework 1.9.6 and php 5.3.1.
soap.php (wsdl generator)
<?php
require_once('Zend/Soap/Server.php');
require_once('Zend/Soap/AutoDiscover.php');
require_once('Soaping.php');
$_WSDL_URI="http://server/soap/soap.php?wsdl";
if(isset($_GET['wsdl'])) {
hadleWSDL();
} else {
handleSOAP();
}
function hadleWSDL() {
$autodiscover = new Zend_Soap_AutoDiscover();
$autodiscover->setClass('Soaping');
$autodiscover->handle();
}
function handleSOAP() {
global $_WSDL_URI;
$soap = new Zend_Soap_Server($_WSDL_URI);
$soap->setClass('Soaping');
$soap->handle();
}
Soaping.php (web service class)
<?php
class Soaping {
/**
*
* @param string $str
* @return string
*/
function doString($str) {
return $str;
}
}
client.php - client
<?php
require_once('Zend/Soap/Client.php');
$_WSDL_URI="http://server/soap/soap.php?wsdl";
$client = new Zend_Soap_Client($_WSDL_URI);
$client->doString('aaa');
when i execute the client.php file i get the error:
Fatal error: Uncaught SoapFault exception: [Sender] Function ("do_math") is not a valid method for this service in /usr/local/ZendFramework-1.9.6/library/Zend/Soap/Client.php:1090 Stack trace: #0 /usr/local/ZendFramework-1.9.6/library/Zend/Soap/Client.php(1090): SoapClient->__soapCall('do_math', Array, NULL, NULL, Array) #1 [internal function]: Zend_Soap_Client->__call('do_math', Array) #2 /home/ufk/Projects/xpogames-development/xpo/soap/client.php(6): Zend_Soap_Client->do_math(1, 1) #3 {main} thrown in /usr/local/ZendFramework-1.9.6/library/Zend/Soap/Client.php on line 1090
xml that is created by following the link http://server/soap/soap.php?wsdl
<?xml version="1.0"?>
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://xpogames/soap/soap.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="Soaping" targetNamespace="http://xpogames/soap/soap.php"><types><xsd:schema targetNamespace="http://xpogames/soap/soap.php"/></types><portType name="SoapingPort"><operation name="doString"><documentation>do string</documentation><input message="tns:doStringIn"/><output message="tns:doStringOut"/></operation></portType><binding name="SoapingBinding" type="tns:SoapingPort"><soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/><operation name="doString"><soap:operation soapAction="http://xpogames/soap/soap.php#doString"/><input><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://xpogames/soap/soap.php"/></input><output><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://xpogames/soap/soap.php"/></output></operation></binding><service name="SoapingService"><port name="SoapingPort" binding="tns:SoapingBinding"><soap:address location="http://xpogames/soap/soap.php"/></port></service><message name="doStringIn"><part name="str" type="xsd:string"/></message><message name="doStringOut"><part name="return" type="xsd:string"/></message></definitions>
i see that the function exists in the xml, why can't i use it ?
update
if i add the following function to the class:
/**
* Add method
*
* @param Int $param1
* @param Int $param2
* @return Int
*/
public function math_add($param1, $param2) {
return $param1+$param2;
}
this function get recognized. but even if i change it to add_math2(), the function doesn't get recognized again.
发布评论
评论(2)
好吧,看来 php 缓存了我第一次创建 wsdl 文件并且没有重新创建它。
可以通过php指令soap.wsdl_cache_enabled=0禁用soap缓存
ok it seems that php cached the first time i created a wsdl file and didn't recreate it.
soap caching can be disabled by the php directive soap.wsdl_cache_enabled=0
您应该只为函数添加注释,然后声明参数输入、输出。例子:
You should add comment for function only, then declare parameter input, output. Example: