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 -
using System;
-
using System.Collections.Generic;
-
using System.Text;
-
using System.Web;
-
using System.Web.Services;
-
using System.Web.Services.Protocols;
-
using System.IO;
-
using System.IO.Compression;
-
using System.Xml;
-
using System.Threading;
-
-
namespace GZIPSoapExtension
-
{
-
public class GZIPSoapExtension : SoapExtension
-
{
-
protected Stream OriginalStream = null;
-
protected Stream NewStream = null;
-
protected String Mode = null;
-
public override object GetInitializer(Type WebServiceType)
-
{
-
return "C:\\" + WebServiceType.FullName + ".log";
-
}
-
-
public override object GetInitializer(LogicalMethodInfo methodInfo, SoapExtensionAttribute attribute)
-
{
-
return null;
-
}
-
-
public override void Initialize(object initializer)
-
{
-
}
-
-
public override Stream ChainStream(Stream stream)
-
{
-
OriginalStream = stream;
-
NewStream = new MemoryStream();
-
return NewStream;
-
}
-
-
public override void ProcessMessage(SoapMessage message)
-
{
-
Mode = "";
-
switch (message.Stage)
-
{
-
case SoapMessageStage.BeforeSerialize:
-
Mode = "BeforeSerialize";
-
break;
-
case SoapMessageStage.AfterSerialize:
-
Mode = "AfterSerialize";
-
AfterSerializeHandler(message);
-
break;
-
case SoapMessageStage.BeforeDeserialize:
-
Mode = "BeforeDeserialize";
-
BeforeDeserializeHandler(message);
-
break;
-
case SoapMessageStage.AfterDeserialize:
-
Mode = "AfterDeserialize";
-
break;
-
}
-
}
-
-
public void BeforeDeserializeHandler(SoapMessage message)
-
{
-
WriteToLog("BeforeDeserializeHandler -- BeforeDecompress", message, OriginalStream);
-
Stream ms = new MemoryStream ();
-
-
Copy(OriginalStream, ms);
-
ms.Position = 0;
-
ms = DeCompressData(ms);
-
ms.Position = 0;
-
NewStream.Position = 0;
-
Copy(ms, NewStream);
-
ms.Position = 0;
-
NewStream.Position = 0;
-
WriteToLog("BeforeDeserializeHandler -- After Decompress", message, NewStream);
-
ms.Position = 0;
-
NewStream.Position = 0;
-
}
-
-
public void AfterSerializeHandler(SoapMessage message)
-
{
-
WriteToLog("AfterSerializeHandler -- before Compress" ,message, NewStream);
-
MemoryStream ms = new MemoryStream();
-
NewStream.Position = 0;
-
Copy(NewStream, ms);
-
NewStream.Position = 0;
-
ms.Position = 0;
-
ms= CompressData(ms);
-
ms.Position = 0;
-
NewStream.Position = 0;
-
Copy(ms, OriginalStream);
-
ms.Position = 0;
-
WriteToLog("AfterSerializeHandler -- After Compress", message, ms);
-
}
-
-
protected void Copy(Stream from, Stream to)
-
{
-
from.Position = 0;
-
int bytesRead;
-
byte[] buffer = new byte[2];
-
BinaryReader reader = new BinaryReader(from);
-
BinaryWriter writer = new BinaryWriter(to);
-
do
-
{
-
bytesRead = reader.Read(buffer, 0, buffer.Length);
-
writer.Write(buffer, 0, bytesRead);
-
} while (bytesRead > 0);
-
writer.Flush();
-
}
-
-
public MemoryStream CompressData(MemoryStream source)
-
{
-
if (source == null) return null;
-
MemoryStream ms = new MemoryStream();
-
GZipStream compressedzipStream = null;
-
try
-
{
-
byte[] buffer = new byte[source.Length];
-
source.Position = 0;
-
source.Read(buffer, 0, buffer.Length);
-
compressedzipStream = new GZipStream(ms, CompressionMode.Compress, true);
-
compressedzipStream.Write(buffer, 0, buffer.Length);
-
}
-
finally
-
{
-
compressedzipStream.Close();
-
}
-
return ms;
-
}
-
-
public MemoryStream DeCompressData(Stream s)
-
{
-
if (s == null) return null;
-
s.Position = 0;
-
GZipStream gs = new GZipStream(s, CompressionMode.Decompress);
-
BinaryReader reader = new BinaryReader(gs);
-
MemoryStream result = new MemoryStream();
-
BinaryWriter writer = new BinaryWriter(result);
-
int bytesRead;
-
byte[] buffer = new byte[2];
-
try
-
{
-
do
-
{
-
bytesRead = reader.Read(buffer, 0, buffer.Length);
-
writer.Write(buffer, 0, bytesRead);
-
} while (bytesRead > 0);
-
writer.Flush();
-
result.Position = 0;
-
}
-
finally
-
{
-
}
-
return result;
-
}
-
-
public void WriteToLog(String Source ,SoapMessage message, Stream s)
-
{
-
Thread.Sleep(1000);
-
int bytesRead;
-
String MsgType = null;
-
byte[] buffer = new byte[2];
-
if (message.GetType() == typeof(SoapServerMessage)) MsgType = "ServerMessage";
-
if (message.GetType() == typeof(SoapClientMessage)) MsgType = "ClientMessage";
-
//It logs message in new file. Just to make it easy to debug compressed message.
-
FileStream fs = new FileStream("C:\\" + MsgType + "-" + Source + "-" + DateTime.Now.Second.ToString() + DateTime.Now.Millisecond.ToString() + ".txt", FileMode.Append, FileAccess.Write);
-
try
-
{
-
BinaryReader reader = new BinaryReader(s);
-
BinaryWriter writer = new BinaryWriter(fs);
-
do
-
{
-
bytesRead = reader.Read(buffer, 0, buffer.Length);
-
writer.Write(buffer, 0, bytesRead);
-
} while (bytesRead > 0);
-
writer.Flush();
-
}
-
finally
-
{
-
//if (swr != null) swr.Close();
-
if (fs != null) fs.Close();
-
}
-
}
-
}
-
-
[AttributeUsage(AttributeTargets.Method)]
-
public class GZIPSoapExtensionAttribute : SoapExtensionAttribute
-
{
-
private int _Priority = 1;
-
public override int Priority
-
{
-
get
-
{
-
return _Priority;
-
}
-
set
-
{
-
_Priority = value;
-
}
-
}
-
-
public override Type ExtensionType
-
{
-
get { return typeof(GZIPSoapExtension); }
-
}
-
}
-
}
-
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?
Sign in to post your reply or Sign up for a free account.
Similar topics |
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.
...
|
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>
|
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
|
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...
|
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...
| |
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...
|
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...
|
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
|
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...
|
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,...
|
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...
| |
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...
|
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...
|
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();...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |