Click here to Skip to main content
15,905,144 members
Home / Discussions / C#
   

C#

 
GeneralRe: Enums and Ints Pin
[Marc]27-Oct-05 12:29
[Marc]27-Oct-05 12:29 
GeneralRe: Enums and Ints Pin
whizzs28-Oct-05 3:38
whizzs28-Oct-05 3:38 
QuestionWindowses in C# Pin
Stanciu Vlad27-Oct-05 6:30
Stanciu Vlad27-Oct-05 6:30 
AnswerRe: Windowses in C# Pin
enjoycrack27-Oct-05 10:22
enjoycrack27-Oct-05 10:22 
AnswerRe: Windowses in C# Pin
Stanciu Vlad27-Oct-05 21:39
Stanciu Vlad27-Oct-05 21:39 
Questionproblem aborting a thread on shutdown Pin
Dan Neely27-Oct-05 6:01
Dan Neely27-Oct-05 6:01 
AnswerRe: problem aborting a thread on shutdown Pin
Dan Neely27-Oct-05 7:45
Dan Neely27-Oct-05 7:45 
QuestionBinary Serialization & Webserver Pin
Gilad Kapelushnik27-Oct-05 5:45
Gilad Kapelushnik27-Oct-05 5:45 
Hi
I'm writing a small WebServer for as a project.
I have a class called Pack1 that contians some properties which I want to send to the client.

[Serializable]
public class Pack1 : ISerializable {
public float[] FloatArray1;
public float[] FloatArray2;

public Pack1(){
FloatArray1 = new float[10];
FloatArray2 = new float[10];
//
// Set Data to these arays.
//

}

public Pack1(SerializationInfo info, StreamingContext ctxt) {
FloatArray1 = (float[])info.GetValue("FloatArray1",typeof(float[]));
FloatArray2 = (float[])info.GetValue("FloatArray2",typeof(float[]));
}

public void GetObjectData(SerializationInfo info, StreamingContext ctxt) {
info.AddValue("FloatArray1",FloatArray1);
info.AddValue("FloatArray2",FloatArray2);
}
}

I use binary Serialization to for the process:

[WebMethod]
public byte[] Test_Func3(){
Pack1 P = new Pack1();
byte[] Buffer;
IFormatter formatter = new BinaryFormatter();
Stream stream = new MemoryStream(1024);
formatter.Serialize(stream,P);
Buffer = new byte[stream.Length];
stream.Seek(0,System.IO.SeekOrigin.Begin);
stream.Read(Buffer,0,Buffer.Length);
return Buffer;
}

And, I have a Binder class to with with Deserialize:

[Serializable]
public sealed class Pack1Binder : System.Runtime.Serialization.SerializationBinder {
public Pack1Binder(){
}
public override Type BindToType(string assemblyName, string typeName){
string[] typeInfo = typeName.Split('.');
string className = typeInfo[typeInfo.Length -1];
if (className.Equals("Pack1")) return typeof(Pack1);
else return Type.GetType(string.Format("{0}, {1}",typeName, assemblyName));
}
}

and a small helper:

[WebMethod]
public System.Runtime.Serialization.SerializationBinder GetSerializationBinder(){ System.Runtime.Serialization.SerializationBinder binder = new Pack1Binder();
return (System.Runtime.Serialization.SerializationBinder)binder;
}

Up until now everything is OK.
The problem is when I deserialize the data on the other side.
On the client Side I have:

Service1 Ser = new Service1();
IFormatter formatter = new BinaryFormatter();

Stream stream = new MemoryStream(1024 * 16);
stream.Flush();

byte[] Buffer = Ser.Test_Func3(10);

stream.Seek(0,System.IO.SeekOrigin.Begin);
stream.Read(Buffer,0,Buffer.Length);

stream.Flush();
stream.Write(Buffer,0,Buffer.Length);
stream.Seek(0,System.IO.SeekOrigin.Begin);

System.Runtime.Serialization.SerializationBinder binder = Ser.GetSerializationBinder(); <-- ???
formatter.Binder = binder;
Pack1 PP = (Pack1)formatter.Deserialize(stream);

The problem here is that the method GetSerializationBinder does not return the same type as System.Runtime.Serialization.SerializationBinder. If I try moving Pack1Binder to the Client then I get a message stating "Pack1 isn't serializable".

I looked over the net for a couple of hours for a solution and only found various similar questions asking pretty much the same thing.

Anyone ?

Gilad.
QuestionInstaller for C# app Pin
Xiangyang Liu 刘向阳27-Oct-05 5:40
Xiangyang Liu 刘向阳27-Oct-05 5:40 
AnswerRe: Installer for C# app Pin
Joshua Quick27-Oct-05 7:17
Joshua Quick27-Oct-05 7:17 
GeneralRe: Installer for C# app Pin
Xiangyang Liu 刘向阳27-Oct-05 8:12
Xiangyang Liu 刘向阳27-Oct-05 8:12 
GeneralRe: Installer for C# app Pin
Xiangyang Liu 刘向阳27-Oct-05 10:32
Xiangyang Liu 刘向阳27-Oct-05 10:32 
GeneralRe: Installer for C# app Pin
Joshua Quick27-Oct-05 10:51
Joshua Quick27-Oct-05 10:51 
GeneralRe: Installer for C# app Pin
Dave Kreskowiak27-Oct-05 14:25
mveDave Kreskowiak27-Oct-05 14:25 
QuestionC# Best approach to a windows form application Pin
spookas27-Oct-05 5:09
spookas27-Oct-05 5:09 
QuestionAssembly not found in release mode Pin
cppdotnet27-Oct-05 4:51
cppdotnet27-Oct-05 4:51 
AnswerRe: Assembly not found in release mode Pin
Matt Newman27-Oct-05 5:01
Matt Newman27-Oct-05 5:01 
AnswerRe: Assembly not found in release mode Pin
enjoycrack27-Oct-05 6:53
enjoycrack27-Oct-05 6:53 
GeneralRe: Assembly not found in release mode Pin
cppdotnet27-Oct-05 7:37
cppdotnet27-Oct-05 7:37 
GeneralRe: Assembly not found in release mode Pin
Dave Kreskowiak27-Oct-05 8:27
mveDave Kreskowiak27-Oct-05 8:27 
QuestionEvents over .Net Remoting Pin
Mikke_x27-Oct-05 4:47
Mikke_x27-Oct-05 4:47 
AnswerRe: Events over .Net Remoting Pin
Tom Larsen27-Oct-05 9:33
Tom Larsen27-Oct-05 9:33 
GeneralRe: Events over .Net Remoting Pin
Mikke_x27-Oct-05 9:57
Mikke_x27-Oct-05 9:57 
GeneralRe: Events over .Net Remoting Pin
Tom Larsen28-Oct-05 4:48
Tom Larsen28-Oct-05 4:48 
QuestionShared Classes Among Applications In a Single Project Pin
budidharma27-Oct-05 4:24
budidharma27-Oct-05 4:24 

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.