473,809 Members | 2,804 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

GZOP soapextension

1 New Member
I am working on soapextension that compresses soap message.
I am stuck at only one stage now. When I get response from webservice....o n client at -BeforeDeseriali ze stage when I try to copy original or old stream to temp stream so that I can de compress it I get 'Stream dose not support seek operation' error.

Has any one come across smilar issue ...that while altering stream you could not capture it properly when client recieves it from server

debugging

This code will create new file for input and output each stage. You can see that till that point message is getting compressed and de compressed properly. Sort file by Date created
Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Web;
  5. using System.Web.Services;
  6. using System.Web.Services.Protocols;
  7. using System.IO;
  8. using System.IO.Compression;
  9. using System.Xml;
  10. using System.Threading;
  11.  
  12. namespace GZIPSoapExtension
  13. {
  14. public class GZIPSoapExtension : SoapExtension
  15. {
  16. protected Stream OriginalStream = null;
  17. protected Stream NewStream = null;
  18. protected String Mode = null;
  19. public override object GetInitializer(Type WebServiceType)
  20. {
  21. return "C:\\" + WebServiceType.FullName + ".log";
  22. }
  23.  
  24. public override object GetInitializer(LogicalMethodInfo methodInfo, SoapExtensionAttribute attribute)
  25. {
  26. return null;
  27. }
  28.  
  29. public override void Initialize(object initializer)
  30. {
  31. }
  32.  
  33. public override Stream ChainStream(Stream stream)
  34. {
  35. OriginalStream = stream;
  36. NewStream = new MemoryStream();
  37. return NewStream;
  38. }
  39.  
  40. public override void ProcessMessage(SoapMessage message)
  41. {
  42. Mode = "";
  43. switch (message.Stage)
  44. {
  45. case SoapMessageStage.BeforeSerialize:
  46. Mode = "BeforeSerialize";
  47. break;
  48. case SoapMessageStage.AfterSerialize:
  49. Mode = "AfterSerialize";
  50. AfterSerializeHandler(message);
  51. break;
  52. case SoapMessageStage.BeforeDeserialize:
  53. Mode = "BeforeDeserialize";
  54. BeforeDeserializeHandler(message);
  55. break;
  56. case SoapMessageStage.AfterDeserialize:
  57. Mode = "AfterDeserialize";
  58. break;
  59. }
  60. }
  61.  
  62. public void BeforeDeserializeHandler(SoapMessage message)
  63. {
  64. WriteToLog("BeforeDeserializeHandler -- BeforeDecompress", message, OriginalStream);
  65. Stream ms = new MemoryStream ();
  66.  
  67. Copy(OriginalStream, ms);
  68. ms.Position = 0;
  69. ms = DeCompressData(ms);
  70. ms.Position = 0;
  71. NewStream.Position = 0;
  72. Copy(ms, NewStream);
  73. ms.Position = 0;
  74. NewStream.Position = 0;
  75. WriteToLog("BeforeDeserializeHandler -- After Decompress", message, NewStream);
  76. ms.Position = 0;
  77. NewStream.Position = 0;
  78. }
  79.  
  80. public void AfterSerializeHandler(SoapMessage message)
  81. {
  82. WriteToLog("AfterSerializeHandler -- before Compress" ,message, NewStream);
  83. MemoryStream ms = new MemoryStream();
  84. NewStream.Position = 0;
  85. Copy(NewStream, ms);
  86. NewStream.Position = 0;
  87. ms.Position = 0;
  88. ms= CompressData(ms);
  89. ms.Position = 0;
  90. NewStream.Position = 0;
  91. Copy(ms, OriginalStream);
  92. ms.Position = 0;
  93. WriteToLog("AfterSerializeHandler -- After Compress", message, ms);
  94. }
  95.  
  96. protected void Copy(Stream from, Stream to)
  97. {
  98. from.Position = 0;
  99. int bytesRead;
  100. byte[] buffer = new byte[2];
  101. BinaryReader reader = new BinaryReader(from);
  102. BinaryWriter writer = new BinaryWriter(to);
  103. do
  104. {
  105. bytesRead = reader.Read(buffer, 0, buffer.Length);
  106. writer.Write(buffer, 0, bytesRead);
  107. } while (bytesRead > 0);
  108. writer.Flush();
  109. }
  110.  
  111. public MemoryStream CompressData(MemoryStream source)
  112. {
  113. if (source == null) return null;
  114. MemoryStream ms = new MemoryStream();
  115. GZipStream compressedzipStream = null;
  116. try
  117. {
  118. byte[] buffer = new byte[source.Length];
  119. source.Position = 0;
  120. source.Read(buffer, 0, buffer.Length);
  121. compressedzipStream = new GZipStream(ms, CompressionMode.Compress, true);
  122. compressedzipStream.Write(buffer, 0, buffer.Length);
  123. }
  124. finally
  125. {
  126. compressedzipStream.Close();
  127. }
  128. return ms;
  129. }
  130.  
  131. public MemoryStream DeCompressData(Stream s)
  132. {
  133. if (s == null) return null;
  134. s.Position = 0;
  135. GZipStream gs = new GZipStream(s, CompressionMode.Decompress);
  136. BinaryReader reader = new BinaryReader(gs);
  137. MemoryStream result = new MemoryStream();
  138. BinaryWriter writer = new BinaryWriter(result);
  139. int bytesRead;
  140. byte[] buffer = new byte[2];
  141. try
  142. {
  143. do
  144. {
  145. bytesRead = reader.Read(buffer, 0, buffer.Length);
  146. writer.Write(buffer, 0, bytesRead);
  147. } while (bytesRead > 0);
  148. writer.Flush();
  149. result.Position = 0;
  150. }
  151. finally
  152. {
  153. }
  154. return result;
  155. }
  156.  
  157. public void WriteToLog(String Source ,SoapMessage message, Stream s)
  158. {
  159. Thread.Sleep(1000);
  160. int bytesRead;
  161. String MsgType = null;
  162. byte[] buffer = new byte[2];
  163. if (message.GetType() == typeof(SoapServerMessage)) MsgType = "ServerMessage";
  164. if (message.GetType() == typeof(SoapClientMessage)) MsgType = "ClientMessage";
  165. //It logs message in new file. Just to make it easy to debug compressed message.
  166. FileStream fs = new FileStream("C:\\" + MsgType + "-" + Source + "-" + DateTime.Now.Second.ToString() + DateTime.Now.Millisecond.ToString() + ".txt", FileMode.Append, FileAccess.Write);
  167. try
  168. {
  169. BinaryReader reader = new BinaryReader(s);
  170. BinaryWriter writer = new BinaryWriter(fs);
  171. do
  172. {
  173. bytesRead = reader.Read(buffer, 0, buffer.Length);
  174. writer.Write(buffer, 0, bytesRead);
  175. } while (bytesRead > 0);
  176. writer.Flush();
  177. }
  178. finally
  179. {
  180. //if (swr != null) swr.Close();
  181. if (fs != null) fs.Close();
  182. }
  183. }
  184. }
  185.  
  186. [AttributeUsage(AttributeTargets.Method)]
  187. public class GZIPSoapExtensionAttribute : SoapExtensionAttribute
  188. {
  189. private int _Priority = 1;
  190. public override int Priority
  191. {
  192. get
  193. {
  194. return _Priority;
  195. }
  196. set
  197. {
  198. _Priority = value;
  199. }
  200. }
  201.  
  202. public override Type ExtensionType
  203. {
  204. get { return typeof(GZIPSoapExtension); }
  205. }
  206. }
  207. }
  208.  
May 23 '08 #1
1 1465
Plater
7,872 Recognized Expert Expert
Could you read the whole stream into a byte[] and then do all your parsing on that object?
That would allow you to do seeks on the data and index based actions?
May 27 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
1748
by: fred carter | last post by:
I would like to be able to set an arbitrary http header from a SoapExtension when said extension is acting on behalf of a client. I have not seen a means for doing so. For incoming messages or their responses (i.e. when the soap extension is intercepting a message as a server function), HttpContext... provides access to the underlying request/response http messages, so headers can be obtained or added from there. So that's fine. ...
1
3268
by: Steven.Dahlin | last post by:
I am trying to execute a soap extension with a WinForm client accessing a Web Service. I have created a application configuration which includes the following: <configuration> <system.web> <webServices> <soapExtensionTypes> <add type="mpa.TraceExtension,mpa" priority="1" group="0" /> </soapExtensionTypes>
3
3611
by: Trevor Pinkney | last post by:
Hi, Is it possible to reference a custom SoapExtension instance from within a WebMethod? I have a SoapExtension used by several web-services for generic logging. The SoapExtension logs the ServiceId, Soap Request, Start Time, End Time etc. to the database. I need to get the Id of the row the SoapExtension inserts into the database from within the Web Method. (The web method sends a
1
2168
by: Dave Buxbaum via .NET 247 | last post by:
Hi, I have a SoapExtension that adds a SoapHeader to all outboundmessages. This works fine, but I don't see a way to control thenamespace of the emitted header. Here is what I'm doing: I have created a subclass of SoapHeader ('MyHeader') and thisclass is in a defined namespace. I then create an instance ofthis class within my SoapExtension (also in a defined namespace)and add it to outbound messages using something...
2
5610
by: lprisr | last post by:
Hi, I have double byte characters in the content that I am returning using Web Services. However, the encoding in the xml file returned by Web Services is utf-8 and I am unable to read the content, not even by changing browser encoding setting to the appropriate one. I implemented SoapExtension (called EncodingExtension) to rewrite the xml to change the encoding="utf-8" to encoding="windows-1252" in BeforeDeserialize SoapMessage...
0
1280
by: Symon | last post by:
I've got a web service project that was built under VS 2003 which has a SoapExtension in the project. The SoapExtension is registered in the <soapExtensionTypes> element of the web.config and has worked fine for some time. Recently we tryed to update the project to VS 2005 and run it under ASP.NET 2.0, but now we get a compile time exception: "The value of the property 'type' cannot be parsed. The error is: Could not load file or...
0
1737
by: thatsMaBoy | last post by:
Hi, I have a VB.NET 2003 web service client (EXE) that makes use of a SOAPExtension class. The client calls a web service that returns a SOAP message containing MIME encoded files. The SOAPExtension intecepts the SOAP message and extracts the MIME, before passing on the rest of the SOAP message to the client so it can process the remainder of the data within the SOAP message. My problem is that I have taken over the project from a...
10
2223
by: Andy Kendall | last post by:
I have a problem accessing my custom SoapHeader from a SoapExtension. My extension has no compile time reference to the class derived from SoapHeader, so how can cast it into a SoapHeader of the correct type? Thanks, Andy
3
2019
by: =?Utf-8?B?Q0V2YW5z?= | last post by:
My Environment * Windows XP * .NET 2.0 * Visual Studio 2005 I have written a SoapExtension in c# on a windows XP machine. The purpose of this extension is to monitor progress for data being transfered over the wire. I have a web service that exposes one method. All this method does is return a byte array of 5 megs. When I call the service I receive all 5 megs, but my SoapException is not called until all 5 megs have been...
0
9603
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10378
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10121
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9200
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6881
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5690
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4333
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3862
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.