note 50621 added to function.soap-soapclient-construct

From: Date: Fri, 04 Mar 2005 22:30:45 +0000
Subject: note 50621 added to function.soap-soapclient-construct
Groups: php.notes 
Request: Send a blank email to php-notes+get-85950@lists.php.net to get a copy of this message
Using a WSDL file is the way to go, however, for my particular application, the LOCATION:PORT needed to be dynamic so that my SOAP clients would be able to call a different service based on the client domain. If you are using a WSDL, SoapClient() requires a URL direct to an actual URL and does not let you use a PHP file that outputs the dynamic WSDL XML in its stead. So, I ended up making a separate WSDL for each possible service needed and had to maintain them all if the service description changed. Finally, after some fiddling, I was able to create a PHP page with the proper Mime type headers so that I could then trick SoapClient() to think that it was being passed a file with a ".wsdl" extension. Example: <?php // filename: wsdl.php header('Content-Type: application/xml; charset=UTF-8'); header('Content-Disposition: attachment; filename="filename.wsdl"'); $wsdl = 'path/wsdl_name.wsdl'; // read in file $handle = fopen($wsdl, "r"); $wsdl_xml = fread($handle, filesize($wsdl)); fclose($handle); // put code here to replace url and port in xml echo $wsdl_xml; ?> Now, in order to make this work, you can't just call a relative path to the file. I believe it has to go through Apache to properly set the mime type headers, etc... So you would use a full "http://....." address as the path to the wsdl.php file. <?php //... somewhere in your soap client code $wsdl_loc = "http://yourdomain.com/wsdl.php"; $soap_client = new SoapClient($wsdl_loc, $client_param_array); ?> Another, perhaps not so clean, way of achieving this would be to modify your .htaccess file in the directory where your WSDL file exists to force ".wsdl" files to run through the PHP engine. Add the following to your .htaccess: AddType application/x-httpd-php .php .wsdl You can then put dynamic PHP code snippets in your *.wsdl files to change whatever values you need to. There are pros and cons to each solutions. The Mime solution probably taxes the system more as it has to read the file in every time a soap request is made. The htaccess solution makes it so you have to depend on either a modified .htaccess or Apache conf file. Perhaps if you set the "soap.wsdl_cache_enabled", using ini_set(), to 1 (default), the caching will make it so it doesn't read the file every time for the Mime solution. ---- Manual Page -- http://www.php.net/manual/en/function.soap-soapclient-construct.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+50621 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+50621&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+50621&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+50621&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+50621&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+50621&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+50621&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#85950) next »