转自:http://blog.csdn.net/wlbing0625/article/details/7835398
通过eclipse自带的axis1插件可快速开发webservice
下载版本比较新eclipse吧!我这里是下载的eclipse-jee-helios-SR2-win32。其他版本也行哦(个人认为)
一、开发服务端:
第一步、新建一个Dynamic Web Porject server
HelloService.java
- package bing;
- public class HelloService{
- public String getGreeting(String name)
- {
- return "你好, " + name;
- }
- public int getPrice()
- {
- return new java.util.Random().nextInt(1000);
- }
- public void printInfo(){
- System.out.println("info");
- }
- public void setName(String name){
- System.out.println("name========"+name);
- }
- }
package bing;
public class HelloService{
public String getGreeting(String name)
{
return "你好, " + name;
}
public int getPrice()
{
return new java.util.Random().nextInt(1000);
}
public void printInfo(){
System.out.println("info");
}
public void setName(String name){
System.out.println("name========"+name);
}
}
选择 server 然后再新建web service
第二步、选择你要发布的bean
第三步、选择你要发布的方法
第四步、启动服务
第五步、问是否发布你的应用。这里我没有选择
第六步、点击finished后,生成的代码。如下
访问:http://localhost:8080/server/servlet/AxisServlet (根据自己的环境情况而定)
是否发布成功。
二、客户端
第一步、新建一个Dynamic Web Porject client
选择client项目,新建web service client
输入发布wsdl地址:http://localhost:8080/server/services/HelloService?wsdl
一路next,直到finish
第二步、finish后项目截图
第三步、测试接口
- import java.rmi.RemoteException;
- import bing.HelloServiceProxy;
- public class TestClient {
- /**
- * @param args
- * @throws RemoteException
- */
- public static void main(String[] args) throws RemoteException {
- HelloServiceProxy proxy=new HelloServiceProxy();
- System.out.println(proxy.getGreeting("大兵哥"));
- System.out.println(proxy.getPrice());
- proxy.printInfo();
- proxy.setName("大兵哥");
- }
- }
import java.rmi.RemoteException;
import bing.HelloServiceProxy;
public class TestClient {
/**
* @param args
* @throws RemoteException
*/
public static void main(String[] args) throws RemoteException {
HelloServiceProxy proxy=new HelloServiceProxy();
System.out.println(proxy.getGreeting("大兵哥"));
System.out.println(proxy.getPrice());
proxy.printInfo();
proxy.setName("大兵哥");
}
}
运行结果:
- 2012-8-6 16:01:35 org.apache.axis.utils.JavaUtils isAttachmentSupported
- 警告: Unable to find required classes (javax.activation.DataHandler and javax.mail.internet.MimeMultipart). Attachment support is disabled.
- 你好, 大兵哥
- 35
2012-8-6 16:01:35 org.apache.axis.utils.JavaUtils isAttachmentSupported
警告: Unable to find required classes (javax.activation.DataHandler and javax.mail.internet.MimeMultipart). Attachment support is disabled.
你好, 大兵哥
35
tomcat console运行结果
info
name========大兵哥
上面出现了警告是因为缺少mail.jar的缘故。
我在tomcat的lib中找到mail-1.4.jar复制到client的lib中。重新运行,警告消失
Unable to find required classes (javax.activation.DataHandler and javax.mail.internet.MimeMultipart)
转自:http://blog.csdn.net/zhengqiqiqinqin/article/details/19341487
在接触WebService时值得收藏的一篇文章:
在调试Axis1.4访问WebService服务时,出现以下错误:
Unable to find required classes (javax.activation.DataHandler and javax.mail.internet.MimeMultipart)
有错误找到错误原因以及发现值得收藏的一篇文章,方便自己查找。
——————————————————————————————————
错误原因:
需要mail.jar和activation.jar。
Solution:
Web Services Required Jars Download Instructions
http://www.eclipse.org/webtools/wst/components/ws/download_instructions_for_jars.html
解决办法:
1) 下载javamail和jaf,解压出mail.jar和activation.jar
http://java.sun.com/products/javamail/downloads/index.html
http://java.sun.com/products/javabeans/glasgow/jaf.html#download
或者我提供了一个rar包:包含mail.jar action.jar
download:mail.jar and activation.jar
2) 把mail.jar和activation.jar放到%AXIS_HOME%/WEB-INF/lib目录下
3) 将.jar文件添加到%CLASSPATH%
说明:
这个是可以忽略的。不过以后构建web services都要用到的,还是添加上的好。
参考:http://www.ogsadai.org.uk/documentation/ogsadai-wsi-2.1/doc/wsi/FAQ.html
This is a warning message that can safely be ignored. It is displayed when Axis has been deployed without an optional JAR. An optional JAR is one that allows Axis to support a particular piece of functionalty but is not required for general use. Please refer to the Axis documentation for more details.
备注:
一篇很好的jars下载指南:Web Services Required Jars Download Instructions
Axis指南:Guide to building Axis