Axis的问题,急!

yingyi8989 yingyi8989 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
Server:
public class MyService
{
public String userLogin(String name, String password)
{
if ("123".equals(name) && "123".equals(password)) {
return true;
}
retrun false;
}
}

拷贝了一份文件MyService.java 改名为MyService.jws

Client:
public class MainTest {
public static void main(String[] args)
{
try {
String endpoint = "http://localhost:8085/test/MyService.jws";

Service service = new Service();
Call call = null;


call = (Call) service.createCall();

call.setOperationName(new QName(endpoint, "userLogin"));
call.setTargetEndpointAddress(new java.net.URL(endpoint));

Boolean bool = (Boolean) call.invoke(new Object[] { "123","123" });
System.out.println("return value is " + bool);
} catch (Exception ex) {
ex.printStackTrace();
}
}
}

这样调用是成功的,但是看到服务那边的Session会越来越多。所以加入了server-config.wsdd文件,原来是使用默认的。
在默认的文件中加入了以下配置:
<handler name="session"
type="java:org.apache.axis.handlers.SimpleSessionHandler" />
<service name="MyService" provider="java:RPC" style="wrapped">
<namespace>urn:</namespace>
<requestFlow>
<handler type="session" />
</requestFlow>
<responseFlow>
<handler type="session" />
</responseFlow>
<parameter name="className" value="MyService" />
<parameter name="allowedMethods" value="*" />
</service>

这样就更改了访问的url,现在client的代码如下:

public class MainTest {
public static void main(String[] args)
{
try {
String endpoint = "http://localhost:8085/test/services/MyService?wsdl";

Service service = new Service();
Call call = null;


call = (Call) service.createCall();

call.setOperationName(new QName(endpoint, "userLogin"));
call.setTargetEndpointAddress(new java.net.URL(endpoint));

Boolean bool = (Boolean) call.invoke(new Object[] { "123","123" });
System.out.println("return value is " + bool);
} catch (Exception ex) {
ex.printStackTrace();
}
}
}

有两个问题:
1、如果我想用原来的url,要怎么做?
2、后来的代码Boolean bool = (Boolean) call.invoke(new Object[] { "123","123" }); 会报类型转换错误,为什么前面的方法可以得到Boolean,后面的只得到String呢?
先谢了。
...全文

相关推荐

评论 2
收藏 已收藏
分享
返回顶部
yingyi8989
Java EE 67,535 成员 225,843 内容