繁体   English   中英

Soap Client调用SSL

[英]Soap Client Call to SSL

我正在尝试从HTTPS服务器获取WSDL的内容

<?php
echo file_get_contents("https://zendsoap.lan/Zend_Soap_Server.php?wsdl");
?>

返回:

警告:file_get_contents()[function.file-get-contents]:SSL操作失败,代码为1。OpenSSL错误消息:/ Applications / AMPPS / www /中的错误:1408E0F4:SSL例程:func(142):reason(244)第4行的zendSoap.lan / Zend_Soap_Client.php

警告:file_get_contents()[function.file-get-contents]:无法在第4行的/Applications/AMPPS/www/zendSoap.lan/Zend_Soap_Client.php中启用加密

警告:file_get_contents(https://zendsoap.lan/Zend_Soap_Server.php?wsdl)[function.file-get-contents]:无法打开流:在/Applications/AMPPS/www/zendSoap.lan/Zend_Soap_Client.php中操作失败在第4行

并且当我可以转到WSDL位置(https://zendsoap.lan/Zend_Soap_Server.php?wsdl)时:一切看起来都很好。

PS:有人可以告诉我如何共享WSDL文件吗?

我同意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

虽然可以进行基本开发,但这并不是一个好主意,并且绝对不应该在生产环境中使用,因为它会带来严重的安全问题-请参阅这篇出色的文章,内容涉及如何通过以下方式正确地保护来自PHP代码的SSL上的远程API调用:有关此主题的更多信息,请参见Artur Ejsmont ,以及OWASP的传输层安全备忘单保护Web服务安全

要了解有关在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 Server的方法,唯一的是我使用了自定义类而不是使用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

感谢您的帮助。

通过更改'verify_peer'=> false解决了问题

如果我不使用file_get_contents()使用Zend_Soap_Client,可以(@dkcwd)告诉我代码是什么。 我的意思是,有什么我在互联网上找不到的选项可以做类似于'verify_peer'=> false的事情。

感谢@dkcwd

更新:让我总结一下我到底在做什么,我正在尝试通过SSL创建一个基本的SOAP服务器。 在我的生产网站上提供Web服务之前,我必须在开发系统上对其进行测试,并获得“自签名证书”(其身份验证现在是一个问题)。 以下是我在这方面面临的问题:

  1. 当我尝试调用https://zendsoap.lan/Zend_Soap_server.php?wsdl时,它的工作正常,我可以查看wsdl。
  2. 但是当我尝试https://zendsoap.lan/Zend_Soap_server.php时 ,我得到了:

    SOAP错误:解析WSDL:无法从'https://zendsoap.lan/Zend_Soap_Server.php?wsdl'加载:无法加载外部实体“ https://zendsoap.lan/Zend_Soap_Server.php?wsdl”我应该是

  3. 我在开发服务器上运行它时将我设置verify_peer => false的原因是,因此无需验证自己创建的证书,但是显然在生产中,我希望对证书进行验证。

这个东西可以在NuSoap上正常工作,但是NuSoap中的大多数东西对于运行PHP 5.4.6的服务器已被弃用,因此使用PHP的SOAP扩展对我来说是最可靠的解决方案。 我使用Zend的原因是我们正在将系统从某些第三方框架迁移到Zend框架,并且每天我都会收到来自客户的添加该新组件的请求,我假设如果我开发了来自客户的每个新请求,使用Zend库,在以后的阶段中,我很容易迁移到Zend Framework。

我希望我在那里有意义。

提前谢谢了...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM