php soap 手册,SoapClient::SoapClient

用户评论:

[#1]

omidkosari at yahoo dot com [2015-06-25 16:05:18]

To solve the problem with a lot of FIN_WAIT2 or CLOSE_WAIT , you should use the option keep_alive=false

[#2]

info at nospam x valiton x com [2015-04-20 13:00:45]

CAUTION:

I had quite a bit of trouble trying to make a request with fopen through a proxy to a secure url.  I kept getting a 400 Bad Request back from the remote host.  It was receiving the proxy url as the SNI host.  In order to get around this I had to explicity set the SNI host to the domain I was trying to reach.  It's apparently the issue outlined in this bug:

https://bugs.php.net/bug.php?id=63519

$domain=parse_url($file,PHP_URL_HOST);$proxy_string="tcp://".WP_PROXY_HOST.":".WP_PROXY_PORT;$opts= array('http'=> array('proxy'=>$proxy_string),'ssl'=> array('SNI_enabled'=>true,'SNI_server_name'=>$domain));$context=stream_context_create($opts);$handle=fopen($file,'r',false,$context);?>

src:

http://php.net/manual/en/context.http.php#114314

[#3]

champetier dot etienne at gmail dot com [2015-03-23 14:30:15]

When using classmap, never put a fully qualified classname (starting with \)

there is a bug (https://bugs.php.net/bug.php?id=69280)

[#4]

softontherocks at gmail dot com [2014-12-02 07:38:49]

I posted in this URL http://softontherocks.blogspot.com/2014/02/web-service-soap-con-php.html a full example of a nusoap web service.

There is defined the server and the client who calls the web service.

I hope it would be useful for you.

[#5]

joshua at wiredrive dot com [2014-10-22 23:42:11]

As of 5.5, ssl_method defaults to SOAP_SSL_METHOD_SSLv23. Just wanted to add this because it was not explicitly specified above.

[#6]

Peter [2014-05-08 14:18:57]

if you need to use ws-security with a nonce and a timestamp, you can use this :

private$wss_ns='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd';

private$wsu_ns='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd';

function__construct($user,$pass) {$created=gmdate('Y-m-d\TH:i:s\Z');$nonce=mt_rand();$passdigest=base64_encode(pack('H*',sha1(pack('H*',$nonce) .pack('a*',$created).pack('a*',$pass))));$auth= newstdClass();$auth->Username= newSoapVar($user,XSD_STRING,NULL,$this->wss_ns,NULL,$this->wss_ns);$auth->Password= newSoapVar($pass,XSD_STRING,NULL,$this->wss_ns,NULL,$this->wss_ns);$auth->Nonce= newSoapVar($passdigest,XSD_STRING,NULL,$this->wss_ns,NULL,$this->wss_ns);$auth->Created= newSoapVar($created,XSD_STRING,NULL,$this->wss_ns,NULL,$this->wsu_ns);$username_token= newstdClass();$username_token->UsernameToken= newSoapVar($auth,SOAP_ENC_OBJECT,NULL,$this->wss_ns,'UsernameToken',$this->wss_ns);$security_sv= newSoapVar(

newSoapVar($username_token,SOAP_ENC_OBJECT,NULL,$this->wss_ns,'UsernameToken',$this->wss_ns),SOAP_ENC_OBJECT,NULL,$this->wss_ns,'Security',$this->wss_ns);parent::__construct($this->wss_ns,'Security',$security_sv,true);

}

}?>

and with your SoapClient do :

$client= newSoapClient("http://host/path");$client->__setSoapHeaders(Array(newWsseAuthHeader("user","pass")));?>

works for me. based on a stackoverlfow post which only did the username and password, not the nonce and the timestamp

[#7]

michael dot arnauts at gmail dot com [2014-01-29 15:53:30]

This doesn't seem to be documented, but when you want to use compression for your outgoing requests, you have to OR with the compression level:

$client= newSoapClient("some.wsdl",

array('compression'=>SOAP_COMPRESSION_ACCEPT|SOAP_COMPRESSION_GZIP|9));?>

This can be really usefull if you want to send large amounts of data.

Source: https://bugs.php.net/bug.php?id=36283

[#8]

tolean dot dj at gmail dot com [2013-08-13 14:21:42]

Here's a function for easier debugging:

<?phpfunctionsoapDebug ($client){$requestHeaders=$client->__getLastRequestHeaders();$request=prettyXml($client->__getLastRequest());$responseHeaders=$client->__getLastResponseHeaders();$response=prettyXml($client->__getLastResponse());

echo''.nl2br(htmlspecialchars($requestHeaders,true)) .'';

echohighlight_string($request,true) ."
\n";

echo''.nl2br(htmlspecialchars($responseHeaders,true)) .''."
\n";

echohighlight_string($response,true) ."
\n";

}$client= newSoapClient(null, array('location'=>'http://sita.local/_mpay/server.php','uri'=>'http://sita.local/_mpay/','trace'=>1,

));$result=$client->__soapCall('getDate', array('format'=>'Y-m-d H:i:s'));soapDebug($client);?>

[#9]

miguel dot angel dot fuentes dot casanova at gmail dot com [2013-06-28 07:39:38]

Somebody using SoapClient has sometimes a lot of CLOSE_WAIT states?

It's in a local connection in a openSuse 11 (x86_64, version 11, patchlevel 2) with Apache 2.2.22 and PHP 5.3.15.

[#10]

pgl at yoyo dot org [2013-04-09 12:21:58]

Note that if libxml_disable_entity_loader() has been called, you cannot specify a WSDL file - you'll get an error that PHP "failed to load external entity".

To resolve this, add

libxml_disable_entity_loader(false);?>

Above any calls to instantiate SoapClient.

[#11]

francesco [at] paladinux [dot] net [2013-03-15 20:43:41]

Where you have the problem of

"looks like we got no XML document SoapClient", really the real problem is the xml code from remote server is not clear (after last tag is possible that you have space or other caracter that the your supplier of service have lost :  no one is perfect!)

I've read some solution, like here, but you must to know that is possible, that is possible that the remote server don't wrong, and the "surplus" (latin word for added values) is needed.

In particolar with axis Java server, is possible that the configuration of server is needed and the "surplus" is one or more attachments...

The solution is 3:

1) contact your supplier if is possible to remove caracter if is an error (good luck! ;) )

2) use another class like nusoap resolve the problem (but has other problem!)

3) this technical solution:

when call the wsdl be sure that the option trace and exceptions are setted (the first true and the second false)

$SoapClient= newSoapClient(NULL,

array(

....'trace'=>1,'exceptions'=>0)?>

(if you don't do that you can't use the __getLastResponse)

Now You can do the request and use __getLastResponse() to obtain all the part..

$result=$SoapClient->problematicCall($par);?>

After all  you obtain a variable like that:

-----=_Part_9325_126764118.1363377774664

Content-Type: text/xml; charset=UTF-8

Content-Transfer-Encoding: binary

Content-Id: <1C06F7FBA057796C5A6185605F9F93E4>

<?phpxml  version="1.0" encoding="utf-8"?><...etc><?xml version="1.0" encoding="UTF-8"?>

<MESSAGGIO>

<DA>MI</DA>

<A>PALADINUX</A>

<ID>12345</ID>

<TIPODOC>RC</TIPODOC>

<RISPOSTA>

</MESSAGGIO>

------=_Part_9325_126764118.1234567890123

Content-Type: application/zip

Content-Transfer-Encoding: binary

Content-Id: <43E91F7E7PALADINUXE07BF041A7BAC9>

-------------------------

Is easy understand if the added part is needed or not!

Now you can explode all the part and parse!

Hope this can help you.See ya in the cyberspace!

[#12]

ale dot comp_06 at xox dot ch [2012-06-11 19:56:12]

If your service is protected through basic http authentication and you're not using wsdl, you will have to put the login in the SoapClient's option:

$client= newSoapClient(null,

array('soap_version'=>SOAP_1_2,'location'=> ...

...,'login'=>'username','password'=>'*******',

)

);?>

[#13]

chris at phblock dot atNoSpam [2011-11-04 05:57:45]

this is the syntax of typemap (found at http://svn.php.net/viewvc/php/php-src/trunk/ext/soap/tests/typemap012.phpt?view=markup)

$options=Array('typemap'=> array(

array("type_ns"=>"http://schemas.nothing.com","type_name"=>"soap","to_xml"=>"some_funktion_name")

));?>

[#14]

Chris Gunawardena [2011-08-15 00:56:24]

To monitor SOAP calls in and out of a unix server:

sudo tcpdump -nn -vv -A -s 0 -i eth0 dst or src host xxx.xxx.xxx.xxx and port 80

And always use 'cache_wsdl' => WSDL_CACHE_NONE

[#15]

svenr at selfhtml dot org [2011-07-27 03:51:49]

The "classmap" option actually is a mapping from the "ComplexType" used within the SOAP to your PHP Classes.

Do not confuse the XML tag names returned for your request with these ComplexTypes. SOAP allows them to be different.

I had something like this:

...

FooBar

TagName is not the key you want to put in your classmap, you have to know the name of the ComplexType this TagName refers to. This info is contained inside the WSDL resource.

[#16]

willem dot stuursma at hyves dot nl [2011-05-30 02:00:41]

If you want to use classes in a different namespace in your classmap, just use the backslash in the the target class name.

Example:

$classmap= array('result'=>'MyNamespace\\Result');?>

You need to specify the backslash twice because it is the escape character in strings.

[#17]

simonlang at gmx dot ch [2011-04-06 06:35:28]

Example for a soap client with HTTP authentication over a proxy:

array(// Stuff for development.'trace'=>1,'exceptions'=>true,'cache_wsdl'=>WSDL_CACHE_NONE,'features'=>SOAP_SINGLE_ELEMENT_ARRAYS,// Auth credentials for the SOAP request.'login'=>'username','password'=>'password',// Proxy url.'proxy_host'=>'example.com',// Do not add the schema here (http or https). It won't work.'proxy_port'=>44300,// Auth credentials for the proxy.'proxy_login'=>NULL,'proxy_password'=>NULL,

)

);?>

Providing an URL to a WSDL file on the remote server (which as well is protected with HTTP authentication) didn't work. I downloaded the WSDL and stored it on the local server.

[#18]

Asaf Meller [2011-01-13 05:57:13]

a full working php .net soap configuration :

notes

1. web.config on .net server must work with basichttp binding.

2. paramaters to soap functions must be passed as :

array ('parm1_name'=>'parm1_value',

'parm2_name'=>'parm2_value'...)

header('Content-Type: text/plain');

try {$options= array('soap_version'=>SOAP_1_1,'exceptions'=>true,'trace'=>1,'cache_wsdl'=>WSDL_CACHE_NONE);$client= newSoapClient('http://www.example.com/end_point.wsdl',$options);// Note where 'Get' and 'request' tags are in the XML} catch (Exception $e) {

echo"

Exception Error!

";

echo$e->getMessage();

}

echo'running HelloWorld :';

try {$response=$client->HelloWorld();

}

catch (Exception $e)

{

echo'Caught exception: ',$e->getMessage(),"\n";

}print_r($response);?>

good luck !

Asaf.

[#19]

faebu at faebu dot ch [2010-12-21 06:58:22]

I'm experiencing the same problems when trying to load a WDSL fiel which is protected by basic http authentication, since the parameters login and password are just used for the request but not when reading the wdsl file. I just use the following workaround by downloading the xml file to a non-protected location on my server. Please notice that this doesn't support any kind of caching.

Hope it helps

private$cache_url='http://www.example.com/cache/';

functionSoapAuthClient($wdsl,$options) {

if (isset($options['wdsl_local_copy']) &&$options['wdsl_local_copy'] ==true&&

isset($options['login']) &&

isset($options['password'])) {$file=md5(uniqid()).'.xml';

if (($fp=fopen($this->cache_dir.$file,"w")) ==false) {

throw newException('Could not create local WDSL file ('.$this->cache_dir.$file.')');

}$ch=curl_init();$credit= ($options['login'].':'.$options['password']);curl_setopt($ch,CURLOPT_URL,$wdsl);curl_setopt($ch,CURLOPT_HTTPAUTH,CURLAUTH_BASIC);curl_setopt($ch,CURLOPT_USERPWD,$credit);curl_setopt($ch,CURLOPT_TIMEOUT,15);curl_setopt($ch,CURLOPT_FILE,$fp);

if (($xml=curl_exec($ch)) ===false) {//curl_close($ch);fclose($fp);unlink($this->cache_dir.$file);

throw newException(curl_error($ch));

}curl_close($ch);fclose($fp);$wdsl=$this->cache_url.$file;

}

unset($options['wdsl_local_copy']);

unset($options['wdsl_force_local_copy']);

echo$wdsl;parent::__construct($wdsl,$options);unlink($this->cache_dir.$file);

}

}?>

[#20]

tatupheba at gmail dot com [2010-12-20 14:30:50]

Hello folks!

A hint for developers:

When programming some soap server set the "soap.wsdl_cache_enabled" directive in php.ini file to 0:

soap.wsdl_cache_enabled=0

Otherwise it will give a bunch of strange errors saying that your wsdl is incorrect or is missing.

Doing that will save you from a lot of useless pain.

[#21]

titan at phpdevshell dot org [2010-10-06 06:11:02]

It should be noted that if you receive a return error : 'Object reference not set to an instance of an object.'. This could be due to something as simple as passing the incorrect parameters. When you look at this XML:

string

dateTime

dateTime

Your code should look something like this:

<?phptry  {$options= array('soap_version'=>SOAP_1_2,'exceptions'=>true,'trace'=>1,'cache_wsdl'=>WSDL_CACHE_NONE);$client= newSoapClient('http://example.com/doc.asmx?WSDL',$options);// Note where 'Get' and 'request' tags are in the XML$results=$client->Get(array('request'=>array('CustomerId'=>'1234')));

} catch (Exception $e) {

echo"

Exception Error!

";

echo$e->getMessage();

}$results=$client->Get(array('request'=>array('CustomerId'=>'842115')));?>

[#22]

marcovtwout at hotmail dot com [2010-06-29 08:30:20]

If your WSDL file containts a parameter with a base64Binary type, you should not use base64_encode() when passing along your soap vars. When doing the request, the SOAP library automatically base64 encodes your data, so otherwise you'll be encoding it twice.

WSDL snipplet:

classNTLM_SoapClientextendsSoapClient{

public function__construct($wsdl,$options= array()) {

if (empty($options['proxy_login']) || empty($options['proxy_password'])) throw newException('Login and password required for NTLM authentication!');$this->proxy_login=$options['proxy_login'];$this->proxy_password=$options['proxy_password'];$this->proxy_host= (empty($options['proxy_host']) ?'localhost':$options['proxy_host']);$this->proxy_port= (empty($options['proxy_port']) ?8080:$options['proxy_port']);parent::__construct($wsdl,$options);

}protected functioncallCurl($url,$data) {$handle=curl_init();curl_setopt($handle,CURLOPT_HEADER,false);curl_setopt($handle,CURLOPT_URL,$url);curl_setopt($handle,CURLOPT_FAILONERROR,true);curl_setopt($handle,CURLOPT_HTTPHEADER, Array("PHP SOAP-NTLM Client") );curl_setopt($handle,CURLOPT_RETURNTRANSFER,true);curl_setopt($handle,CURLOPT_POSTFIELDS,$data);curl_setopt($handle,CURLOPT_PROXYUSERPWD,$this->proxy_login.':'.$this->proxy_password);curl_setopt($handle,CURLOPT_PROXY,$this->proxy_host.':'.$this->proxy_port);curl_setopt($handle,CURLOPT_PROXYAUTH,CURLAUTH_NTLM);$response=curl_exec($handle);

if (empty($response)) {

throw newSoapFault('CURL error: '.curl_error($handle),curl_errno($handle));

}curl_close($handle);

return$response;

}

public function__doRequest($request,$location,$action,$version,$one_way=0) {

return$this->callCurl($location,$request);

}

}?>

Requires curl and could be extended, but it works for my simple needs.

[#30]

eric dot caron at gmail dot com [2010-01-31 13:26:09]

Though pointed out by jan at bestbytes, and discussed in bug #27777, one common source of the "Parsing WSDL: Couldn't find " error is from trying to access a WSDL that is protected by HTTP authentication. Passing the login/password in the 2nd parameter doesn't always work; so if you encounter this error message and are trying to access a protected WSDL file, try passing the username and password in with the first parameter.

[#31]

Anonymous [2010-01-10 06:53:14]

I had to struggle with a rather strange behavior when trying to consume standard Parlay X web services with no success. However, I found a remedy to my problem.

The problem which I faced was about an erroneous invalid HTTP basic authentication request sent to the web service. Although I was sending the right credentials, I was getting an authentication error. It turns out that PHP was sending HTTP requests to another endpoint which is not exposed directly through the web service and that end point does not require authentication.

My remedy for that issue was by using this simple lines in the example of using sendSms Paraly-X method.

First, creating a soap client without any HTTP authentication options:

$client= newSoapClient($wsdl_url);?>

The above request will cache the wsdl in the /tmp directory. Immediately after this construction we create another soap client, this time with HTTP authentication options:

<?phptry  {$client= newSoapClient($wsdl_url, array('login'=>"griffin",'password'=>"password"));

} catch (Exception $e) {printf("Error:sendSms: %s\n",$e->__toString());

returnfalse;

}?>

Now it should work without any problem. Without the second call, PHP will call sendSms without credentials resulting in a failed attempt due to missing authentication information. I found this procedure to be the simplest.

This process should be done every time the cached wsdl expires, or simply a one can increase the time-to-live for the cached wsdl from php.ini

[#32]

jon dot gilbert at net-entwicklung dot de [2009-12-12 09:55:45]

Note that creating a soap client for an invalid URL (you do test what happens, when a service is not available, right?) usually throws an exception which can be caught with try..catch. However, if xdebug is active you will get a fatal error, which obviously cannot be caught.

[#33]

sloloem at gmail dot com [2009-10-19 13:14:30]

I had an issue figuring out the use of classmap that took me quite a while to figure out.  I was assuming the WSDL type the docs were referring to was the name of the element being returned in the SOAP, so like,

and I was wondering why mapping

'classmap'=>array('node'=>'MyNode')

did nothing.

That's because in my WSDL I defined node as:

The classmap I needed was:

'classmap'=>array('nodeType'=>'MyNode')

I was able to find the type names using SoapClient->__getTypes()

Later, I realized where I could look inside the WSDL for the typename I needed.

I dunno if I missed something painfully obvious but maybe this can clear up some of the docs.

[#34]

Jon [2009-05-06 03:13:29]

We've had some problems using SoapClient connecting to an external server via Microsoft ISA (presently v.2006 but this may apply to other versions too). We supply the proxy_host, proxy_port, proxy_login and proxy_password but the ISA server reports the login in its logs as "anonymous".

Our sysadmin believes this is because PHP is not supplying NTLN information (Windows security protocol) in the correct format (and whether it should work with proprietary proxies is of course another debate). We'd tried "username", "DOMAIN\username" to no effect. The solution is to add an exception in the ISA server for the target hostname/IP; null can then be supplied for proxy_login and proxy_password and the connection should then work as expected.

On a slightly related note, if you are having problems make sure the port number is supplied as an integer. Some versions of PHP will not use the proxy with SoapClient if the port number is supplied as a string.

[#35]

jan at bestbytes dot de [2009-02-12 07:32:15]

You CAN get a wsdl, if basic authentication is required:

$login='bert';$password='berts password';$client= newSoapClient('http://'.urlencode($login) .':'.urlencode($password) .'@www.server.com/path/to/wsdl',

array('login'=>$login,'password'=>$password)

);?>

[#36]

info at nicksilvestro dot net [2008-11-09 22:40:37]

For anyone having trouble with ArrayOf_xsd_string and getting an error similar to 'No deserializer defined for array type {http://www.w3.org/2001/XMLSchema}string'

Try using the 'features' param, set to SOAP_USE_XSI_ARRAY_TYPE - this makes sure the correct deserializer is used.

eg,

$client= newSoapClient("some.wsdl", array('features'=>SOAP_USE_XSI_ARRAY_TYPE));?>

[#37]

sniper [2008-09-27 23:46:54]

i was looking for a good example and couldnt find one,

finally found it somewhere(forgot where) i think this is

the best example to make a soap request with multiple params

$params->AWSAccessKeyId = AMAZON_API_KEY;

$params->Request->SearchIndex = 'Books';

$params->Request->Keywords = 'php5 oop';

$amazon = new SoapClient('http://webservices.amazon.com

/AWSECommerceService/AWSECommerceService.wsdl');

$result = $amazon->itemSearch($params);

[#38]

taras dot dot dot di at gmail dot com [2008-09-16 09:23:44]

This took me a while to figure out.

As described at the bottom of here: http://bugs.php.net/bug.php?id=38703

having xdebug may interfere with the constructor throwing exceptions

[#39]

alex on reutone comma com [2008-09-10 06:53:03]

To connect PHP SOAP to MS SOAP (CRM/EXCHANGE/...) I have created some classes using the explanation below and in other places.

www.reutone.com/heb/articles.php?instance_id=62&actions=show&id=521

[#40]

naugtur at gmail dot com [2008-06-19 06:48:03]

SoapFault exception: [Client] looks like we got no XML document in  has been already mentioned to occur when your server outputs something before <?xml  ... > tag.

For all those having problems with that, and no access to the server code:

This is how to make a proxy that would clean responses for You

protected$cacheDocument="";

public function__construct($wsdl,$options) {parent::__construct($wsdl,$options);

}public functionSetCacheDocument($document) {$this->cacheDocument=$document;

}public function__doRequest() {

return$this->cacheDocument;

}

}//put this code in your function or wherever You have all required variables set$client= newSoapClient($wsdl_url,$settings_array);$void=$client->$method($params);//call this to get response from server$response_string=$client->__getLastResponse();//this part removes stuff$start=strpos($response_string,'<?xml ');$end=strrpos($response_string,'>');$response_string=substr($response_string,$start,$end-$start+1);//get your proxy prepared$proxy= newProxy_Client($wsdl_url,$settings_array);//and fill it with the server's response$proxy->SetCacheDocument($response_string);$and_finally_the_result_is=$proxy->$method($params);print_r($and_finally_the_result_is);//this allows You to see what's there?>

$method is the method's name eg. $method='getVersion';

$params - typical params for a soap method

[#41]

david at globulebleu dot com [2008-06-09 00:44:45]

When using classmap option to map the SOAP results to a class, the constructor

of the object you've mapped to is not called.

$client = new SoapClient("url_to_wsdl",

array('classmap' => array('contact' => "Contact"));

$params = array("1");

$contact = $client->__soapCall("get_contact", $params);

Expected result:

A contact object that has properties initialized (i.e. db connections,

....).

Actual result:

A contact object without the properties.

Thanks for your help.

David Georges.

[#42]

Anno v. Heimburg [2008-05-27 10:23:40]

> When using HTTP basic authentication, PHP will only send

> the credentials when invoking the service, not when

> fetching the WSDL.

The same goes for using an SSL client certficate, the SoapClient will only present the certificate on the actual remote call, not when getting the WSDL. The workaround is the same as above. HttpRequest works as expected.

[#43]

cw at netresearch dot de [2008-04-30 01:24:24]

The "cache_wsdl" option takes constants like WSDL_CACHE_NONE or WSDL_CACHE_DISK that are listed on the "SOAP constants" page -> /manual/en/soap.constants.php

[#44]

james dot ellis at gmail dot com [2008-01-29 17:10:21]

A note regarding boolean values that may seem obvious on reflection but could be a gotcha for some:

Seeing a SOAP request example with true may lead you to pass in string "true" or "false" as the parameter, which is incorrect - the correct method is to use boolean data types.

$client= newSoapClient($wsdl,$options);$method="DoSomething";$params= newstdClass;$params->SomeBooleanParam=TRUE;$client->$method($params);//this will also be correct, but not for the right reasons:$params->SomeBooleanParam="true";$client->$method($params);//this is where you may be wondering what is going on$params->SomeBooleanParam="false";$client->$method($params);//you need to do this instead$params->SomeBooleanParam=FALSE;$client->$method($params);?>

Hope that helps!

[#45]

giosh94mhz [2007-07-08 11:46:53]

Oops!

I have written the wrong exception message in my last post.

The correct exception is:

SoapFault exception: [Client] looks like we got no XML document in 

[#46]

lsmith at php dot net [2007-02-08 07:20:57]

As noted in the bug report http://bugs.php.net/bug.php?id=36226, it is considered a feature that sequences with a single element do not come out as arrays. To override this "feature" you can do the following:

$x = new SoapClient($wsdl, array('features' =>

SOAP_SINGLE_ELEMENT_ARRAYS));

[#47]

matt_schiros at academicsuperstore dot com [2006-11-30 12:26:40]

When using classmap to map the SOAP results to a class, the constructor of the object you've mapped to is _not_ called.  This applies to the PHP5 __construct() and the PHP4 ClassName() constructors.

[#48]

Marius Mathiesen [2006-03-01 04:57:51]

I kept having a problem using an HTTP proxy with SOAP. The proxy_port parameter has to be an integer, ie. "proxy_port"=>"80" won't work, you'll have to use "proxy_port"=>80.

HTH,

Marius

[#49]

php at sowen dot de [2005-12-22 06:40:42]

If you're using CLI and there are multiple IP addresses available for outgoing SOAP-requests, try this "secret" to set outgoing IP:

e.g. for local IP 10.1.4.71:

$opts = array('socket' => array('bindto' => '10.1.4.71:0'));

$context = stream_context_create($opts);

$client  = new SoapClient(null, array('location'=>'http://...','uri' => '...','stream_context' => $context));

You can also set other options for the stream context, please refer to this page:

Appendix M: http://www.php.net/manual/en/wrappers.php

Bye,

Nils Sowen

[#50]

jared at ws-db dot com [2005-08-28 14:31:11]

If you connect to a SoapServer, that has been created with session persistence, you can access the server's session id via SoapClient->_cookies[][0]. This property becomes available after your first client method call.

I have only tested this with session.use_cookies=1.

[#51]

Arjan van Bentem [2005-08-11 23:31:42]

When using HTTP basic authentication, PHP will only send the credentials when invoking the service, not when fetching the WSDL.

To solve this, one needs to fetch the WSDL manually (or using PHP, of course!) and store it on the file system. Obviously, the first parameter for SoapClient(..) then needs to refer to that local copy.

Alternatively, the user annotations at http://nl3.php.net/manual/en/ref.soap.php state that one could encode the login and password into the URL as well.

See http://bugs.php.net/bug.php?id=27777

[#52]

Jim Plush [2005-07-11 12:56:04]

As of version 5.0.4 you can now dynamically change your location even if you're using a wsdl

$client= newSoapClient("http://some.host.net/wsdl/somefile.wsdl",array("location"=>'myurl.com'));?>

notice you can now use the "location" key.

This means you can have the same wsdl file not define a location until runtime which is great if you have a development test site or if you distribute your files to other companies.

Prior to this change you would have to ship a custom wsdl file to every client you had with their location hardcoded.

[#53]

Brian Grayless [2005-03-04 14:30:43]

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:

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.

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值