[英]WCF CultureInfo Typed DataMember Serialization CommunicationException
When I Call my WCF service's Method with CultureInfo Typed DataMember it throws CommunicationException. 当我使用CultureInfo类型为DataMember调用WCF服务的Method时,它将引发CommunicationException。
How can I solve this? 我该如何解决?
The InnerException message was 'Type 'System.Globalization.GregorianCalendar' with data contract name 'GregorianCalendar: http://schemas.datacontract.org/2004/07/System.Globalization ' is not expected.
InnerException消息是“类型'System.Globalization.GregorianCalendar”,数据协定名称为“ GregorianCalendar: http : //schemas.datacontract.org/2004/07/System.Globalization ”,这是不希望的。 Add any types not known statically to the list of known types
将任何静态未知的类型添加到已知类型列表中
[DataContract]
class MyClass
{
[DataMember]
public CultureInfo UserCulture { get; set; }
}
Add this configuration to both host and clients configs. 将此配置添加到主机和客户端配置。
<system.runtime.serialization>
<dataContractSerializer>
<declaredTypes>
<add type="System.Globalization.CultureInfo, mscorlib,Version=2.0.0.0, Culture = neutral, PublicKeyToken=b77a5c561934e089">
<knownType type="System.Globalization.GregorianCalendar,mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
</add>
</declaredTypes>
</dataContractSerializer>
CultureInfo contains a calendar field of the base class Calendar and it doesn't know about the specialized GregorianCalendar type, but we would expect that's taken care of by adding the knowntype attribute.
CultureInfo包含基类Calendar的日历字段,它不知道特殊的GregorianCalendar类型,但是我们希望可以通过添加knowntype属性来解决。
http://www.vistax64.com/indigo/65776-cultureinfo-serialization-issue-gregoriancalendar-wcf.html http://www.vistax64.com/indigo/65776-cultureinfo-serialization-issue-gregoriancalendar-wcf.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.