Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Binary Serialization & Webserver

Binary Serialization & Webserver

Scheduled Pinned Locked Moved C#
jsonhelp
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Gilad Kapelushnik
    wrote on last edited by
    #1

    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);

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups