use*_*344 6 java web-services webservice-client
我是webservices的新手,我想在我的eclipse项目中使用java来实现webservices.
所以任何人都可以告诉我如何实施和创建项目
谢谢
正如W3C所定义的,Web服务是一种软件系统,用于支持网络上可互操作的机器对机器交互.更精细的是,系统消耗来自其他软件系统的服务.
Web服务有两大类:
要实现Web服务,需要根据他/她的要求选择一个类别.Java有一堆APIS来实现这两个类别的Web服务.
实施Web服务之前的要求是:
与其他类别相比,基于REST的实现有点容易实现.因此,最好从REST投诉Web服务开始.
Web服务的工作原理:
WS作为请求 - 响应范例起作用,有一个实体将向其特定对应方(服务提供方实体)请求某些服务.根据请求,服务提供商将回复响应消息.因此,有两个消息涉及一个请求消息(XML)和一个响应消息(XML).有很多方法可以实现这些目标.细节可以在Web服务体系结构中找到
初学者可以从JERSEY jsr311标准参考实现开始构建RESTful Web服务.
示例(特定于运动衫):
第一步:创建根资源
// The Java class will be hosted at the URI path "/helloworld"
@Path("/helloworld")
public class HelloWorldResource {
@GET
@Produces("text/plain")
public String getClichedMessage() {
return "Hello World";
}
}
Run Code Online (Sandbox Code Playgroud)
第二步:部署
public class Main {
private static URI getBaseURI() {
return UriBuilder.fromUri("http://localhost/").port(8080).build();
}
public static final URI BASE_URI = getBaseURI();
protected static HttpServer startServer() throws IOException {
System.out.println("Starting ...");
ResourceConfig resourceConfig = new PackagesResourceConfig("com.sun.jersey.samples.helloworld.resources");
return GrizzlyServerFactory.createHttpServer(BASE_URI, resourceConfig);
}
public static void main(String[] args) throws IOException {
HttpServer httpServer = startServer();
System.out.println(String.format("Jersey app started with WADL available at "
+ "%sapplication.wadl\nTry out %shelloworld\nHit enter to stop it...",
BASE_URI, BASE_URI));
System.in.read();
httpServer.stop();
}
Run Code Online (Sandbox Code Playgroud)
}
Webservice是一些程序接口,它使用SOAP协议进行通信。使用soap,您可以与任何程序进行通信,无论它是用哪种语言编写的。
SOAP 是一种基于 XML 的通信协议和编码格式,用于应用程序间通信。它最初由 Microsoft 和 Userland software 构思,已经发展了几代;当前的规范是 SOAP 1.2 版本,尽管 1.1 版本更为广泛。W3C 的 XML 协议工作组负责该规范。SOAP 被广泛视为新一代跨平台跨语言分布式计算应用程序(称为 Web 服务)的支柱。
以下是一些示例:
归档时间: |
|
查看次数: |
16963 次 |
最近记录: |