WebServices Axis使用

WebServices Axis使用记录。

1)在服务端定义接口:
package demo;

import java.rmi.Remote;
public interface MyInterface extends Remote {

void test(String id, String name);
}

2)实现已经定义的接口:
package demo;

import demo.MyInterface;
public class Service implements MyInterface {
@Override
public void test(String id, String name) {
System.out.println("id: " + id + "; name: " + name);
}
}


3)配置文件demo.wsdd:
<?xml version="1.0" encoding="GB2312"?>
<deployment xmlns="http://xml.apache.org/axis/wsdd/" xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
<service name="MyInterface" provider="java:RPC" style="rpc" use="encoded">
<parameter name="className" value="demo.Service" />
<parameter name="allowedMethods" value="*" />
</service>
</deployment>


4)客户端代码:
package demo.client;

public class ClientDemo {

public static void demo(String id, String name) throws Exception {

String url = "http://127.0.0.1:7001/Demo/services/MyInterface"; //服务端部署的url。

org.apache.axis.client.Service ws = new org.apache.axis.client.Service();
org.apache.axis.client.Call call = (org.apache.axis.client.Call) ws.createCall();
call.setTargetEndpointAddress(url);
call.setOperationName("test");
call.setTimeout(30000);

java.lang.Object ret = call.invoke(new java.lang.Object[] { id, name });
if (ret instanceof java.rmi.RemoteException) {
throw (java.rmi.RemoteException) ret;
}
}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值