c# - WCF sending object through pipe communication -


i got big issue trying make work. have wcf scenario, callbacks, trying send message struct made of string , object. seems object can't serialized.

i following error trying call function sending data:

type '<>f__anonymoustype01[system.string]' cannot serialized. consider marking datacontractattribute attribute, , marking of members want serialized datamemberattribute attribute. see microsoft .net framework documentation other supported types.

the code client is:

using system; using system.servicemodel; using system.servicemodel.channels; using system.runtime.serialization; using system.io;  namespace wcfclient {     [datacontract]     public struct message     {         private string messagetype;         private object param;          public message(string _messagetype, object _param)         {             // todo: complete member initialization             this.messagetype = _messagetype;             this.param = _param;         }         [datamember]         public string type { { return messagetype; } set { messagetype = type; } }         [datamember]         public object obj { { return param; } set { param = obj; } }     }      [servicecontract(sessionmode = sessionmode.required,       callbackcontract = typeof(icallbacks))]     public interface imessagehandler     {         [operationcontract]         void handlemessage(string value);     }      public interface icallbacks     {         [operationcontract(isoneway = true)]         void queuepaths_callback(string cpath, string epath, string rpath, string ipath, string opath);         [operationcontract(isoneway = true)]         void mycallbackfunction(message msg);     }      public class callbacks : icallbacks     {         public void queuepaths_callback(string cpath, string epath, string rpath, string ipath, string opath)         {             console.writeline("callback received: ");         }         public void mycallbackfunction(message msg)         {             console.writeline("callback received: ");         }     }      class program     {         static void main(string[] args)         {             callbacks mycallbacks = new callbacks();              duplexchannelfactory<imessagehandler> pipefactory =                new duplexchannelfactory<imessagehandler>(                   mycallbacks,                   new netnamedpipebinding(),                   new endpointaddress(                      "net.pipe://localhost/pipereverse"));              imessagehandler pipeproxy =               pipefactory.createchannel();              while (true)             {                 string str = console.readline();                  pipeproxy.handlemessage(str);//send type example             }         }     } } 

and server code:

using system; using system.servicemodel; using system.runtime.serialization.formatters.binary; using system.io; using system.text;  namespace wcfserver {     [datacontract]     public struct message     {         private string messagetype;         private object param;          public message(string _messagetype, object _param)         {             // todo: complete member initialization             this.messagetype = _messagetype;             this.param = _param;         }         [datamember]         public string type { { return messagetype; } set { messagetype = type; } }         [datamember]         public object obj { { return param; } set { param = obj; } }     }     [servicecontract(sessionmode = sessionmode.required,        callbackcontract = typeof(icallbacks))]     public interface imessagehandler     {         [operationcontract]         void handlemessage(string value);     }      public interface icallbacks     {         [operationcontract(isoneway = true)]         void queuepaths_callback(string cpath, string epath, string rpath, string ipath, string opath);         [operationcontract(isoneway = true)]         void mycallbackfunction(message msg);     }      public class stringreverser : imessagehandler     {         public void handlemessage(string value)//handle type , request         {             icallbacks callbacks = operationcontext.current.getcallbackchannel<icallbacks>();             if (value.compareto("1") == 0)             {                 callbacks.queuepaths_callback("path1", "path2", "path3", "path4", "path5");              }             else             {                 console.writeline("in else");                 //binaryformatter bformatter = new binaryformatter();                 //memorystream stream = new memorystream();                  //bformatter.serialize(stream, new message(value, new { pathcompleted = "path" }));                  callbacks.mycallbackfunction(new message(value, new { pathcompleted = "path" }));             }         }     }      class program     {         static void main(string[] args)         {             using (servicehost host = new servicehost(               typeof(stringreverser),               new uri[]{           new uri("net.pipe://localhost")         }))             {                  host.addserviceendpoint(typeof(imessagehandler),                   new netnamedpipebinding(),                   "pipereverse");                  host.open();                  console.writeline("service available. " +                   "press <enter> exit.");                 console.readline();                  host.close();             }         }     } } 

why have issue objects? annonymous know in types supported data contract serializer msdn!(http://msdn.microsoft.com/en-us/library/ms731923.aspx) .net framework primitive types. following types built .net framework can serialized , considered primitive types: byte, sbyte, int16, int32, int64, uint16, uint32, uint64, single, double, boolean, char, decimal, object, , string. don't know why cant.

thank you, appreciate help


Comments

Popular posts from this blog

php - get table cell data from and place a copy in another table -

javascript - Mootools wait with Fx.Morph start -

php - Navigate throught databse rows -