我正在尝试在我的计算机中使用 SOAP 客户端-服务器,但它看起来无法正常工作,当我尝试运行我的 SOAP 客户端时出现错误获取 Http header 错误。
我一直在寻找,我遇到的解决方案是将 default_socket_timeout 从 60 秒增加到 120 秒,但它对我不起作用,我还看到了另一种解决方案,将虚拟主机放在我的 apache KeepAlive Off 中,那没有用。
WSDL 工作正常,因为我尝试在另一台计算机上使用它并且它工作正常。
我正在使用 Zend Framework 在 Linux Mint 中运行 PHP 版本 5.3.5-1ubuntu7.4,我希望你们中的一些人能帮助我解决这个问题,谢谢。
最佳答案
抱歉,我不知道您使用什么来设置您的 SOAP 服务......
如果您能提供有关您的 SOAP 服务的更多信息(给定 Zend Framework 标签的 Zend_Soap)等,那就太好了。
此外,作为一种快速替代方案,您说您已经在另一台计算机上查看了 WSDL,或许可以在替代环境中尝试该应用程序以确保它不是环境问题。
可能是您的客户端-服务器代码的一个简单问题。
更新: 好吧,所以我意识到我昨天提到的例子没有完全实现,所以我很快把一些东西拼凑在一起,你可以试试看它是否适用于你的环境。
代码是我发现的东西的混合 here (an example of Zend_Soap_Server)以及来自另一个 SO 问题的内容 here (an example of a basic SOAP service test) .
我最后使用 ZF 1.11 对其进行了测试,我概述的示例使用了您通过新 ZF 项目获得的默认应用程序路径(例如,模型位于目录 application/models 中,因此显示的模型是抬头 Application_Model_Classname)。
如果有效,您可以相应地进行调整……如果无效,我们可以尝试其他方法。 首先创建一个新的 SOAP Controller 并像这样设置类:
<?php
class SoapController extends Zend_Controller_Action
{
public function init()
{
ini_set("soap.wsdl_cache_enabled", "0"); //disable WSDL caching
$this->_helper->layout()->disableLayout(); //disable the layout
$this->_helper->viewRenderer->setNoRender(); //disable the view
}
public function indexAction ()
{
if (isset($_GET['wsdl'])) {
//return the WSDL
$this->handleWSDL();
} else {
//handle SOAP request
$this->handleSOAP();
}
}
private function handleWSDL ()
{
$strategy = new Zend_Soap_Wsdl_Strategy_AnyType();
$autodiscover = new Zend_Soap_AutoDiscover();
$autodiscover->setComplexTypeStrategy($strategy);
$autodiscover->setClass('Application_Model_SoapService');
$autodiscover->handle();
}
private function handleSOAP ()
{
$server = new Zend_Soap_Server(null,
array('uri' => "http://YOURDOMAIN/soap?wsdl"));
$server->setClass("Application_Model_SoapService");
$server->handle();
}
public function testAction()
{
$client = new Zend_Soap_Client("http://YOURDOMAIN/soap?wsdl");
try {
echo $client->testMethod('test');
} catch (Exception $e) {
echo $e;
}
}
}
在上面的类中,WSDL 是使用 Zend_Soap_Autodiscover 自动生成的,并将 application/models/SoapService.php 中的 SoapService.php 文件用作模板。请注意目标类中每个方法上方的 DocBock 注释是此过程不可或缺的一部分。
接下来在默认模型文件夹中创建 SoapService.php 文件:
<?php
class Application_Model_SoapService
{
/**
* testMethod
*
* @param string $string
* @return string $testSuccess
*/
public function testMethod(string $string)
{
$testSuccess = 'Test successful, the message was: ' . $string;
return $testSuccess;
}
}
如果一切正常,您可以访问:
http://YOURDOMAIN/soap?wsdl
查看 WSDL 并访问:
http://YOURDOMAIN/soap/test
使用您在 SoapController 类中的 testAction() 代码中的客户端请求中指定的字符串作为消息的一部分来获取成功消息。
让我知道它是否有效,我们可以从那里开始。
我可以在星期一再看一次。
关于php - SOAP 客户端错误 : "Error Fetching Http Headers",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9007391/