webservice服务接口为:
[code]
public class TestService {
long ll = 0;
public TestService() {
ll = System.currentTimeMillis();
System.out.println("create time>>>>>>>"+ll);
}
public Integer[] listData() {
System.out.println("function time>>>>>>>"+ll);
return new Integer(0);
}
}
[/code]
用wsad生成wsdl描述文件,再生成生成客户端代码(一切都是自动生成)。
编写客户端测试代码为:
[code]
public class Test {
public static void main(String[] args) {
try{
TestService ts = new TestServiceProxy();
Integer[] mess = ts.listData();
Integer[] mess1 = ts.listData();
Integer[] mess2 = ts.listData();
}catch(Exception e){
e.printStackTrace();
}
}
}
[/code]
输出结果为:
[b]
create time>>>>>>>1162366219517
function time>>>>>>>1162366219517
create time>>>>>>>1162366227899
function time>>>>>>>1162366227899
create time>>>>>>>1162366233848
function time>>>>>>>1162366233848
[/b]
很显然,每次请求webservice的服务接口,都要在服务端创建一个服务实例。但有些情况下,服务接口并不需要每次创建实例,可以使用单例来实现,这样会大大提高效率。要是在创建服务描述(WSDL)时有这种选择就好了(由开发人员自己掌握)。
例如下面是一个更明显的例子,没有必要每次请求产生一个实例:
[code]
public class TestService1 {
public TestService1() {
}
public int add(int a, int b) {
return a+b;
}
public int sub(int a, int b) {
return a-b;
}
}
[/code]
[code]
public class TestService {
long ll = 0;
public TestService() {
ll = System.currentTimeMillis();
System.out.println("create time>>>>>>>"+ll);
}
public Integer[] listData() {
System.out.println("function time>>>>>>>"+ll);
return new Integer(0);
}
}
[/code]
用wsad生成wsdl描述文件,再生成生成客户端代码(一切都是自动生成)。
编写客户端测试代码为:
[code]
public class Test {
public static void main(String[] args) {
try{
TestService ts = new TestServiceProxy();
Integer[] mess = ts.listData();
Integer[] mess1 = ts.listData();
Integer[] mess2 = ts.listData();
}catch(Exception e){
e.printStackTrace();
}
}
}
[/code]
输出结果为:
[b]
create time>>>>>>>1162366219517
function time>>>>>>>1162366219517
create time>>>>>>>1162366227899
function time>>>>>>>1162366227899
create time>>>>>>>1162366233848
function time>>>>>>>1162366233848
[/b]
很显然,每次请求webservice的服务接口,都要在服务端创建一个服务实例。但有些情况下,服务接口并不需要每次创建实例,可以使用单例来实现,这样会大大提高效率。要是在创建服务描述(WSDL)时有这种选择就好了(由开发人员自己掌握)。
例如下面是一个更明显的例子,没有必要每次请求产生一个实例:
[code]
public class TestService1 {
public TestService1() {
}
public int add(int a, int b) {
return a+b;
}
public int sub(int a, int b) {
return a-b;
}
}
[/code]