本人按照网上例子制作一个sample,遇到一个问题,当用java编写的客户端调用返回值类型是int的函数时能正确得到返回值,但是调用返回值类型是string的函数时,不能正确得到返回值。以下为服务器端程序源代码:
/**
* 此处插入类型描述。
* 创建日期:(2005-10-27 10:32:48)
* @author:administrator
*/
import java.util.*;
public class zxjtest {
protected string name="gaga";
protected int age=20;
protected int sex=22;
protected list items=new arraylist();
/**
* zxjtest 构造子注解。
*/
public zxjtest() {
super();
}
public string getname()
{
return name;
}
public int getage()
{
return age;
}
public int getsex()
{
return sex;
}
public list getitems()
{
return items;
}
}
客户端调用的源代码:
string endpoint = "http://myserver:7001/zxjtest.jws";
service service = new service();
call call = (call) service.createcall();
call.settargetendpointaddress(new java.net.url(endpoint));
call.setoperationname("getname");
string ret = (string) call.invoke(new object[] {});
出错的就是最后一句。如果这一句改成调用返回值是int的函数,就不会出错。请问,这是axis的配置的问题吗?如果是,该如何改?
应该不大可能是axis的配置的问题,你调用的是
public string getname()
{
return name;
}
因此返回的是string,这个是没有错误的!
你的程序我在自己机器上运行的很好!不管调用哪个方法,都一样输出。你可以把string ret = (string) call.invoke(new object[] {});改成object ret = (object)call.invoke(new object[] {});这样的话你就不用去类型转换了!
或者如果你要类型转换的话,也可以这样做:
1,如果调用返回类型是string的方法 那么最后一句应该为
string ret = (string) call.invoke(new object[] {});
2,如果调用返回类型是int的方法,那么最后一句应该为
integer ret = (integer)call.invoke(new object[] {});
还有要注意的是在利用客户端进行测试的时候,确保服务器已经启动,否则会出错。如果你是采用http://myserver:7001/zxjtest.jws的话,你的web-inf下确保没有
server-config.wsdd,否则也会出错。
还有一个很简单的错误,可能仅仅只是weblogic配置的问题。最好重建一个应用并重新配置。
闽公网安备 35060202000074号