使用WebService压缩传输的心得

 
   现在对WebService技术的使用已经非常多。既然是Web技术,就免不了要进行数据传输,比如传输文本、图片、Zip压缩包等等。在网络环境比较好、数据量小的情况下,传输的方式可以忽略不计,你可以选择任意的方式,不要考虑优化的问题,可以将图片、包变成二进制流进行传输,可以从数据库读出数据来,以DataSet形式进行传输。
 
   但是如果网络条件不好,或者数据量很大的情况下,应该如何做呢?
 
以传输DataSet为例,解决方案如下:
1、从数据库读取DataSet
2、使用DataSetSurrogate类序列化DataSet,转换成二维数组,一般能变成原来大小的1/3
3、使用SharpZipLib压缩
此时如果在网络上传输字节数组的话,又会讲过Base64编码,造成大小的反弹
4、使用Web Services Enhancements的WS-Attachment进行传输。将包放到SOAP附件里,而不是信封里,不用经过XML序列化。封成DIME消息(Direct Internet Message Encapsulation)
 
这样,原来的大数据就可以被封成很小的数据了。传输也变得简单、迅速。
=======================================================
使用DIME进行传输的必要条件
1、安装Microsoft WSE 2.0 SP3.msi,可以在微软的网站上下
 
2、服务器端实现
 
1) 添加Microsoft.Web.Services2.dll Microsoft.Web.Services2.dll 引用
 
2) 修改修改Web.config Web.config 配置文件配置文件
<configuration>
<system.web>
<webServices>
<soapExtensionTypes>
<add type=
"Microsoft.Web.Services2.WebServicesExtension,
Microsoft.Web.Services2, Version=2.0.0.0,
Culture=neutral,
PublicKeyToken=31bf3856ad364e35"
priority="1" group="0" />
</soapExtensionTypes>

</webServices>
</system.web>
</configuration>
 
3)WebMethod实现
using Microsoft.Web.Services2.Dime;
using Microsoft.Web.Services2;
 
[WebMethod]
public void CreateDimedImage()
{
SoapContext respContext = ResponseSoapContext.Current;
DimeAttachment dimeAttach = new DimeAttachment(
"image/gif", TypeFormat.MediaType,
@"C:\images\test.gif");
respContext.Attachments.Add(dimeAttach);
}
 
3、客户端引用
using Microsoft.Web.Services2.Dime;
using Microsoft.Web.Services2;
 
改变改变Reference.cs Reference.cs 文件中代理类的基类为文件中代理类的基类为
Microsoft.Web.Services2.WebServicesClientProtocol
 
如何找到Reference.cs?
在VS的资源管理器上选择“显示所有文件”,在Web Service下的Reference下有
 
实现例子
private void btnGetImage_Click(object sender, EventArgs e)
{
MyDimeServiceWse svc = new MyDimeServiceWse();
svc.CreateDimedImage();
if (svc.ResponseSoapContext.Attachments.Count == 1)
{
MessageBox.Show("Got it!\n");
pbDime.Image = new Bitmap(
svc.ResponseSoapContext.Attachments[0].Stream);
}
}
 

http://blog.sina.com.cn/s/blog_4b22165e01000774.html 现在对WebService技术的使用已经非常多。既然是Web技术,就免不了要进行数据传输,比如传输文本、图片、Zip压缩包等等。在网络环境比较好、数据量小的情况下,传输的方式可以忽略不计,你可以选择任意的方式,不要考虑优化的问题,可以将图片、包变成二进制流进行传输,可以从数据库读出数据来,以DataSet形式进行传输。
 
   但是如果网络条件不好,或者数据量很大的情况下,应该如何做呢?
 
以传输DataSet为例,解决方案如下:
1、从数据库读取DataSet
2、使用DataSetSurrogate类序列化DataSet,转换成二维数组,一般能变成原来大小的1/3
3、使用SharpZipLib压缩
此时如果在网络上传输字节数组的话,又会讲过Base64编码,造成大小的反弹
4、使用Web Services Enhancements的WS-Attachment进行传输。将包放到SOAP附件里,而不是信封里,不用经过XML序列化。封成DIME消息(Direct Internet Message Encapsulation)
 
这样,原来的大数据就可以被封成很小的数据了。传输也变得简单、迅速。
=======================================================
使用DIME进行传输的必要条件
1、安装Microsoft WSE 2.0 SP3.msi,可以在微软的网站上下
 
2、服务器端实现
 
1) 添加Microsoft.Web.Services2.dll Microsoft.Web.Services2.dll 引用
 
2) 修改修改Web.config Web.config 配置文件配置文件
<configuration>
<system.web>
<webServices>
<soapExtensionTypes>
<add type=
"Microsoft.Web.Services2.WebServicesExtension,
Microsoft.Web.Services2, Version=2.0.0.0,
Culture=neutral,
PublicKeyToken=31bf3856ad364e35"
priority="1" group="0" />
</soapExtensionTypes>

</webServices>
</system.web>
</configuration>
 
3)WebMethod实现
using Microsoft.Web.Services2.Dime;
using Microsoft.Web.Services2;
 
[WebMethod]
public void CreateDimedImage()
{
SoapContext respContext = ResponseSoapContext.Current;
DimeAttachment dimeAttach = new DimeAttachment(
"image/gif", TypeFormat.MediaType,
@"C:\images\test.gif");
respContext.Attachments.Add(dimeAttach);
}
 
3、客户端引用
using Microsoft.Web.Services2.Dime;
using Microsoft.Web.Services2;
 
改变改变Reference.cs Reference.cs 文件中代理类的基类为文件中代理类的基类为
Microsoft.Web.Services2.WebServicesClientProtocol
 
如何找到Reference.cs?
在VS的资源管理器上选择“显示所有文件”,在Web Service下的Reference下有
 
实现例子
private void btnGetImage_Click(object sender, EventArgs e)
{
MyDimeServiceWse svc = new MyDimeServiceWse();
svc.CreateDimedImage();
if (svc.ResponseSoapContext.Attachments.Count == 1)
{
MessageBox.Show("Got it!\n");
pbDime.Image = new Bitmap(
svc.ResponseSoapContext.Attachments[0].Stream);
}
}
 

http://blog.sina.com.cn/s/blog_4b22165e01000774.html
   现在对WebService技术的使用已经非常多。既然是Web技术,就免不了要进行数据传输,比如传输文本、图片、Zip压缩包等等。在网络环境比较好、数据量小的情况下,传输的方式可以忽略不计,你可以选择任意的方式,不要考虑优化的问题,可以将图片、包变成二进制流进行传输,可以从数据库读出数据来,以DataSet形式进行传输。
 
   但是如果网络条件不好,或者数据量很大的情况下,应该如何做呢?
 
以传输DataSet为例,解决方案如下:
1、从数据库读取DataSet
2、使用DataSetSurrogate类序列化DataSet,转换成二维数组,一般能变成原来大小的1/3
3、使用SharpZipLib压缩
此时如果在网络上传输字节数组的话,又会讲过Base64编码,造成大小的反弹
4、使用Web Services Enhancements的WS-Attachment进行传输。将包放到SOAP附件里,而不是信封里,不用经过XML序列化。封成DIME消息(Direct Internet Message Encapsulation)
 
这样,原来的大数据就可以被封成很小的数据了。传输也变得简单、迅速。
=======================================================
使用DIME进行传输的必要条件
1、安装Microsoft WSE 2.0 SP3.msi,可以在微软的网站上下
 
2、服务器端实现
 
1) 添加Microsoft.Web.Services2.dll Microsoft.Web.Services2.dll 引用
 
2) 修改修改Web.config Web.config 配置文件配置文件
<configuration>
<system.web>
<webServices>
<soapExtensionTypes>
<add type=
"Microsoft.Web.Services2.WebServicesExtension,
Microsoft.Web.Services2, Version=2.0.0.0,
Culture=neutral,
PublicKeyToken=31bf3856ad364e35"
priority="1" group="0" />
</soapExtensionTypes>

</webServices>
</system.web>
</configuration>
 
3)WebMethod实现
using Microsoft.Web.Services2.Dime;
using Microsoft.Web.Services2;
 
[WebMethod]
public void CreateDimedImage()
{
SoapContext respContext = ResponseSoapContext.Current;
DimeAttachment dimeAttach = new DimeAttachment(
"image/gif", TypeFormat.MediaType,
@"C:\images\test.gif");
respContext.Attachments.Add(dimeAttach);
}
 
3、客户端引用
using Microsoft.Web.Services2.Dime;
using Microsoft.Web.Services2;
 
改变改变Reference.cs Reference.cs 文件中代理类的基类为文件中代理类的基类为
Microsoft.Web.Services2.WebServicesClientProtocol
 
如何找到Reference.cs?
在VS的资源管理器上选择“显示所有文件”,在Web Service下的Reference下有
 
实现例子
private void btnGetImage_Click(object sender, EventArgs e)
{
MyDimeServiceWse svc = new MyDimeServiceWse();
svc.CreateDimedImage();
if (svc.ResponseSoapContext.Attachments.Count == 1)
{
MessageBox.Show("Got it!\n");
pbDime.Image = new Bitmap(
svc.ResponseSoapContext.Attachments[0].Stream);
}
}
 

http://blog.sina.com.cn/s/blog_4b22165e01000774.html
   现在对WebService技术的使用已经非常多。既然是Web技术,就免不了要进行数据传输,比如传输文本、图片、Zip压缩包等等。在网络环境比较好、数据量小的情况下,传输的方式可以忽略不计,你可以选择任意的方式,不要考虑优化的问题,可以将图片、包变成二进制流进行传输,可以从数据库读出数据来,以DataSet形式进行传输。
 
   但是如果网络条件不好,或者数据量很大的情况下,应该如何做呢?
 
以传输DataSet为例,解决方案如下:
1、从数据库读取DataSet
2、使用DataSetSurrogate类序列化DataSet,转换成二维数组,一般能变成原来大小的1/3
3、使用SharpZipLib压缩
此时如果在网络上传输字节数组的话,又会讲过Base64编码,造成大小的反弹
4、使用Web Services Enhancements的WS-Attachment进行传输。将包放到SOAP附件里,而不是信封里,不用经过XML序列化。封成DIME消息(Direct Internet Message Encapsulation)
 
这样,原来的大数据就可以被封成很小的数据了。传输也变得简单、迅速。
=======================================================
使用DIME进行传输的必要条件
1、安装Microsoft WSE 2.0 SP3.msi,可以在微软的网站上下
 
2、服务器端实现
 
1) 添加Microsoft.Web.Services2.dll Microsoft.Web.Services2.dll 引用
 
2) 修改修改Web.config Web.config 配置文件配置文件
<configuration>
<system.web>
<webServices>
<soapExtensionTypes>
<add type=
"Microsoft.Web.Services2.WebServicesExtension,
Microsoft.Web.Services2, Version=2.0.0.0,
Culture=neutral,
PublicKeyToken=31bf3856ad364e35"
priority="1" group="0" />
</soapExtensionTypes>

</webServices>
</system.web>
</configuration>
 
3)WebMethod实现
using Microsoft.Web.Services2.Dime;
using Microsoft.Web.Services2;
 
[WebMethod]
public void CreateDimedImage()
{
SoapContext respContext = ResponseSoapContext.Current;
DimeAttachment dimeAttach = new DimeAttachment(
"image/gif", TypeFormat.MediaType,
@"C:\images\test.gif");
respContext.Attachments.Add(dimeAttach);
}
 
3、客户端引用
using Microsoft.Web.Services2.Dime;
using Microsoft.Web.Services2;
 
改变改变Reference.cs Reference.cs 文件中代理类的基类为文件中代理类的基类为
Microsoft.Web.Services2.WebServicesClientProtocol
 
如何找到Reference.cs?
在VS的资源管理器上选择“显示所有文件”,在Web Service下的Reference下有
 
实现例子
private void btnGetImage_Click(object sender, EventArgs e)
{
MyDimeServiceWse svc = new MyDimeServiceWse();
svc.CreateDimedImage();
if (svc.ResponseSoapContext.Attachments.Count == 1)
{
MessageBox.Show("Got it!\n");
pbDime.Image = new Bitmap(
svc.ResponseSoapContext.Attachments[0].Stream);
}
}
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
您可以按照以下步骤在Java中实现通过Web服务接口传输压缩XML的ZIP文件: 1. 生成要传输的XML文件并将其压缩为ZIP文件。 2. 创建一个Web服务接口,将ZIP文件作为输入参数传递到该接口。 3. 在Web服务接口的实现中,使用Java的压缩文件API将ZIP文件解压缩,并读取XML内容。 4. 对XML内容执行所需的操作,并将结果作为输出返回到Web服务接口调用方。 以下是一个基本的示例代码,用于在Java中实现通过Web服务接口传输压缩XML的ZIP文件: ``` @WebService public class MyWebService { @WebMethod public String processZipFile(byte[] zipFile) { // 解压缩ZIP文件 try (ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(zipFile); ZipInputStream zipInputStream = new ZipInputStream(byteArrayInputStream)) { ZipEntry entry = zipInputStream.getNextEntry(); if (entry != null) { // 读取XML内容 byte[] xmlBytes = new byte[(int) entry.getSize()]; zipInputStream.read(xmlBytes); // 对XML内容执行所需的操作 String result = processXml(xmlBytes); return result; } } catch (IOException e) { e.printStackTrace(); } return ""; } private String processXml(byte[] xmlBytes) { // 对XML内容执行所需的操作 return "XML processing result"; } } ``` 在此示例中,`processZipFile`方法接收一个`byte[]`类型的ZIP文件,使用Java的压缩文件API解压缩ZIP文件,并读取XML内容。然后对XML内容执行所需的操作,并将结果作为输出返回到Web服务接口调用方。 请注意,此示例仅用于演示目的,您需要根据自己的具体需求进行修改和扩展。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值