views:

42

answers:

1

Hi,

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

    }
}
+2  A: 

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.

halfdan
Thanks for your suggestion, however i'm getting a error, i get: `SOAP-ENV:Client: Operation '' is not defined in the WSDL for this service` when doing a call now
Rodrigo
$wsdl needs to be your WSDL. It was just placed in this example script because it needs to be given to SoapClient on instantiation.
halfdan
yeah, i have it implemented as you said the problem is that if i assign a port it gives that error, if i just fill up the ip it works, apparently a port must be defined at the original wsdl.
Rodrigo