2010-09-21 53 views
1

我需要實現一個web服務,其中SoapServer要求我在SoapClient機器上使用特定IP發送數據,這些機器上有許多不同的IP。問題是,如何強制PHP使用此特定IP發送該請求?將SoapClient請求綁定到特定的IP

有關SOAP的PHP文檔非常差。

謝謝。


隨着哈夫丹的回答我能解決這個問題,所以我張貼的是如何變成了一個片段:

protected function load_ws() { 
    if ($this->ws == null) { // load webservice 

     ini_set("soap.wsdl_cache_enabled", 0); 
     ini_set("allow_url_fopen", 1); 

     try { 
      if ($this->context == null) // load stream context socket 
       $this->context = stream_context_create(array(
        "socket" => array(
         "bindto" => te_auth_ip.":0" 
        ) 
       )); 

      $this->ws = new SoapClient($this->wsdl_path, array(
       "soap_version" => SOAP_1_1, 
       "style" => SOAP_RPC, 
       "use" => SOAP_ENCODED, 
       "authentication" => SOAP_AUTHENTICATION_BASIC, 

       "login" => te_login, 
       "password" => te_pass, 

       "encoding" => "UTF-8", 
       "trace" => true, 
       "exceptions" => true, 
       "compression" => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP, 
       "connection_timeout" => te_timeout, 
       "stream_context" => $this->context 
      )); 

     } catch (SoapFault $fault) { 
      $this->error($fault, "LOAD"); 
     } 

    } 
} 
+0

我的建議工作? – halfdan 2010-09-21 16:36:30

回答

3

這應該工作(見#60004):

$options = array('socket' => array('bindto' => 'www.xxx.yyy.zzz:port')); 
$context = stream_context_create($options); 
$soap = new SoapClient($wsdl, array('location'=>'http://...','uri' => '...','stream_context' => $context)); 

我同意文檔應該包含此選項。

+0

感謝您的建議,但是我收到一個錯誤消息,我得到:現在進行調用時,沒有在WSDL中爲此服務定義'SOAP-ENV:Client:Operation' – Rodrigo 2010-09-21 18:09:13

+0

$ wsdl需要是您的WSDL 。它只是放在這個示例腳本中,因爲它需要在實例化時賦予SoapClient。 – halfdan 2010-09-21 18:36:31

+0

是的,我有它的實現,因爲你說的問題是,如果我分配一個端口它給出了這個錯誤,如果我只是填滿它的IP它的工作,顯然一個端口必須在原始wsdl定義。 – Rodrigo 2010-09-21 18:43:19

相關問題