Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » WebService/XML/JSON/SOAP/SOA  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 Re:请问哪里有webservices的入门程序(hello world 式的) [Re:bwpc]
jameszhang



CJSDN高级会员


发贴: 1594
积分: 111
于 2004-06-08 14:31 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
首先准备开发环境:

Axis http://apache.linuxforum.net/dist/ws/axis/1_1/axis-1_1.zip
Tomcat http://jakarta.apache.org/site/binindex.cgi

准备完成后安装:

安装JRE或JDK
1、安装tomcat,版本要求4.1.x
2、解压下载Axis,将子目录webapps下的axis目录,复制到$TOMCAT_HOME/webapps目录下,将子目录lib下的所有jar文件,复制到TOMCAT_HOME/common/lib/目录下。
3、启动tomcat,访问http://localhost:8080/axis测试

如果测试成功:

编写服务端CLASS

public class MyService
{
public String serviceMethod(String arg)
{
return arg;
}
}


编写描述文件 deploy.wsdd

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

<service name="MyService" provider="java:RPC">
<parameter name="className" value="MyService"/>
<parameter name="serviceMethod" value="*"/>
</service>

</deployment>


接下来就是编译和部署了
1、编译用JDK
2、部署用:
java -classpath "axis.jar;axis-ant.jar;commons-discovery.jar;commons-logging.jar;jaxrpc.jar;log4j-1.2.4.jar;saaj.jar;wsdl4j.jar" org.apache.axis.client.AdminClient deploy.wsdd

之后可查看服务是否被部署上

这里有一段测试代码:用JAVA写的客户端

import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;
import org.apache.axis.utils.Options;

import javax.xml.namespace.QName;
import javax.xml.rpc.ParameterMode;

public class Client
{
public static void main(String [] args)
{
try {
Options options = new Options(args);

String endpointURL = "http://127.0.0.1:8080/axis/services/MyService";
String textToSend;

args = options.getRemainingArgs();
if ((args == null) || (args.length < 1)) {
textToSend = "<nothing>";
} else {
textToSend = args[0];
}

Service service = new Service();
Call call = (Call) service.createCall();

call.setTargetEndpointAddress( new java.net.URL(endpointURL) );
call.setOperationName( new QName("MyService", "serviceMethod") );
call.addParameter( "arg1", XMLType.XSD_STRING, ParameterMode.IN);
call.setReturnType( org.apache.axis.encoding.XMLType.XSD_STRING );

String ret = (String) call.invoke( new Object[] { textToSend } );

System.out.println("You typed : " + ret);
} catch (Exception e) {
System.err.println(e.toString());
}
}
}


上面是我以前做的个例子,如果有什么问题根据你的实际情况更改,呵呵!!


jameszhang edited on 2004-06-16 08:42

"First they ignore u, then they laugh at u, then they fight u, then u will win

Mahatma Gandhi"


话题树型展开
人气 标题 作者 字数 发贴时间
14410 请问哪里有webservices的入门程序(hello world 式的) bwpc 75 2004-06-07 15:56
13828 Re:请问哪里有webservices的入门程序(hello world 式的) jameszhang 2567 2004-06-08 14:31
12398 Re:请问哪里有webservices的入门程序(hello world 式的) bwpc 35 2004-06-08 15:20
12341 Re:请问哪里有webservices的入门程序(hello world 式的) bwpc 111 2004-06-08 17:00
12220 Re:请问哪里有webservices的入门程序(hello world 式的) jameszhang 20 2004-06-08 21:41
12693 Re:请问哪里有webservices的入门程序(hello world 式的) floater 1266 2004-06-08 22:05
12241 Re:请问哪里有webservices的入门程序(hello world 式的) enna 9 2004-06-15 10:14
11996 Re:请问哪里有webservices的入门程序(hello world 式的) oiesis 331 2004-07-26 10:53
12116 Re:请问哪里有webservices的入门程序(hello world 式的) oiesis 331 2004-07-26 10:55
12858 Re:请问哪里有webservices的入门程序(hello world 式的) bwpc 92 2004-07-28 17:18

flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923