Description of the nusoapwsdl file .. My server is created as follows: App: import ('bad', 'nusoap/lib/nusoap '); $ server = newsoap_server; & nbsp; $ server-& gt; configureWSDL ('sum'); $ description of the serv nusoap wsdl file ..
My server is created as follows:
App: import ('upload', 'nusoap/lib/nusoap ');
$ Server = new soap_server;
$ Server-> configureWSDL ('sum ');
$ Server-> register ('sum', array ('x' => 'xsd: String', 'y' => 'xsd: String '), array ('Return '=> 'xsd: String'), '', 'http: // localhost/ws/info/sum ');
$ HTTP_RAW_POST_DATA = isset ($ HTTP_RAW_POST_DATA )? $ HTTP_RAW_POST_DATA :'';
$ Server-> service ($ HTTP_RAW_POST_DATA );
// $ This-> set ('data', $ server );
$ This-> autoRender = false;
Enter
Http: // localhost/ws/info? Wsdl
The returned xml information contains this sentence.
Can we set the value of soap: address location when creating $ server, because errors may occur when cakephp is used by default ..
------ Solution --------------------
For example:
PHP calls the Webservice instance and you will understand it after reading it.
NuSoap is a WebService programming tool in the PHP environment. it is used to create or call WebService. It is an open source software, is fully written in PHP language, through HTTP to send and receive SOAP messages of a series of PHP class, developed by NuSphere Corporation (http://dietrich.ganx4.com/nusoap. One advantage of NuSOAP is that it does not require the support of extension libraries. This feature allows NuSoap to be used in all PHP environments and is not affected by server security settings.
Many friends who use NuSoap to call. NET WebService or J2EE WebService may have encountered Chinese garbled characters. The following describes the causes and solutions of this problem.
Reasons for garbled WebService calling by NuSoap:
Usually we do WebService development is used for UTF-8 encoding, then we need to set:
$ Client-> soap_defencoding = 'utf-8 ′;
At the same time, xml must be transmitted in the same encoding mode:
$ Client-> xml_encoding = 'utf-8 ′;
At this point, everything is normal, but when we output the results, we find that the returned code is garbled.
Solution to WebService call garbled by NuSoap:
In fact, a friend who has enabled the debugging function will find that $ client-> response returns the correct result. why $ result = $ client-> call ($ action, array ('parameters '=> $ param); is it garbled?
After studying the NuSoap code, we will find that when xml_encoding is set to UTF-8, NuSoap will detect the decode_utf8 setting. if it is true, it will execute the utf8_decode function in PHP, nuSoap is set to true by default. Therefore, we need to set:
NuSOAP is a WEB service programming tool in the PHP environment. it is used to create or call WEB services. It is an open-source software. The current version is 0.7.2. it supports SOAP1.1 and WSDL1.1 and can interoperate with other systems that support SOAP1.1 and WSDL1.1. NuSOAP is completely compiled by the PHP language and consists of a series of PHP classes without the support of extension libraries. This feature allows NuSOAP to be used in all PHP environments and is not affected by server security settings.
1. obtain and install NuSOAP
The NuSOAP project is built on SourceForge and the network address is: http://sourceforge.net/projects/nusoap/, where you can download to the latest version of NuSOAP.
The installation of NuSOAP is relatively simple. copying the downloaded NuSOAP file to the server can be stored in an independent directory or in the same directory as the program code, as long as your PHP code can access these files.
The test environment in this article is based on PHP4.3.2 and NuSOAP 0.7.2. NuSOAP is installed in the "/nusoap" WEB directory and has two subdirectories: lib and samples. Among them, the lib Directory stores all the source code files of NuSOAP, and the samples directory contains some examples provided by the NuSOAP development team. The test file is stored in the "/nusoap" WEB directory.
2. use of NuSOAP
NuSOAP is composed of PHP classes, the most common of which are soap_server classes and soalclient classes. The class soap_server is used to create WEB services, and the class soapclient is used to access WEB services.
2.1 A simple example: Hello World
In this example, a simple WEB service is created using NuSOAP, and a client program is created using NuSOAP to call this service. The only function of this service is to return a string "Hello World" to the client ". First, create the WEB service program code File "/nusoap/nusoap_server1.php ":
// Include the source file of NuSOAP into the current code file
Require_once ("lib/nusoap. php ");
// Define the Service Program
Function hello (){
Return 'Hello World! ';
}
// Initialize the service object, which is an instance of the soap_server class
$ Soap = new soap_server; // call the register method of the service object to register the program to be accessed by the client.
// Only registered programs can be accessed by remote clients.
$ Soap-> register ('Hello'); // The last step is to pass the data submitted by the client in post mode to the service method of the service object.
// The service method processes the input data, calls the corresponding function or method, generates correct feedback, and returns it to the client.
$ Soap-> service ($ HTTP_RAW_POST_DATA );
?> Now, the WEB service program code file has been created. Next, create a client program code File "/nusoap/nusoap_client1.php" and call the WEB service:
// Include the source file of NuSOAP into the current code file
Require_once ("lib/nusoap. php ");
// Initialize the client object, which is an instance of soapclient class,
// Pass the URL of the service program to the constructor of the soapclient class.
$ Client = new soapclient ('http: // 127.0.0.1/nusoap/nusoap_server1.php '); // call the WEB service program using the call method of the client object
$ Str = $ client-> call ('Hello'); // The getError () method of the client object can be used to check whether an error occurs during the call.
// If there is no error, the getError () method returns false; if there is an error, the getError () method returns an error message.
If (! $ Err = $ client-> getError ()){
Echo "program return:", htmlentities ($ str, ENT_QUOTES );
} Else {
Echo "error:", htmlentities ($ err, ENT_QUOTES );
}
?> Now, the client program has been established. open the browser, access the client program, and check the result. In this example, the browser will display a string: "The program returns: Hello World! "
2.2 Methods for passing parameters and returning error messages
The example shows how to pass parameters and return error messages. In this example, two strings are connected. the parameters are two strings, and the returned values are strings connected by two parameters. First, create the service program code File "/nusoap/nusoap_server2.php". the complete code is as follows:
Require_once ("lib/nusoap. php ");
Function concatenate ($ str1, $ str2 ){
If (is_string ($ str1) & is_string ($ str2 ))
Return $ str1. $ str2;
Else
Return new soap_fault ('client', ", 'parameters of the concatenate function should be two string ');
}
$ Soap = new soap_server;
$ Soap-> register ('concatenate ');
$ Soap-> service ($ HTTP_RAW_POST_DATA );
?> Compared with the code of the WEB service program in section 2.1, the code structure here is roughly the same. Note the following:
Different service programs have two parameters. The process of registering a service program using NuSOAP is the same. The register method of the service object is called.
Here we use a new NuSOAP class soap_fault. When either of the two parameters is not a string, the program returns the error message to the client through this class. The constructor of this class has four parameters:
Fault
Code
Required parameter. the recommended value is "Client" or "Server", indicating whether the error is a Client error or a Server error.
Faultactor
Reserved item, not used yet
Faultstring
Error Description
Faultdetail
Optional, XML format data, detailed error information
The complete content of the client code File "/nusoap/nusoap_client2.php" is as follows:
Require_once ("lib/nusoap. php ");
$ Client = new soapclient ('http: // 127.0.0.1/nusoap/nusoap_server2.php ');
$ Parameters = array ('string 1', 'string 2 ′);
$ Str = $ client-> call ('concatenate', $ parameters );
If (! $ Err = $ client-> getError ()){
Echo "program return:", $ str;
} Else {
Echo "error:", $ err;
}
?> When a NuSOAP client calls a WEB service with parameters, it uses arrays to pass parameters. $ Parameters is an array with values of each parameter in sequence. When the client calls a remote service program, it uses the call method with two parameters. The first parameter is the name of the service program, and the second parameter is the parameter array of the service program, here is $ parameters. Access the client program in the browser, and the browser will display a string: "program return: String 1 string 2"
Next, try to pass in the error parameter to the WEB service program, modify the above client program, and change the statement that generates the parameter array to: $ parameters = array ("string", 12 ), then access the client program through the browser, and the browser will display the string: "Error: The client: concatenate function parameter should be two strings ". The WEB service program judges that the input parameter is not a string and returns an error message to the client through soap_fault.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.