1

I have a class that implement IBsonSerializer:

public class PersistentObject : IBsonSerializer
    {
        public object Id { get; set; }

        public object Deserialize(BsonReader bsonReader, Type nominalType, IBsonSerializationOptions options)
        {
            throw new NotImplementedException();
        }

        public object Deserialize(BsonReader bsonReader, Type nominalType, Type actualType, IBsonSerializationOptions options)
        {
            throw new NotImplementedException();
        }

        public bool GetDocumentId(object document, out object id, out Type idNominalType, out IIdGenerator idGenerator)
        {
            throw new NotImplementedException();
        }

        public void Serialize(BsonWriter bsonWriter, Type nominalType, object value, IBsonSerializationOptions options)
        {
            throw new NotImplementedException();
        }

        public void SetDocumentId(object document, object id)
        {
            throw new NotImplementedException();
        }

    }

Is it possible to implement Serialize and Deserialize methods using WCF Serializer?

Omid.Hanjani
  • 1,444
  • 2
  • 20
  • 29
  • 1
    I don't get it. The WCF serializer should speak to the outside (your app to another app) while the BsonSerializer should speak to the database only. Are you trying to build an adapter so you can 'translate' WCF to a MongoDB connection? – mnemosyn Dec 14 '11 at 08:02
  • I think that BsonSerializer using JsonSerializer or serialize objects to json format, is it correct? so if it's correct, is it possible to use DataContractSerializer for serialize objects? – Omid.Hanjani Dec 14 '11 at 12:42
  • I don't know the `DataContractSerializer` in detail, but I'd tackle the problems on different levels. You'll need some kind of controller that manages application logic, validation and authorization in between. Why do you need the `DataContract serializer` btw? Are you building a REST API? – mnemosyn Dec 14 '11 at 13:01
  • thanks mnemosyn, I want to serialize a class with bidirectional relationship. BsonSerializer can't do it but DataContract serializer can! so what's the solution? – Omid.Hanjani Dec 14 '11 at 14:32
  • I think this boils down to the same question you asked here: http://stackoverflow.com/questions/8461996/save-an-object-with-a-bidirectional-relationship-in-mongodb-using-official-c-sha – mnemosyn Dec 14 '11 at 15:18

1 Answers1

0

You don't have to implement IBsonSerializer. MongoDB mapper can serialize your object. Take a look at http://www.mongodb.org/display/DOCS/CSharp+Driver+Serialization+Tutorial for more information and sample.

Nat
  • 3,587
  • 20
  • 22