Click here to Skip to main content
15,899,937 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
AnswerRe: Multiple web site hosting in IIS having multiple domain names with static ip Pin
T M Gray13-Jul-10 8:43
T M Gray13-Jul-10 8:43 
GeneralRe: Multiple web site hosting in IIS having multiple domain names with static ip Pin
Vinay Varghese13-Jul-10 12:36
Vinay Varghese13-Jul-10 12:36 
GeneralRe: Multiple web site hosting in IIS having multiple domain names with static ip Pin
T M Gray14-Jul-10 9:37
T M Gray14-Jul-10 9:37 
GeneralRe: Multiple web site hosting in IIS having multiple domain names with static ip Pin
Vinay Varghese21-Jul-10 19:24
Vinay Varghese21-Jul-10 19:24 
Questionproblem in implementing validations in dynamically generated textboxes in Desktop vb.net application Pin
Amit Spadez9-Jul-10 2:04
professionalAmit Spadez9-Jul-10 2:04 
AnswerRe: problem in implementing validations in dynamically generated textboxes in Desktop vb.net application Pin
Eddy Vluggen10-Jul-10 23:55
professionalEddy Vluggen10-Jul-10 23:55 
QuestionCreating Triggers Using Managed Code in SQL Server 2005 Pin
brian0048-Jul-10 23:11
brian0048-Jul-10 23:11 
QuestionDecompression is not producing actual data Pin
ameem858-Jul-10 20:30
ameem858-Jul-10 20:30 
I am using the following code for compression of data at the server:

The job of this method is to execute the specified method passed as a string and return the object as a compressed stream (serializing the object and compressing the serialized stream) to the client application. When value is returned to the client, the decompression takes place there and the decompressed stream is deserialized to obtain the actual object

The method below takes parameters as name of method to be executed including the methodarguments and argumenttypes to distinguish the different overloaded methods and identify the exact method and avoid ambiguity. ExecObject is the object with which the specified method will be invoked.



//SERVER SIDE METHOD

public Stream CompressedMethodCall(string MethodName, object[] MethodArguments, Type[] ArgumentTypes, object ExecObject)
{

object Result;//the object which will be returned by the specified methodname
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter Serializer; //to serialize the object
System.IO.Compression.GZipStream Compressor;//to compress the serialized object
Stream SerializedStream;//contains the stream which is serialized
Stream CompressedStream;//contains the compressed serailized stream
byte[] Buffer;
try
{
MethodInfo mi = ExecObject.GetType().GetMethod(MethodName, ArgumentTypes);
Result = mi.Invoke(ExecObject, MethodArguments);//now result has the object which should be serialized and compressed
if (Result != null)
{
Serializer = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();//binaryformatter is used for compact serialization
SerializedStream = new MemoryStream();
Serializer.Serialize(SerializedStream, Result);//now SeralizedStream has the serialized object
SerializedStream.Position = 0;
Result = null;
CompressedStream = new MemoryStream();
Compressor = new System.IO.Compression.GZipStream(CompressedStream, System.IO.Compression.CompressionMode.Compresstrue);
while (SerializedStream.Position != SerializedStream.Length)
{
long BytesRemaining = SerializedStream.Length - SerializedStream.Position + 1;
if (BytesRemaining < BufferLength)
Buffer = new byte[BytesRemaining];
else
Buffer = new byte[BufferLength];
SerializedStream.Read(Buffer, 0, Buffer.Length);
Compressor.Write(Buffer, 0, Buffer.Length);
}
SerializedStream.Close();
CompressedStream.Position = 0;
return CompressedStream;
}
}
catch (Exception ex)
{
return null;
}
return null;
}



Now the returned value(compressed stream) is used to obtain the actual object. I am doing it this way

//CLIENT SIDE STATIC METHOD

public class DeCompressor
{
const int BufferLength = 4096;
public static object GetObject(Stream CompressedStream)
{
object Result;
BinaryFormatter DeSerializer = new BinaryFormatter();
Stream SerializedStream = new MemoryStream();
CompressedStream.Position = 0;
GZipStream DeCompressor = new GZipStream(CompressedStream, CompressionMode.Decompress,true);
byte[] Buffer;
int Read = 1;
try
{
while (Read > 0)
{
Buffer = new byte[BufferLength];
Read = DeCompressor.Read(Buffer, 0, BufferLength);
if (Read == 0) Read = DeCompressor.Read(Buffer, 0, BufferLength);//sometimes it decompressing 0 bytes eventhough there is data to be decmopressed. If I again call Read() it will decompress. To avoid this, I am using it twice
SerializedStream.Write(Buffer, 0, Read);
}
CompressedStream.Close();
SerializedStream.Position = 0;
Result = DeSerializer.Deserialize(SerializedStream);
SerializedStream.Close();
return Result;
}
catch (Exception ex)
{
Castor.CastorMessageBox.Show(ex.Message);
return null;
}
}



This method is working fine. But sometimes decompression is not producing the exact stream which was produced at server. Due to this, deserialization process is not successful and I am unable to retreive the actual object.


I am using VS2008. Any help would be appreciated
AnswerRe: Decompression is not producing actual data Pin
Luc Pattyn8-Jul-10 23:44
sitebuilderLuc Pattyn8-Jul-10 23:44 
QuestionHow to deliver our Core class library Pin
cullyk7-Jul-10 21:17
cullyk7-Jul-10 21:17 
AnswerRe: How to deliver our Core class library Pin
Ennis Ray Lynch, Jr.8-Jul-10 6:53
Ennis Ray Lynch, Jr.8-Jul-10 6:53 
GeneralRe: How to deliver our Core class library Pin
Luc Pattyn8-Jul-10 8:09
sitebuilderLuc Pattyn8-Jul-10 8:09 
AnswerRe: How to deliver our Core class library Pin
The Man from U.N.C.L.E.8-Jul-10 8:06
The Man from U.N.C.L.E.8-Jul-10 8:06 
GeneralRe: How to deliver our Core class library Pin
cullyk8-Jul-10 14:15
cullyk8-Jul-10 14:15 
GeneralRe: How to deliver our Core class library Pin
The Man from U.N.C.L.E.8-Jul-10 22:24
The Man from U.N.C.L.E.8-Jul-10 22:24 
GeneralRe: How to deliver our Core class library Pin
cullyk8-Jul-10 23:49
cullyk8-Jul-10 23:49 
AnswerRe: How to deliver our Core class library Pin
Eddy Vluggen9-Jul-10 5:25
professionalEddy Vluggen9-Jul-10 5:25 
GeneralRe: How to deliver our Core class library Pin
cullyk11-Jul-10 16:57
cullyk11-Jul-10 16:57 
GeneralRe: How to deliver our Core class library Pin
Eddy Vluggen11-Jul-10 21:29
professionalEddy Vluggen11-Jul-10 21:29 
Questiondependency (injection?) question Pin
Super Lloyd7-Jul-10 14:22
Super Lloyd7-Jul-10 14:22 
QuestionRequest format is unrecognized for URL unexpectedly ending in web method name Pin
phoopwint7-Jul-10 11:34
phoopwint7-Jul-10 11:34 
AnswerRe: Request format is unrecognized for URL unexpectedly ending in web method name Pin
Richard MacCutchan7-Jul-10 11:51
mveRichard MacCutchan7-Jul-10 11:51 
GeneralRe: Request format is unrecognized for URL unexpectedly ending in web method name Pin
phoopwint7-Jul-10 11:58
phoopwint7-Jul-10 11:58 
QuestionHELP: How to remove the Microsoft.NET Framework error dialog by programming? Pin
Curious 20096-Jul-10 15:49
Curious 20096-Jul-10 15:49 
AnswerRe: HELP: How to remove the Microsoft.NET Framework error dialog by programming? Pin
Dave Kreskowiak6-Jul-10 17:48
mveDave Kreskowiak6-Jul-10 17:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.