Java+Axis WebService接口开发实例

转载原文:

http://www.tuicool.com/articles/Y7jAR3一、下载Axis的jar包

下载地址:http://ws.Apache.org/axis/

二、创建两个Web项目

1、WebService项目:负责提供接口,导入Axis的Jar包

(1)创建server-config.wsdd

xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">

< name="attachments.implementation">

value="org.apache.axis.attachments.AttachmentsImpl" />

<>

name="URLMapper" />

class="org.apache.axis2.receivers.RawXMLINOutMessageReceiver" />

(2)在web.xml中添加

AxisServlet

org.apache.axis.transport.http.AxisServlet

AxisServlet

/services/*

(3)创建接口类

package com.donghaiair.test;

public class TestWebsService {

public String testWebsServiceNull(){

return "test";

}

public String testWebsServiceOne(String s){

return "test:" + s;

}

public String testWebsServiceTwo(int i,String s){

return "test:" + i + "\n" + s;

}

}

2、WebServiceClient项目:负责调用接口,导入Axis的Jar包

package com.donghaiair.test;

import java.net.MalformedURLException;

import java.rmi.RemoteException;

import javax.xml.rpc.ServiceException;

import org.apache.axis.client.Call;

import org.apache.axis.client.Service;

public class TestWebsService {

public static void main(String[] args) {

String url = "http://localhost:8080/WebService/services/TestWebService.jws";//

Service service = new Service();

Call call;

try {

call = (Call) service.createCall();

call.setTargetEndpointAddress(new java.net.URL(url) );

// call.setOperationName("testWebsServiceNull" );// 这是要调用的方法

// String res = (String) call.invoke(new Object[] {null});

call.setOperationName("testWebsServiceOne" );// 这是要调用的方法

String res = (String) call.invoke( new Object[] {"徐士宽"} );

// call.setOperationName("testWebsServiceTwo" );// 这是要调用的方法

// String res = (String) call.invoke( new Object[] {17,"徐士宽"} );

System.out.println(res);

}catch (MalformedURLException e) {

} catch (RemoteException e) {

e.printStackTrace();

} catch (ServiceException e) {

e.printStackTrace();

}

}

}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值