PHP invoke Java WebService simple instance

Source: Internet
Author: User

  This article is mainly on the PHP call Java WebService Simple example of the introduction, the need for friends can come to the reference, I hope to help you.

Use PHP to invoke the Java language development webservice. The client submits two string parameters, and the service side returns an object type. The service side uses AXIS-1.4 as the SOAP engine. The client is PHP5.2.9, using Nusoap as the SOAP engine.   Server   object class     code is as follows: Import java.io.Serializable;   public class Person implements Serializable {       /**      *    &N Bsp  */    Private static final long serialversionuid = -410186774891162281l;     Private String username;     private int age;     Private Boolean sex;//true:male;false:female       public String GetUserName () {  &nbs P     return username;    }       public void Setusername (String username) {        This.username = Username;    }       public int getage () {        return age;    }       public void setage (int age) {        this.age = age;    }       Public Boolean getsex () {        return sex    :       public void Setsex (Boolean sex) {        this.sex = sex;    }}     service class   code is as follows: public Class Userlogin {      public person login (string loginName, String loginpasswd) {      &N Bsp Person Aperson = new person ();         if (loginname.equals ("Laoli") && loginpasswd.equals ("111111")) {            Aperson.setusername ("Lao Li");             Aperson.setage (55);             Aperson.setsex (true);        } else if (Loginname.equals ("Xiaoli") && loginpasswd.equals ("123456")) {            Aperson.setusername ("Xiaoli");             Aperson.setage (23);             Aperson.setsex (false);        } else {            Aperson = null;         }         return Aperson;    }  }     client   code is as follows: <?php  / * Created on 2011-10-12  * Author Wan Ghao  *  * package_name/userloginclient.php  */header ("Content-type:text/html;charset=utf-8"); Pull in the Nusoap code require_once ("libs/nusoap.php"); Create the client instance $client = new Nusoapclient (' http://localhost:8080/axis/services/UserLoginWS?wsdl ', true); $client->soap_defencoding = ' utf-8 '; $client->decode_utf8 = false; $client->xml_encoding = ' utf-8 '; Check for an error $err = $client->geterror (); if ($err) {   /Display the error     echo ' <h2>constructor error</h2><pre> '. $e Rr. ' </pre> ';    //at ' This point ', you know the ' call ' follows'll fail}//Call the SOAP method $param =arRay (' LoginName ' => ' Laoli ', ' loginpasswd ' => ' 111111 '); $result = $client->call (' login ', $param); Check for a fault if ($client->fault) {    echo ' <h2>Fault</h2><pre> ';     PR Int_r ($result);     echo ' </pre> '; else {   /Check for errors     $err = $client->geterror ();     if ($err) {  & nbsp    /Display the error         echo ' <h2>Error</h2><pre> '. $err. ' </pre> ';    } else {       //Display The result         Echo ' <h2>resul T</h2><pre> ';         Print_r ($result);         echo ' </pre> ';    } echo ' <br> '; $param =array (' loginName ' => ' Xiaoli ', ' loginpasswd ' => ' 123456 '); $result = $client->call (' login ', $param); Check for a fault if ($client->fault) {    echo ' <H2>fault</h2><pre> ';     Print_r ($result);     echo ' </pre> '; else {   /Check for errors     $err = $client->geterror ();     if ($err) {  & nbsp    /Display the error         echo ' <h2>Error</h2><pre> '. $err. ' </pre> ';    } else {       //Display The result         Echo ' <h2>resul T</h2><pre> ';         Print_r ($result);         echo ' </pre> ';    }}?>  

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.