簡體   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