PHP调用JAVA的WebService简单实例

2020-03-02 02:34:47来源:爱站网 阅读 ()

新老客户大回馈,云服务器低至5折

开发项目的时候我们都会有前台和后台链接服务器后为大家进行展现,但是数据想要在PHP中输入,本文是爱站技术频道小编带给大家的PHP调用JAVA的WebService简单实例。

服务端

对象类

复制代码 代码如下:

import java.io.Serializable;

?

public class Person implements Serializable {???
??? /**
???? *
???? */
??? private static final long serialVersionUID = -410186774891162281L;
??? private String username;
??? private int age;
??? private boolean sex;// true:male;false:female

??? public String getUsername() {
??????? 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;
??? }
}


服务类

?

复制代码 代码如下:

?


public class UserLogin {

?

??? public Person login(String loginName, String loginPasswd) {
??????? Person aPerson = new Person();
??????? if (loginName.equals("laoli") && loginPasswd.equals("111111")) {
??????????? aPerson.setUsername("老李");
??????????? aPerson.setAge(55);
??????????? aPerson.setSex(true);
??????? } else if (loginName.equals("xiaoli") && loginPasswd.equals("123456")) {
??????????? aPerson.setUsername("小丽");
??????????? aPerson.setAge(23);
??????????? aPerson.setSex(false);
??????? } else {
??????????? aPerson = null;
??????? }
??????? return aPerson;
??? }

}


客户端

?

复制代码 代码如下:

?


<?php

?

/*
?* Created on 2011-10-12
?* Author wanghao
?*
?* 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>' . $err . '</pre>';
??? // At this point, you know the call that follows will 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>';
??? print_r($result);
??? echo '</pre>';
} else {
??? // Check for errors
??? $err = $client->getError();
??? if ($err) {
??????? // Display the error
??????? echo '<h2>Error</h2><pre>' . $err . '</pre>';
??? } else {
??????? // Display the result
??????? echo '<h2>Result</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) {
??????? // Display the error
??????? echo '<h2>Error</h2><pre>' . $err . '</pre>';
??? } else {
??????? // Display the result
??????? echo '<h2>Result</h2><pre>';
??????? print_r($result);
??????? echo '</pre>';
??? }
}
?>

PHP调用JAVA的WebService简单实例爱站技术频道小编就到这里了哦,相信有些朋友们已经迫不及待的去操作了,相信精美的操作手法会把你深深的吸引住的。


原文链接:https://js.aizhan.com/develop/php/11855.html
如有疑问请与原作者联系

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:php调用C代码的实现方法

下一篇:PHP生成网站桌面快捷方式代码分享