有没有人得到这个实际工作?关于如何启用此功能并不存在文档,尽管有3.5 SP1项目,我仍然缺少属性异常。WCF Datacontract免费序列化(3.5 SP1)
3
A
回答
1
我发现它不适用于内部/私人类型,但使我的类型公开它工作正常。这意味着没有匿名类型:(
使用反射器我发现方法ClassDataContract.IsNonAttributedTypeValidForSerialization(类型)似乎做出决定。它是最后一行似乎是杀手,类型必须是可见的,所以没有内部/私有类型允许:(
internal static bool IsNonAttributedTypeValidForSerialization(Type type)
{
if (type.IsArray)
{
return false;
}
if (type.IsEnum)
{
return false;
}
if (type.IsGenericParameter)
{
return false;
}
if (Globals.TypeOfIXmlSerializable.IsAssignableFrom(type))
{
return false;
}
if (type.IsPointer)
{
return false;
}
if (type.IsDefined(Globals.TypeOfCollectionDataContractAttribute, false))
{
return false;
}
foreach (Type type2 in type.GetInterfaces())
{
if (CollectionDataContract.IsCollectionInterface(type2))
{
return false;
}
}
if (type.IsSerializable)
{
return false;
}
if (Globals.TypeOfISerializable.IsAssignableFrom(type))
{
return false;
}
if (type.IsDefined(Globals.TypeOfDataContractAttribute, false))
{
return false;
}
if (type == Globals.TypeOfExtensionDataObject)
{
return false;
}
if (type.IsValueType)
{
return type.IsVisible;
}
return (type.IsVisible && (type.GetConstructor(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance, null, Globals.EmptyTypeArray, null) != null));
}
0
WCF中有几个序列化选项:数据契约,XML序列化和原始数据有效载荷。你试图使用哪些?从这个问题看来,您似乎在尝试使用除datacontact属性装饰的对象之外的其他东西。你在问什么?
0
是的,我正在尝试使用作为SP1(http://www.pluralsight.com/community/blogs/aaron/archive/2008/05/13/50934.aspx)的一部分发布的属性自由序列化。如果我可以使用它并且没有任何文档,那该死的。
1
我这对一个测试应用程序就好了工作...
服务定义:
[ServiceContract]
public interface IService1
{
[OperationContract]
CompositeType GetData(int value);
}
public class CompositeType
{
bool boolValue = true;
string stringValue = "Hello ";
public bool BoolValue
{
get { return boolValue; }
set { boolValue = value; }
}
public string StringValue
{
get { return stringValue; }
set { stringValue = value; }
}
}
服务实现:
public class Service1 : IService1
{
public CompositeType GetData(int value)
{
return new CompositeType()
{
BoolValue = true,
StringValue = value.ToString()
};
}
}
0
可能是我用抽象基类的是令人困惑的是,尽管我将所有内容添加到已知类型列表中。
0
是的,它可能与抽象类和继承有关。它有时会弄乱序列化。此外,如果所有内容都不公开,它可能是类和类层次结构的可见性。
相关问题
- 1. WCF DataContract需要序列化?
- 2. WCF - 在.NET 3.5 SP1中使用[DataContract]还是不使用?
- 3. Silverlight WCF序列化DataContract(IsReference = true)问题
- 4. WCF与集合的DataContract序列化
- 5. WCF/RESTful DataContract反序列化问题
- 6. 有没有一种方法可以免费安装.NET 3.5 SP1?
- 7. WCF DataContract DataMember顺序?
- 8. DataContract反序列化XML
- 9. DataContract序列化(继承)
- 10. 序列化部分DataContract
- 11. HashSet的DataContract序列化
- 12. 从经典的ASP消费WCF(与datacontract)
- 13. 可序列化和DataContract(而不是?)
- 14. WCF通用datacontract没有被序列
- 15. WCF DataContract从派生类中序列化排除数据成员
- 16. 即使在提供DataContract和DataMember后,WCF - 序列化异常
- 17. 复杂类型的WCF DataContract反序列化
- 18. 如何序列化WCF DataContract中的可空DateTime?
- 19. 使用DataContract/Data成员为WCF序列化对象
- 20. MSCharts&.NET 3.5 SP1
- 21. WCF DataContract
- 22. .net 3.5 SP1的Web API?
- 23. WCF DataContract与DataContract接口
- 24. (免费).Net程序优化程序
- 25. WCF序列化
- 26. 序列化WCF
- 27. wcf序列化
- 28. WCF和[DATACONTRACT] + [DATAMEMBER]
- 29. WCF DataContract Upcasting
- 30. DataContract在WCF
难道客户实际获得的数据? – 2009-03-03 03:03:58