-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo3.php
85 lines (76 loc) · 3.6 KB
/
demo3.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
// This demonstrates how I get around a really nasty problem: If the
// SOAP client won't send a parameter when the value is NULL, the
// SoapServer will fail with "Missing parameter" when giving the WSDL
// in the first parameter of the SoapServer constructor. If you give
// NULL as first parameter to the SoapServer constructor, your method
// will be called with a wrong parameter order.
//
// With the PhpWsdlProxy class I try to get around the problem, but
// complex type return values must be returned with PHPs SoapVar
// object then. Primitive return types like string, int or boolean don't
// need a special handling.
// To get rid of the NULL problem you need to ensure that the PHP
// SoapServer has no knowledge of the WSDL. To ensure this, set the
// PhpWsdl::$UseProxyWsdl property to FALSE (is FALSE per default).
//
// If you want to mix class and global methods, you need to use the proxy.
// Include the demonstration classes
require_once('class.soapdemo.php');
require_once('class.complextypedemo.php');
// Initialize the PhpWsdl class
require_once('class.phpwsdl.php');
PhpWsdlMethod::$DefaultException='SoapFault';// This will set SoapFault as exception type for all methods
PhpWsdl::$UseProxyWsdl=true; // Comment this line out to get rid of "Missing parameter" exceptions and to use the method "AnotherDemoMethod" exported by the class "SecondClass"
$soap=PhpWsdl::CreateInstance(
null, // PhpWsdl will determine a good namespace
null, // Change this to your SOAP endpoint URI (or keep it NULL and PhpWsdl will determine it)
'./cache', // Change this to a folder with write access
Array( // All files with WSDL definitions in comments
'class.soapdemo.php',
'class.complextypedemo.php',
__FILE__ // To include the global method example at the end of this file
),
null, // The name of the class that serves the webservice will be determined by PhpWsdl
null, // This demo contains all method definitions in comments
null, // This demo contains all complex types in comments
false, // Don't send WSDL right now
false); // Don't start the SOAP server right now
// Disable caching for demonstration
ini_set('soap.wsdl_cache_enabled',0); // Disable caching in PHP
PhpWsdl::$CacheTime=0; // Disable caching in PhpWsdl
// Run the SOAP server
if($soap->IsWsdlRequested())
$soap->Optimize=false; // Don't optimize WSDL to send it human readable to the browser
$soap->RunServer( // Finally, run the server and enable the proxy
null,
Array( // Use an array for this parameter to enable the proxy:
'SoapDemo', // The name of the target class that will handle SOAP requests
new SoapDemo() // An instance of the target class that will handle SOAP requests
)
);
/**
* This is how to define a global method for WSDL
*
* @return string Response
* @pw_set global=1 -> Tell PhpWsdl to serve this as global method (outside of a class)
*/
function GlobalMethodDemo(){
return utf8_encode('Response of the global method demo');
}
// If you want PhpWsdl to handle all methods as global per default, set the
// PhpWsdlMethod::$IsGlobalDefault to TRUE. Then you don't need to set the
// setting "global" to "1" for every method.
class SecondClass{
/**
* This method is in another class
*
* @param string $str A string
* @return string The input string
*/
public function AnotherDemoMethod($str){
return $str;
}
}
// If you want to export handler methods from different classes, ensure that
// the PHP SoapServer won't get the WSDL