开发者

Bind SoapClient request to a specific IP

I need to implement a webservice where the SoapServer requires me to send data using a specific IP at the SoapClient machine which have a bunch of different IPs. Problem is, how to force PHP to send that request using this specific IP?

PHP documentation on SOAP is really poor.

Thanks.


With halfdan's answer i was able to fix the issue, so i'm posting a snippet of how it turned out:

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,
                开发者_StackOverflow社区"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");
        }

    }
}


This should work (see #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));

I agree that the documentation should include this option.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜