SCA导航2-用Tuscany构建你的第一个web service
来源:互联网 发布:跑步测速软件 编辑:程序博客网 时间:2024/06/11 21:48
2. 用Tuscany构建你的第一个web service
这篇导航文章将一步步地介绍如何使用Tuscany构建web service。第一部分将介绍如何将Tuscany运行环境添加到Eclipse开发环境,第二部分将介绍如何利用Tuscany简单地创建web service。
2.1. 安装最新的Tuscany的Eclipse插件
本节将介绍Tuscany的Eclipse插件安装方法,它能够使你在Package Explorer中运行SCA组合构件。
从Eclipse菜单Help->Software Updates…->Find and Install,选择“Search for new features to install”,然后按下一步,在此步中点击“new Remote site…”按钮,输入name为“Tuscany”,站点URL为http://archive.apache.org/dist/tuscany/java/sca/1.4/tuscany-sca-1.4-updatesite/,添加完后选择刚才新增的远程站点,右击鼠标在弹出菜单中选择“Install”,在接下来的界面点击接收协议,按下一步即可完成安装。
2.2. 创建你的服务业务逻辑
2.2.1. 创建一个Java Project
在这一小节中你将创建一Eclipse的Java Project,用于构建组合构件应用。点击“New Java Project”按钮,加载新建Java Project对话框。输入Project Name为“ws”,Project Layout选择“Create separate folders for sources and class files.”
图-5
按提示到下一步,在Libraries选项卡中点击“Add Library...”按钮,把Tuscany Library添加到此Project中。
图-6
接着按提示完成新建ws工程。
图-7
2.2.2. 构建web service
首先新建个helloworld包
图-8
下一步新建个helloworld服务接口,接口内容如下
package helloworld;
import org.osoa.sca.annotations.Remotable;
@Remotable
public interface HelloWorld {
String sayHello(String name);
}
然后创建此接口的实现
package helloworld;
public class HelloWorldImpl implements HelloWorld {
public String sayHello(String name) {
return "Hello " + name;
}
}
2.2.3. 装配服务
现在服务接口跟实现都已经有了,接下来把它装配起来,提供组合服务。装配的信息都包含在.composite文件中。在src目录下新建helloworld.composite文件,其内容如下
<?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"
targetNamespace="http://helloworld"
name="helloworld">
<component name="HelloWorldComponent">
<implementation.java class="helloworld.HelloWorldImpl"/>
<service name="HelloWorld">
<binding.ws uri="http://localhost:8080/HelloWorld"/>
</service>
</component>
</composite>
此时ws工程内容如图-9
图-9
服务已经装配好,接下来我们来运行它。
2.3. 运行服务
在这一节中你将加载,刚刚装配的helloworld web service服务。在helloworld.composite文件上右击鼠标,选择“Run as->Tuscany”。之后Tuscany运行环境将启动,helloworld组合构件被加入它的域中,然后发布helloworld web service服务。
Eclipse控制台消息如图-10
图-10
你可以在浏览器中,输入http://localhost:8080/HelloWorld?wsdl,可以看到此web service的wsdl内容。
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions targetNamespace="http://helloworld" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:ns0="http://helloworld" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:ns1="http://org.apache.axis2/xsd" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
<wsdl:types>
<xs:schema attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://helloworld" xmlns:ns="http://helloworld">
<xs:element name="sayHello">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="param0" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="sayHelloResponse">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="return" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
</wsdl:types>
<wsdl:message name="sayHelloRequest">
<wsdl:part name="parameters" element="ns0:sayHello">
</wsdl:part>
</wsdl:message>
<wsdl:message name="sayHelloResponse">
<wsdl:part name="parameters" element="ns0:sayHelloResponse">
</wsdl:part>
</wsdl:message>
<wsdl:portType name="HelloWorldPortType">
<wsdl:operation name="sayHello">
<wsdl:input message="ns0:sayHelloRequest" wsaw:Action="urn:sayHello">
</wsdl:input>
<wsdl:output message="ns0:sayHelloResponse" wsaw:Action="urn:sayHelloResponse">
</wsdl:output>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="HelloWorldHttpBinding" type="ns0:HelloWorldPortType">
<http:binding verb="POST"/>
<wsdl:operation name="sayHello">
<http:operation location="HelloWorld/sayHello"/>
<wsdl:input>
<mime:content part="sayHello" type="text/xml"/>
</wsdl:input>
<wsdl:output>
<mime:content part="sayHello" type="text/xml"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:binding name="HelloWorldSOAP11Binding" type="ns0:HelloWorldPortType">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="sayHello">
<soap:operation soapAction="urn:sayHello" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="HelloWorld">
<wsdl:port name="HelloWorldSOAP11port_http" binding="ns0:HelloWorldSOAP11Binding">
<soap:address location="http://192.168.209.1:8080/HelloWorld"/>
</wsdl:port>
<wsdl:port name="HelloWorldHttpport" binding="ns0:HelloWorldHttpBinding">
<http:address location="http://192.168.209.1:8080/HelloWorld"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
这样你就已经用Tuscany创建了web service。
- SCA导航2-用Tuscany构建你的第一个web service
- Tuscany SCA 发布Web Service
- Tuscany SCA 发布Web Service
- SCA导航1-Apache Tuscany SCA入门
- Tuscany SCA
- Tuscany是什么?为什么要用Tuscany命名SCA规范的实现?
- Tuscany是什么?为什么要用Tuscany命名SCA规范的实现?
- 第一个web service
- Tuscany SCA 引导和装配的过程
- Tuscany SCA与OSGI的结合方式
- Tuscany SCA 引导和装配的过程 .
- SCA 之Tuscany 10 ——SCA模型的理解
- Tuscany发布Web Service示例
- SharePoint Framework 构建你的第一个web部件(一)
- SharePoint Framework 构建你的第一个web部件(二)
- SharePoint Framework 构建你的第一个web部件(三)
- 构建你第一个App
- 使用Eclipse3.2.1+STP.0.4.0+Apache Tuscany开发SCA的Java组件(2)代码篇
- 做锚文本链接要注意什么
- Jdbc 统一数据库访问框架设计
- 资源整理
- Linux下MySQL5.1的安装
- 在Web站点中创建和使用Rss源
- SCA导航2-用Tuscany构建你的第一个web service
- asp操作access数据库实例
- 学习Microsoft .Net Remoting系列专题(Marshal、Disconnect与生命周期以及跟踪服务)
- 学习Microsoft .Net Remoting系列专题(Remoting事件处理全接触)
- 如何将3G移动商务应用于直销行业
- oracle右连接符号
- 修行
- 微软面试题
- Beginning Of Tiffany