我正在尝试构建一个简单的 Web 服务,并且正在跨情况运行。我不知道我做错了什么,所以我无法获取肥皂服务器返回的值。
我的 indexController 中有一个 Zend_Soap_Server 和一个 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() ) ;
}
}
并将一个非常简单的 Service 类传递给肥皂服务器:
class Web_Service
{
public function getMessage()
{
return 'ok';
}
}
当我请求我的 Soap 服务器的 URL 时,它返回我猜应该返回的内容:
<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>
但是当我访问客户端的测试时,它什么也没打印!
例如,如果我将 getMessage 方法的名称更改为 getMessages,Zend 会抛出异常:
Message: Function ("getMessages") is not a valid method for this service
我不知道我做错了什么。
提前致谢!