2008-05-07

使用Tuscany,建立web services

关键字: tuscany
Tuscany-ws项目
摘要》
使用Tuscany创建Web services服务
一:安装Tuscany的Eclipse plugin
启动Eclipse后,菜单Help->Software Updates->Find and Install
选择Searh for new features to install ,然后执行New Remote Site
名字:Tusany
URL:http://people.apache.org/~jsdelfino/tuscany/tools/updatesite/*
Remote site ,完成即可

安装完成后,重启eclipse
二:建立Java Project
Tuscany-ws
由于插件已经加入开发工具,因此可以自行建立一个User Library资源,供以引用;

>>一:源代码文件HelloWorld.java

package com.spsoft.tuscany.ws.helloworld;
import org.osoa.sca.annotations.Remotable;
@Remotable
public interface HelloWorld{
String sayHello(String name);
}

>>二:源代码文件HelloWorldImpl.java
package com.spsoft.tuscany.ws.helloworld;
public class HelloWorldImpl implements HelloWorld{
Public String sayHello(String name){
Return “Hello:”+name;
}

}

>>三:helloworld.composite建立在src下
<?xml version="1.0" encoding="UTF-8"?>
<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
xmlns:t="http://tuscany.apache.org/xmlns/sca/1.0"
xmlns:c="http://helloworld.ws.tuscany.spsoft.com.cn"
name="helloworld">
<component name="HelloWorldComponent">
<implementation.java class=" com.spsoft.tuscany.ws.helloworld.HelloWorldImpl"/>
<service name="HelloWorld">
<binding.ws uri="http://localhost:9080/HelloWorld"/>
</service>
</component>
</composite>
>>四:建立启动web services的服务类
package com.spsoft.tuscany.ws.helloworld;

import java.io.IOException;

import org.apache.tuscany.sca.host.embedded.SCADomain;

public class HelloWorldServer {
public static void main(String[] args) {
SCADomain scaDomain = SCADomain.newInstance("helloworld.composite");
try {
System.out
.println("HelloWorld server started (press enter to shutdown)");
System.in.read();
} catch (IOException e) {
e.printStackTrace();
}
scaDomain.close();
System.out.println("HelloWorld server stopped");
}

}

运行该类时,控制台将会看到以下信息:
2008-5-7 19:35:01 org.apache.tuscany.sca.http.jetty.JettyServer addServletMapping
信息: Added Servlet mapping: http://spsoft-35c9654c:9080/HelloWorld
HelloWorld server started (press enter to shutdown)
此时您可以通过访问
http://spsoft-35c9654c:9080/HelloWorld?wsdl
观看你的服务是否已经成功创建!
评论
zwm 2008-05-07
采用XFire客户端调用
public static void main(String[] args) {
// TODO Auto-generated method stub
Service servModel = new ObjectServiceFactory().create(HelloWorld.class);
//
XFireProxyFactory factory = new XFireProxyFactory(XFireFactory
.newInstance().getXFire());
String wsUrl = "http://spsoft-35c9654c:9080/HelloWorld";
try {
HelloWorld srvc = (HelloWorld) factory.create(servModel, wsUrl);
System.out.println(srvc.sayHello("@author:zwm"));
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
发表评论

您还没有登录,请登录后发表评论

zwm
搜索本博客
博客分类
最近加入圈子
存档
最新评论