---
title: "Webservice原理一"
author: "xiaowei2002"
date: "2015-01-12T10:30:32Z"
tags: []
categories: ["企业架构"]
slug: "webservice"
draft: false
lastmod: "2015-01-12T10:30:32Z"
id: 2174340
url: "https://xiaowei2002.iteye.com/blog/2174340"
---

1.整体结构

   
![](http://dl.iteye.com/upload/attachment/334601/9887d2cd-7f99-3150-ac11-259ef877e723.jpg "点击查看原始大小图片")  
 

2.一个Web Service客户端，顾名思义是和一个Web Service服务器进行交互。

  下面是一个Web Service客户端调用Web Service的基本过程。

--&gt; 构造SOAP请求消息（将本地数据对象转换为SOAP消息）

--&gt; 发送SOAP消息到Web Service服务器的指定端口

--&gt; 接收SOAP响应消息 

--&gt; 将SOAP响应消息转换为本地数据对象

 

3.webService与SOA的关系  
  webService是SOA的一个具体实现  
  SOA是思想  
  就像面向对象和J2ee的关系  
    
   
4.SOAP基于HTTP的，在http协议下传输xml文件

 

5.UDDI:发现和整合服务，很少用

 

6.开发方法:只要获得wsdl方式即可

 

7.webService效率较慢  
  传输的是文本  
  EJB和CORBA传输的是二进制,效率较好

 

8.拦截soap请求和响应信息

  

Java代码 [![复制代码](http://darrendu.iteye.com/images/icon_copy.gif)](http://darrendu.iteye.com/blog/789922 "复制代码") [![收藏代码](http://darrendu.iteye.com/images/icon_star.png)![](http://darrendu.iteye.com/images/spinner.gif)]()

1. JaxWsServerFactoryBean factory = **new** JaxWsServerFactoryBean();
2. factory.setServiceClass(HelloImpl.**class**);
3. factory.setAddress("http://localhost:8080/helloword");
4. factory.getInInterceptors().add(**new** LoggingInInterceptor());
5. factory.getOutInterceptors().add(**new** LoggingOutInterceptor());
6. Server server = factory.create();
7. server.start();

```
JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();
		
		factory.setServiceClass(HelloImpl.class);
		factory.setAddress("http://localhost:8080/helloword");
		factory.getInInterceptors().add(new LoggingInInterceptor());
		factory.getOutInterceptors().add(new LoggingOutInterceptor());
		
		
		Server server = factory.create();
		server.start();
```

 添加拦截器

factory.getInInterceptors().add(new LoggingInInterceptor());  
factory.getOutInterceptors().add(new LoggingOutInterceptor());

 

soap消息结构：

![](http://dl.iteye.com/upload/attachment/334608/1799d292-8680-39de-8a21-32cc2383ba05.jpg)