我正在尝试从HTTPS服务器获取WSDL的内容
<?php
echo file_get_contents("https://zendsoap.lan/Zend_Soap_Server.php?wsdl");
?>它返回:
警告: file_get_contents()函数.file-get-contents: SSL操作失败,代码为% 1。OpenSSL错误消息:错误:1408E0F4:SSL例程:func(142):/Applications/AMPPS/www/zendSoap.lan/Zend_Soap_Client.php中第4行的原因(244)
警告: file_get_contents()函数.file-get-contents:无法在第4行的/Applications/AMPPS/www/zendSoap.lan/Zend_Soap_Client.php中启用加密
警告: file_get_contents(https://zendsoap.lan/Zend_Soap_Server.php?wsdl)函数。file_get_contents-get-contents:无法打开流:第4行上的文件中的操作失败
当我可以转到WSDL位置(https://zendsoap.lan/Zend_Soap_Server.php?wsdl)时:一切看起来都很好。
附言:谁能告诉我怎样才能共享WSDL文件
发布于 2013-01-16 23:28:57
我同意RockyFord关于SSL的问题(我非常肯定你会有一个自签名证书,由于使用SSL,你需要采取一些步骤来最小化安全问题)。对于直接的问题,您可以尝试使用类似如下的代码来修复它:
$url = 'https://zendsoap.lan/Zend_Soap_Server.php?wsdl';
$contextOptions = array(
'ssl' => array(
'verify_peer' => true,
'CN_match' => 'zendsoap.lan' // assuming zendsoap.lan is the CN used in the certificate
)
);
$sslContext = stream_context_create($contextOptions);
$wsdlContent = file_get_contents($url, NULL, $sslContext);(更新:将上面的代码更改为
'verify_peer' => false虽然它对于基本的开发来说可能是可以的,但它确实不是一个好主意,绝对不应该在生产环境中使用,因为它引入了严重的安全问题-有关这个主题的更多信息,请参阅上的这篇优秀的文章以及OWASP的和 )
要了解您关于在Zend Framework应用程序中共享WSDL的观点,您可以这样开始:
// go to application/configs/application.ini
// if your APPLICATION_ENV is development then add the following line in the development section:
phpSettings.soap.wsdl_cache_enabled = 0上面的代码行将防止wsdl在开发过程中被缓存。接下来,您可能想要创建一个SoapController,并像这样添加此操作:
public function serverAction()
{
$baseUrl = 'http://zendsoap.lan/soap/server';
if( isset( $_GET['wdsl'] ) ) {
$strategy = new Zend_Soap_Wsdl_Strategy_AnyType();
$server = new Zend_Soap_AutoDiscover($strategy);
$server->setUri($baseUrl);
$server->setClass('Application_Model_Web_Service');
$server->handle();
} else {
$server = new Zend_Soap_Server($baseUrl . '?wsdl');
$server->setClass('Application_Model_Web_Service');
$server->handle();
}
}上述方法的好处是将为您动态生成WSDL。您可能已经注意到,调用setClass()方法时会将'Application_Model_Web_Service‘作为唯一的参数进行传递。要测试您的配置,我建议您创建该类并插入下面的方法。使用包含单个方法的简单服务测试您的配置将有助于您在使服务变得更加复杂之前进行故障排除。下面是示例方法:
// Note: you should definitely comment your methods correctly in the class so
// the WSDL will be generated correctly - by that I mean use @param and @return
// so the correct input and output types can be determined and added to the WSDL
// when the the ZF component generates it for you
/**
* @return string
*/
public function getMessage()
{
return 'ok';
}(更新:还回答了你提出的关于使用Zend_Soap_Client访问web服务的问题,因为看起来你打算让它成为一个安全的服务,我建议你提出一个关于用php设置安全soap服务的单独问题。如果你在这个问题中更多地解释你正在尝试做什么,你可能会从一系列专家那里得到一些关于最佳实践的很好的意见:-)
)
我知道你是新手,所以如果你对答案感到满意,你可以接受它,而且一般来说,最好是只回复一个答案,而不是添加另一个答案来回复。当然,当你知道怎么做的时候很容易,当别人告诉你的时候更容易;-)
发布于 2013-01-18 03:17:31
我尝试了您定义Soap服务器的方法,唯一的问题是我使用了我的自定义类,而不是使用Application_Model_Web_Service。我对客户端和服务器使用单个文件。当我在不使用wsdl的情况下运行https://zendsoap.lan/Zend_Soap_Server.php时,结果如下:
<SOAP-ENV:Envelope>
<SOAP-ENV:Body>
<SOAP-ENV:Fault>
<faultcode>WSDL</faultcode>
<faultstring>SOAP-ERROR: Parsing WSDL: Couldn't load from 'https://zendsoap.lan/Zend_Soap_Server.php?wsdl' : failed to load external entity "https://zendsoap.lan/Zend_Soap_Server.php?wsdl"
</faultstring>
</SOAP-ENV:Fault>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>当我按照您所说的方式尝试file_get_contents()时,我得到的结果是:
Warning: file_get_contents() [function.file-get-contents]: SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:func(144):reason(134) in /Applications/AMPPS/www/zendSoap.lan/https_soap_test.php on line 16
Warning: file_get_contents() [function.file-get-contents]: Failed to enable crypto in /Applications/AMPPS/www/zendSoap.lan/https_soap_test.php on line 16
Warning: file_get_contents(https://zendsoap.lan/Zend_Soap_Server.php?wsdl) [function.file-get-contents]: failed to open stream: operation failed in /Applications/AMPPS/www/zendSoap.lan/https_soap_test.php on line 16以下是我的证书屏幕截图的链接:http://i.stack.imgur.com/bKoVD.png
非常感谢你的帮助。
发布于 2013-01-18 03:53:49
已通过更改'verify_peer‘=> false解决问题
你能(@dkcwd)告诉我如果我使用不带file_get_contents()的Zend_Soap_Client,代码应该是什么?我的意思是,有没有什么办法是我在网上找不到的,可以做一些类似'verify_peer‘=> false的事情。
非常感谢@dkcwd
更新:让我总结一下我到底在做什么,我正在尝试创建一个基于SSL的基本SOAP服务器。在我的生产网站上提供Web服务之前,我必须用has got Signed Certificate (它的身份验证现在是一个问题)在开发系统上测试它。以下是我在这方面面临的问题:
SOAP-错误:解析WSDL:无法从'https://zendsoap.lan/Zend_Soap_Server.php?wsdl‘加载:未能加载外部实体"https://zendsoap.lan/Zend_Soap_Server.php?wsdl“是我应该
这个东西在NuSoap上运行得很好,但是对于我们运行PHP5.4.6的服务器来说,NuSoap中的大多数东西都是不推荐的,所以对我来说最可靠的解决方案是使用PHP扩展。我使用 Zend 的原因是我们正在将我们的系统从一些第三方框架转移到Zend框架,每天我都会收到来自客户端的请求来添加这个&那个新的组件,我假设如果我使用Zend库开发来自客户端的每个新请求,那么在以后的阶段对我来说很容易转移到Zend框架。
我希望我说的有点道理。
非常感谢你……
https://stackoverflow.com/questions/14360111
复制相似问题