none
Best way to deserialize object in .Net client from WCF (or Web API) without using built-in deserializers RRS feed

  • Question

  • I'm working on a Unity3D client / server project. The client will be done in Unity3D. I already have a server built on .Net that this client will use. The server could be adapted to use WCF or even ASP.Net Web API. However the Unity3D web player base class libraries are incompatible with System.ServiceModel so I can't deserialize messages coming from a WCF service. Similarly the Web API client is out because Unity3D is only compatible with .Net 3.5 and earlier.

    This means that I have no really easy way to consume either a WCF or a ASP.Net Web API service. If I use Unity's WWW class to make calls to one of these two APIs I would be given a big and ugly serialized .NET object to deal with in my Unity code which would be unfortunate :(.

    Does anyone know of any good methods for deserialzing these .NET objects on the client side without doing it all manually?

    Maybe there's a way to hook into the WCF client deserializers without using System.ServiceModel? Essentially giving me a way to get the raw XML from the WCF service and then feed that to some .NET classes to turn them into objects?

    Maybe there's a codeplex project or some other code somewhere that duplicates the functionality in these .NET client libraries that's not dependent on System.ServiceModel?

    I know I could manually serialize the output of each call to byte[] or xml and manually deserialize everything on the client but I would like to avoid that for a few reasons.

    1. You can't tell what the service is returning by looking at the contract.
    2. The KnownTypeAttribute is a pain in the butt to work with.

    Any help much appreciated!

    Thursday, August 28, 2014 1:29 AM

All replies

  • I am working on a project that was written a few years ago, it uses WCF, XML and Oracle with DAL sitting behind the WCF Web service. The XML is sent between the WCF client and service as string data, and the string data is loaded into a XML Document object to be used by both sides. There are no serializable DTO(s) or custom objects period being sent between the client and the service. 
    Thursday, August 28, 2014 3:05 AM
  • Hi omatase,

    In Wcf you can achieve the message serializing and de-serializing through the message formater interface and implementations. 

    Refer the below URL for implementing custom WCF serialization in request and responses.

    http://blogs.msdn.com/b/carlosfigueira/archive/2011/05/03/wcf-extensibility-message-formatters.aspx


    prabakaran.M

    Thursday, August 28, 2014 5:04 AM
  • I'm not looking to write my own serializers, I'm trying to use the .NET serializers through a kind of back-door mechanism by calling them directly.

    Thanks though.

    Friday, August 29, 2014 2:10 PM
  • This solution would work, but as I'm using .NET on both sides binary serialization is a lot less work. I think I'm just going to go that route because either I'm not asking the question correctly, or there's just no way to do this.

    • Proposed as answer by Mankdng Nef Monday, September 8, 2014 2:26 AM
    Friday, August 29, 2014 2:11 PM