axis2创建web service(四)
2012-10-15 16:52
253 查看
上节我们做了一个简单的例子,调用的服务里的方法只是简单返回一个字符串,这次我们要做一个复杂点的例子,调用服务里的方法返回一个java Bean对象。
1. 首先做一个简单的java bean ,代码如下
Java代码
![](http://deltaj.iteye.com/images/icon_copy.gif)
![](http://deltaj.iteye.com/images/icon_star.png)
![](http://deltaj.iteye.com/images/spinner.gif)
package com.deltaj.server;
public class Persion {
// 姓名
private String name;
// 年龄
private int age;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
2.做一个服务,里面只发布一个方面,这个方法返回这个bean。
Java代码
![](http://deltaj.iteye.com/images/icon_copy.gif)
![](http://deltaj.iteye.com/images/icon_star.png)
![](http://deltaj.iteye.com/images/spinner.gif)
package com.deltaj.server;
public class BeanServer {
/**
* 简单的测试方法
*
*/
public Persion testMethod(String name,
int age) {
Persion persion = new Persion();
persion.setName(name);
persion.setAge(age);
return persion;
}
}
3.按照第二节的做法,把这个服务发布出来。
4.同样按照第三节的方法,用这个wsdl来生成stub代码。
5.然后我们开始做一个方法来调用一下这个服务。
Java代码
![](http://deltaj.iteye.com/images/icon_copy.gif)
![](http://deltaj.iteye.com/images/icon_star.png)
![](http://deltaj.iteye.com/images/spinner.gif)
package com.deltaj.client;
import com.deltaj.server.TestServerStub;
public class BeanClient {
public static
void main(String[] args) throws Exception{
// 初始化桩文件
TestServerStub stub = new TestServerStub();
// 初始化TestMethod方法。
TestServerStub.TestMethod request = new TestServerStub.TestMethod();
// 设置bean的属性值。
request.setName("delta ");
request.setAge(20);
//
System.out.println("The name is:"+stub.testMethod(request).get_return().getName());
System.out.println("The age is:"+stub.testMethod(request).get_return().getAge());
}
}
6.如果按照这里说的做的话,你会看到
log4j:WARN No appenders could be found for logger (org.apache.axis2.description.AxisService).
log4j:WARN Please initialize the log4j system properly.
The name is:delta
The age is:20
祝你好运。:)
1. 首先做一个简单的java bean ,代码如下
Java代码
![](http://deltaj.iteye.com/images/icon_copy.gif)
![](http://deltaj.iteye.com/images/icon_star.png)
![](http://deltaj.iteye.com/images/spinner.gif)
package com.deltaj.server;
public class Persion {
// 姓名
private String name;
// 年龄
private int age;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
package com.deltaj.server; public class Persion { // 姓名 private String name; // 年龄 private int age; public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } }
2.做一个服务,里面只发布一个方面,这个方法返回这个bean。
Java代码
![](http://deltaj.iteye.com/images/icon_copy.gif)
![](http://deltaj.iteye.com/images/icon_star.png)
![](http://deltaj.iteye.com/images/spinner.gif)
package com.deltaj.server;
public class BeanServer {
/**
* 简单的测试方法
*
*/
public Persion testMethod(String name,
int age) {
Persion persion = new Persion();
persion.setName(name);
persion.setAge(age);
return persion;
}
}
package com.deltaj.server; public class BeanServer { /** * 简单的测试方法 * */ public Persion testMethod(String name, int age) { Persion persion = new Persion(); persion.setName(name); persion.setAge(age); return persion; } }
3.按照第二节的做法,把这个服务发布出来。
4.同样按照第三节的方法,用这个wsdl来生成stub代码。
5.然后我们开始做一个方法来调用一下这个服务。
Java代码
![](http://deltaj.iteye.com/images/icon_copy.gif)
![](http://deltaj.iteye.com/images/icon_star.png)
![](http://deltaj.iteye.com/images/spinner.gif)
package com.deltaj.client;
import com.deltaj.server.TestServerStub;
public class BeanClient {
public static
void main(String[] args) throws Exception{
// 初始化桩文件
TestServerStub stub = new TestServerStub();
// 初始化TestMethod方法。
TestServerStub.TestMethod request = new TestServerStub.TestMethod();
// 设置bean的属性值。
request.setName("delta ");
request.setAge(20);
//
System.out.println("The name is:"+stub.testMethod(request).get_return().getName());
System.out.println("The age is:"+stub.testMethod(request).get_return().getAge());
}
}
package com.deltaj.client; import com.deltaj.server.TestServerStub; public class BeanClient { public static void main(String[] args) throws Exception{ // 初始化桩文件 TestServerStub stub = new TestServerStub(); // 初始化TestMethod方法。 TestServerStub.TestMethod request = new TestServerStub.TestMethod(); // 设置bean的属性值。 request.setName("delta "); request.setAge(20); // System.out.println("The name is:"+stub.testMethod(request).get_return().getName()); System.out.println("The age is:"+stub.testMethod(request).get_return().getAge()); } }
6.如果按照这里说的做的话,你会看到
log4j:WARN No appenders could be found for logger (org.apache.axis2.description.AxisService).
log4j:WARN Please initialize the log4j system properly.
The name is:delta
The age is:20
祝你好运。:)
相关文章推荐
- 使用Axis2创建Web Service
- axis2创建web service(一)
- axis2创建web service
- Axis2 创建 web service (2) : 同步异步调用
- axis2创建web service(一)
- axis2创建web service
- axis2创建web service(二)
- axis2创建web service(三)
- 使用Axis2创建一个Web Service的客户端
- axis2创建web service(一)
- axis2创建web service(三)
- axis2创建web service(二)
- 使用Axis2创建Web Service
- axis2创建web service
- axis2创建web service
- axis2创建web service(2)
- axis2创建web service2
- axis2创建web service
- axis2创建web service(三)
- axis2创建web service(四)