package com.webservice;
/*
* File name: TestService.java
*/
import java.io.IOException;
import java.net.MalformedURLException;
import javax.xml.namespace.QName;
import javax.xml.rpc.ServiceException;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* @author Stephen
*
* 测试调用WebService
*/
public class TestService {
private static final Log log = LogFactory.getLog(TestService.class);
private static final String HELLO_SERVICE_ENDPOINT = "http://localhost:8080/test_webservice/services/HelloServices?wsdl";
//private static final String HELLO_SERVICE_ENDPOINT = "http://www.yodao.com/smartresult-xml/search.s?wsdl";
public static void main(String[] args) {
TestService tester = new TestService();
// tester.callSayHello();
tester.callSayHelloToPerson();
}
public void callSayHello() {
try {
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(new java.net.URL(
HELLO_SERVICE_ENDPOINT));
call.setOperationName(new QName("http://webservice.com/",
"sayHello"));
call.setReturnType(org.apache.axis.Constants.XSD_STRING);
try {
String ret = (String) call.invoke(new Object[] {});
System.out.println("The return value is:" + ret);
return;
} catch (IOException e) {
e.printStackTrace();
}
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (ServiceException e) {
e.printStackTrace();
}
log.error("call sayHello service error!");
}
public void callSayHelloToPerson() {
try {
Service service = new Service();
Call call = (Call) service.createCall();
//引用webservice接口地址
call.setTargetEndpointAddress(new java.net.URL(
HELLO_SERVICE_ENDPOINT));
//调用某方法
call.setOperationName(new QName("http://webservice.com/",
"sayHelloToPerson"));
/* 传递参数给name
* 如果把参数写在xml中,则用org.apache.axis.encoding.XMLType.XSD_STRING方式调用
*/
call.addParameter("name", org.apache.axis.Constants.XSD_STRING,
javax.xml.rpc.ParameterMode.IN);
//设置返回参数
call.setReturnType(org.apache.axis.Constants.XSD_STRING);
try {
String ret = (String) call.invoke(new Object[] { "" });
System.out.println("The return value is:" + ret);
return;
} catch (IOException e) {
e.printStackTrace();
}
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (ServiceException e) {
e.printStackTrace();
}
log.error("call sayHello service error!");
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
Webservice接口开发简单例子
共27个文件
jar:10个
class:2个
xml:2个
需积分: 49 39 下载量 94 浏览量
2019-08-05
01:27:28
上传
评论
收藏 2.3MB ZIP 举报
温馨提示
NULL 博文链接:https://lihong11.iteye.com/blog/2058911
资源推荐
资源详情
资源评论
收起资源包目录
test_webservice.zip (27个子文件)
test_webservice
src
com
webservice
HelloService.java 288B
TestService.java 3KB
.classpath 2KB
build
classes
com
webservice
HelloService.class 877B
TestService.class 3KB
.settings
org.eclipse.wst.jsdt.ui.superType.container 49B
org.eclipse.wst.common.project.facet.core.xml 345B
org.eclipse.wst.jsdt.ui.superType.name 6B
org.eclipse.wst.common.component 497B
.jsdtscope 503B
org.eclipse.jdt.core.prefs 364B
WebContent
META-INF
MANIFEST.MF 39B
index.jsp 366B
deploywebservice.bat 539B
deploy.wsdd 369B
WEB-INF
classes
lib
wsdl4j-1.5.1.jar 124KB
commons-logging-1.0.4.jar 37KB
saaj.jar 19KB
commons-discovery-0.2.jar 70KB
mail.jar 274KB
log4j-1.2.8.jar 344KB
axis-ant.jar 32KB
jaxrpc.jar 30KB
activation.jar 53KB
axis.jar 1.53MB
web.xml 3KB
.project 1KB
共 27 条
- 1
资源评论
weixin_38669628
- 粉丝: 383
- 资源: 6万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功