In php, nusoap calls the webservice released by javaaxis2.

Source: Internet
Author: User
Webservice call: the development environment is Eclipse3.6 (javaIDE) + JDK1.6 + Tomcat7.0 + Axis21.6 + php5.2.14 (IDE is ecli... webservice call: the development environment is Eclipse3.6 (java IDE) + JDK 1.6 + Tomcat 7.0 + Axis2 1.6 + php 5.2.14 (Ideis eclipse-php-helios-sr1-win32.zip) + apache2.2.15. these software is updated at any time, please download Google Baidu from the official website.

1. write a service on the java end and publish it as a service using axis2. the service name in this article is sayHi, which contains a function sayHello (). The code is as follows:

package Hi; public class sayHi {   public String sayHello(String user,String info) {     return"Hello, My Friend "+ user + info;   } }

2. Compile the php client and call the webservice released by axis2.

2.1 Download nusoap.rar and add the decompressed lib folder to the project

2.2 compile the php client with the following code:

 Soap_defencoding = 'utf-8'; // $ client-> decode_utf8 = false; // set parameters (note: PHP can only pass parameters in the 'Array set' mode) $ param = array ('user' => 'National holiday not traveling ', 'info' => 'Welcome to my home! '); // Call the remote method 'sayhel' as the method name in the service // 'http: // hi' is the value of targetNamespace in the wsdl file $ result = $ client-> call ('sayhel', $ param, 'http: // hi '); // display the execution result if (! $ Err = $ client-> getError () {// open-source phprm.com echo $ result;} else {echo $ err ;}?>

III. execution result:

Hello, My Friend National holiday does not travel Welcome to my home!

Webservice garbled:

Many use NuSoap calls. NET WebService or J2EE WebService friends may have encountered Chinese garbled characters (I used PHP to call NuSoap). The following describes the causes and corresponding solutions for 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 passed in the same encoding method: $ 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.


Link to this article:

Add to favorites ^ please keep the tutorial address.

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.