使用soapextension技术


Compressing text is a procedure that can reduce the size of content representation up to 80%.
This means that compressed text can be stored using 80% less space than uncompressed text.
It also means that the content needs less time to be transferred over a network.
SOAP extensions is a Microsoft ASP.NET WebMethod interception mechanism that can be used to manipulate SOAP requests/responses before they are sent on the wire.
In most cases SOAP requests are much smaller in size than SOAP responses (for example, a large dataset), so we will only compress SOAP responses in this example.
Reference the Figure File

Improve XML Web Services' Performance by Compressing SOAP

This example is that:
The SOAP Message is compressed on AfterSerialize stage (server side) and decompressed on BeforeDeserialize stage (client side)
In order to compress our Web service's SOAP responses, we need to do two things:
· Compress the SOAP response message after serialization on the server.
· Decompress the SOAP response message before deserialization on the client.
The steps of server side are as following:
· First, here is the XML Web service that returns a large data.
 · Second,On the server side, the SOAP response from the server is compressed in order to reduce its size.
 · We add the ServerSoapExtension.dll assembly as reference and declare the SOAP extension on web.config of the XML Web service:(not necessary)
 Then,We turned to the Consumer-Side SOAP Extension
 · here need a soap extension too
 · add the ClientSoapExtension.dll assembly as reference and declare the SOAP extension on the XML Web service reference of our application
 
 Notice:
(1) In the Client,We banding the SoapExtension Class to the Method in the corresponding reference.cs,which we can find in the Web reference Item in the Client.
 And we need to add the code as following:
  /// <remarks/>
        [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/GetData", RequestNamespace="http://tempuri.org/", ResponseNamespace="http://tempuri.org/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped),SoapExtensionClient.DeCompressSoap()]
        public string GetData() {
            object[] results = this.Invoke("GetData", new object[0]);
            return ((string)(results[0]));
        }
    When the WebMethod is updated , we need to add this code manually again.
 (2) testing xml:
 string test2 = "<?xml version=/"1.0/" encoding=/"utf-8/"?><soap:Envelope xmlns:soap=/"http://schemas.xmlsoap.org/soap/envelope//" xmlns:xsi=/"http://www.w3.org/2001/XMLSchema-instance/" xmlns:xsd=/"http://www.w3.org/2001/XMLSchema/"><soap:Body><GetDataResponse xmlns=/"http://tempuri.org//"><GetDataResult>Large Data Source KKK</GetDataResult></GetDataResponse></soap:Body></soap:Envelope>";  
 
 /************************************************************************************
 * Qeustion:
 (1)why this code can not be complied in the Web.config file;
 <!--
  <webServices>
   <soapExtensionTypes>
    <add type="TestSoapExtensionWebService.CompressSoapMessage" priority="1"

group="High"/>
   </soapExtensionTypes>
  </webServices>
  -->
  
  如果是这样的话,我们需要把soap扩展单独配置成程序集,这样才能找到,但是不能在web.config里面给每个方法指定不同的soap扩展处理。
  如果要给每个方法指定不同的扩展处理,需要在WebMethod方法上一个一个的添加。
同理,在客户端我们可以在App.config中指定统一的soap扩展处理。但是如果要给每个方法指定不同的扩展处理,需要在具体的WebMethod方法的reference上一个一个的添加。
   最好我们是将soap扩展统一配置成一个程序集,便于发布和管理 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值