文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>使用Myeclipse开发基于xfire的Web Services 入门

使用Myeclipse开发基于xfire的Web Services 入门

时间:2008-09-03  来源:ybu2008

在myeclipse的新建工程向导对话框中,有一个web services project 选项,下面逐步说明:
1.New->project->MyEclipse->Java Enterprise Projects->web service project->给工程起个名字,我起名为WebServicesDemo,在Web Service& J2EE Details中选择XFire(deprecated)注意这里其实已经说明了(已废弃)我刚刚在写demo的时候没有看到,晕。
2.点击下一步,填写用于提供服务的Servlet信息,因为我也是初次尝试所以都保留了默认值,下一步选择依赖的jar包,建议从官方网站上下载,不使用myeclipse提供的。
官方网站地址http://xfire.codehaus.org/
下载xfire-distribution-1.2.6.zip和 xfire-all-1.2.6.jar
依赖包介绍http://xfire.codehaus.org/Dependency+Guide 这里有介绍那些包必须引那些包可以不引。引过包后点finish。
3.编写测试代码:
package com.syj.ws;
 
/**
 *<p>Title:服务的接口</p>
 *
 *<p>
 *Copyright:转载请注明出处http://blog.csdn.net/sunyujia/
 *</p>
 *
 *@author孙钰佳
 *@[email protected]
 *@dateJul13,200812:25:41PM
 */
publicinterface MyServer {
    public String getTestStr();
}
package com.syj.ws;
 
/**
 *<p>
 *Title:服务的实现
 *</p>
 *
 *<p>
 *Copyright:转载请注明出处http://blog.csdn.net/sunyujia/
 *</p>
 *

 *@author孙钰佳
 *@[email protected]
 *@dateJul13,200812:26:19PM
 */
publicclass MyServerImpl implements MyServer {
 
    public String getTestStr() {
       return"this is demo";
    }
 
}
4.配置services.xml,在没尝试web services之前就发现了这个按钮,但在昨天我还不知道它的真正用途。

这里点击第一个,可在services.xml中生成相关配置,稍后会使用第二个生成客户端程序。


生成services.xml的内容如下
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://xfire.codehaus.org/config/1.0">
    <service>
       <name>Demo</name>
       <serviceClass>com.syj.ws.MyServer</serviceClass>
       <implementationClass>
           com.syj.ws.MyServerImpl
       </implementationClass>

 <style>wrapped</style>
       <use>literal</use>
       <scope>application</scope>
    </service>
</beans>
       5.将应用发布到tomcat上面使用myeclipse发布即可。
注意:正常情况下services.xml应该被拷贝到WEB-INF\classes\META-INF\xfire目录下
         使用浏览器访问
http://127.0.0.1:8080/WebServicesDemo/services/Demo?wsdl
如果看到wsdl文件即表明成功。

编写客户端程序


先利用myeclipse生成客户端的代码,上面有提到,和生成services配置差不多。



生成客户端的过程要保证tomcat是开启状态
测试生成的客户端代码
publicstaticvoid main(String[] args) { DemoClient client = new DemoClient(); DemoPortType service = client.getDemoHttpPort(); System.out.println(service.getTestStr()); System.out.println("test client completed"); System.exit(0); }

       运行DemoClient 后稍等片刻(web services确实很慢)
控制台打印
this is demo
test client completed
说明执行成功!
 
最后推荐大家一些资料
http://xfire.codehaus.org/Quick+Start
http://xfire.codehaus.org/Dependency+Guide
http://java.sun.com/webservices/docs/2.0/tutorial/doc/index.html
http://weblogs.java.net/blog/kohlert/archive/2005/05/jaxrpc_20_renam.html
http://www.w3.org/TR/soap/

相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载