0

I want to pass a Generic object to the client, where a wrapper will take care of decoding the object. I know that WCF is not built for such a task.

I currently have the following type:

[DataContract]
public class GenericData 
{
    [DataMember(Order = 0)]
    public object Args { get; set; }
    [DataMember(Order = 0)]
    public string EventName { get; set; }
}

Where args can be of any type.

I know this is asking for a lot out of the serializer, but I want to know if there is something out there that could help me. Using KnownType is not an option, as I don't necessarily know the type being passed in at runtime.

I looked around and the only solution I can come up with is to pass in a serialized string.

  • 1
    I'd JSON serialize it and pass the name of the type so I could deserialize it later – Camilo Terevinto Oct 16 '18 at 23:52
  • What's the point of using a web service if the client has no idea what you are going to pass? Why do you ask for a "generic" object? What is the actual problem you want to solve? – Panagiotis Kanavos Oct 17 '18 at 06:40
  • Sounds like `Args` really wants to be an interface implemented by concrete argument classes. – Panagiotis Kanavos Oct 17 '18 at 06:41
  • @CamiloTerevinto I did look into using JSON, but I was a bit hesitant on using it due to a possible downfall in speed: any experience with this? – user3699878 Oct 17 '18 at 15:09
  • @PanagiotisKanavos, I want to WCF to be flexible enough to support any operation. At some point the client will not be synced with the server (meaning the operations between the client and server could be different up to an extent). Using something like REST would be the best solution, however I do want to have a Duplex connection. Also, WCF offer many types of bindings. I am new to WCF, so I could be chasing a fool's errand. – user3699878 Oct 17 '18 at 15:14
  • Versioning is a *very* big problem with REST as well. You can't just change the payload or parameters and expect clients to work without problems. WCF means SOAP, and SOAP means you *know* what's available through the WSDL and XSD. The equivalent in REST would be the Swagger/OpenAPI. – Panagiotis Kanavos Oct 17 '18 at 15:19

0 Answers0