如何使用wcf序列化程序序列化mongodb c#驱动程序中的对象?
我有一个实现IBsonSerializer的类:如何使用wcf序列化程序序列化mongodb c#驱动程序中的对象?,c#,mongodb,serialization,C#,Mongodb,Serialization,我有一个实现IBsonSerializer的类: public class PersistentObject : IBsonSerializer { public object Id { get; set; } public object Deserialize(BsonReader bsonReader, Type nominalType, IBsonSerializationOptions options) {
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();
}
}
是否可以使用WCF Serializer实现序列化和反序列化方法?您不必实现IBsonSerializer。MongoDB映射器可以序列化对象。查看更多信息和样本。我不明白。WCF序列化程序应与外部(您的应用程序与另一个应用程序)对话,而BsonSerializer应仅与数据库对话。您是否正在尝试构建适配器,以便将WCF“转换”到MongoDB连接?我认为BsonSerializer使用JsonSerializer或将对象序列化为json格式,是否正确?因此,如果它是正确的,是否可以使用DataContractSerializer来序列化对象?我不知道详细的
DataContractSerializer
,但我会在不同的级别上解决问题。您需要某种控制器来管理应用程序逻辑、验证和授权。为什么需要DataContract序列化程序
btw?您正在构建RESTAPI吗?谢谢mnemosyn,我想序列化一个具有双向关系的类。BsonSerializer无法完成,但DataContract序列化程序可以!那么解决方案是什么呢?我想这可以归结为你在这里问的同一个问题: