将SoapClient请求绑定到特定IP

时间:2010-09-21 15:27:24

标签: php soap soap-client

我需要实现一个网络服务,其中SoapServer要求我使用具有一堆不同IP的SoapClient计算机上的特定IP发送数据。问题是,如何强制PHP使用这个特定的IP发送该请求?

关于SOAP的PHP文档非常糟糕。

感谢。


有了halfdan的答案,我能够解决这个问题,所以我发布了一个结果如何:

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");
        }

    }
}

1 个答案:

答案 0 :(得分:4)

这应该有效(见#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));

我同意文档应该包含此选项。