以传输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>
<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;
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);
}
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;
using Microsoft.Web.Services2;
改变改变Reference.cs Reference.cs 文件中代理类的基类为文件中代理类的基类为
Microsoft.Web.Services2.WebServicesClientProtocol
Microsoft.Web.Services2.WebServicesClientProtoco
如何找到Reference.cs?
实现例子
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);
}
}
{
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,
PublicKeyToken=31bf3856ad364e35"
priority="1" group="0" />
</soapExtensionTypes>
</webServices>
</system.web>
</configuration>
<configuration>
<system.web>
<webServices>
<soapExtensionTypes>
<add type=
"Microsoft.Web.Services2.WebServicesExtension,
PublicKeyToken=31bf3856ad364e35"
priority="1" group="0" />
</soapExtensionTypes>
</webServices>
</system.web>
</configuration>
3)WebMethod实现
using Microsoft.Web.Services2.Dime;
using Microsoft.Web.Services2;
using Microsoft.Web.Services2;
[WebMethod]
public void CreateDimedImage()
{
SoapContext respContext = ResponseSoapContext.Current;
DimeAttachment dimeAttach = new DimeAttachment(
"image/gif",
@"C:\images\test.gif");
respContext.Attachments.Add(dimeAttach);
}
public void CreateDimedImage()
{
SoapContext respContext = ResponseSoapContext.Current;
DimeAttachment dimeAttach = new DimeAttachment(
"image/gif",
@"C:\images\test.gif");
respContext.Attachments.Add(dimeAttach);
}
3、客户端引用
using Microsoft.Web.Services2.Dime;
using Microsoft.Web.Services2;
using Microsoft.Web.Services2;
改变改变Reference.cs Reference.cs 文件中代理类的基类为文件中代理类的基类为
Microsoft.Web.Services2.WebServicesClientProtocol
Microsoft.Web.Services2.WebServicesClientProtoco
如何找到Reference.cs?
实现例子
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);
}
}
{
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
Box.Show("Got it!\n"); pbDime.Image = new Bitmap( svc.ResponseSoapContext.Attachments[0].Stream); } }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。