惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

W
WeLiveSecurity
T
The Exploit Database - CXSecurity.com
C
CXSECURITY Database RSS Feed - CXSecurity.com
S
Security @ Cisco Blogs
T
Threat Research - Cisco Blogs
TaoSecurity Blog
TaoSecurity Blog
Recent Commits to openclaw:main
Recent Commits to openclaw:main
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
腾讯CDC
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
T
The Blog of Author Tim Ferriss
Microsoft Azure Blog
Microsoft Azure Blog
罗磊的独立博客
F
Full Disclosure
博客园 - 【当耐特】
C
CERT Recently Published Vulnerability Notes
Engineering at Meta
Engineering at Meta
Application and Cybersecurity Blog
Application and Cybersecurity Blog
T
Threatpost
I
Intezer
V2EX - 技术
V2EX - 技术
H
Hackread – Cybersecurity News, Data Breaches, AI and More
The Hacker News
The Hacker News
小众软件
小众软件
Google DeepMind News
Google DeepMind News
T
Tailwind CSS Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
B
Blog RSS Feed
Microsoft Security Blog
Microsoft Security Blog
N
News | PayPal Newsroom
MyScale Blog
MyScale Blog
AI
AI
Vercel News
Vercel News
Spread Privacy
Spread Privacy
美团技术团队
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
The GitHub Blog
The GitHub Blog
V
Vulnerabilities – Threatpost
Schneier on Security
Schneier on Security
Cyberwarzone
Cyberwarzone
G
GRAHAM CLULEY
Help Net Security
Help Net Security
Hacker News: Ask HN
Hacker News: Ask HN
Google DeepMind News
Google DeepMind News
MongoDB | Blog
MongoDB | Blog
L
LINUX DO - 热门话题
U
Unit 42
L
LangChain Blog
Recent Announcements
Recent Announcements

博客园 - neverlost

客户端开发杂记 html5 元素 来自 nativeformelements.com 闲扯,面向对象的ext4中的一些事儿1 Ext 4 beta1 发布似乎仍不给力 .net 下比较蛋疼的word 表格转excel表格 浅述教学上基于Media Player的视频切片方式 现场保障系统开发过程中增加并行处理(一) vs2010中文版+codesmith 5.2 安装失败 转的 winform开发连接webservice中单向证书 .net下开发windows服务的经验 .net 写的 webservice 给java调用 ext中使用tab方式 ext做列表页面关于查询多行的办法 关于架构的问题 ext的grid 获取页面内容方式 - neverlost - 博客园 微软.net下 charting 要注意的事情 - neverlost .net 获取 其他类型的webservice的方式以及看法 2条路 代码生成 or 配置 2.1 2条路 代码生成 or 配置 2
webservice传输数据量较大的情况的解决方案 - neverlost - 博客园
neverlost · 2010-12-30 · via 博客园 - neverlost

目前遇到的项目服务器端是java平台的,客户端是.net的,而且网络情况不定,所以服务器端采用webservice方式向客户端提供数据。

这样的情况下传输数据的量就成为影响性能的瓶颈之一。

刚开始我们针对某些返回数据量较大的方法采用gzip压缩,那么在客户端直接进行解压缩,由于不是重点直接上方法:

代码

/// <summary>
/// 对内容进行解压缩
/// </summary>
/// <param name="bytes"></param>
/// <returns></returns>
public String Decompress(byte[] bytes)
{
    
byte[] gzBuffer = bytes;
    String strret 
= "";
    
using (System.IO.MemoryStream ms = new System.IO.MemoryStream(gzBuffer))
    {
        
using (System.IO.Compression.GZipStream zs = new System.IO.Compression.GZipStream(ms, System.IO.Compression.CompressionMode.Decompress))
        {
            
using (System.IO.StreamReader sr = new System.IO.StreamReader(zs))
            {
                strret 
= sr.ReadToEnd();
            }
        }
    }
    
return strret;
}

这个时候就产生了一个问题方法多的情况下这样做还是比较麻烦。所以java平台对所有返回的内容都进行压缩这样就省事了,那么针对这样的变化客户端该怎么做可以改动最小呢?

首先增加类CompressSoapExtension继承SoapExtension

然后  override ProcessMessage方法和其他一些方法 那么剩下要做的事情就很简单了

只需要在应用程序的appconfig里增加配置节:

<system.web>

    <webServices>

      <soapExtensionTypes>

        <add type="namespace.CompressSoapExtension, app" group="High" priority="1"/>

      </soapExtensionTypes>

    </webServices>

</system.web>

补充下上面继承SoapExtension大致要override的内容:

代码

class CompressSoapExtension : SoapExtension
    {
        
/// <summary>
        
/// 旧流
        
/// </summary>
        private Stream _originStream = null;/// <summary>
        
/// 新流
        
/// </summary>
        private Stream _newStream = null;public override Stream ChainStream(Stream stream)
        {
            
this._originStream = stream;
            
this._newStream = new MemoryStream();return this._newStream;
        }
public override object GetInitializer(Type serviceType)
        {
            
return null;
        }
public override object GetInitializer(LogicalMethodInfo methodInfo, SoapExtensionAttribute attribute)
        {
            
return null;
        }
public override void Initialize(object initializer)
        {
        }
public override void ProcessMessage(SoapMessage message)
        {
            
switch (message.Stage)
            {
                
case SoapMessageStage.BeforeSerialize:
                    {
                        SoapClientMessage msg 
= message as SoapClientMessage;
                        msg.ContentEncoding 
= "gzip";
                    }
                    
break;
                
case SoapMessageStage.AfterSerialize:
                    {
                        
this._newStream.Position = 0;
                        
this._newStream.CopyTo(this._originStream);
                    }
                    
break;
                
case SoapMessageStage.BeforeDeserialize:
                    {
                        
//判断是gzip头那么就进行解压缩 这样就对原来的程序没有影响了
                        if (string.Compare(message.ContentEncoding, "gzip"true== 0)
                        {
                            
using (GZipStream zs = new GZipStream(this._originStream, CompressionMode.Decompress))
                            {
                                zs.CopyTo(
this._newStream);
                            }
                        }
                        
else
                        {
                            
this._originStream.CopyTo(this._newStream);
                        }
this._newStream.Position = 0;
                    }
                    
break;
            }
        }