【发布时间】:2016-07-04 09:32:15
【问题描述】:
给定以下 DataContract:
[DataContract]
public class GetGameSessionHistory : ValueBaseCasinoIT
{
[DataMember]
public GameSession[] GameSessions => GameSessionsValue.ToArray<GameSession>();
public IEnumerable<GameSession> GameSessionsValue { get; set; }
}
由于 IEnumerable 接口,我仍然收到 GetGameSessionHistory 不可序列化的错误消息。
System.NotSupportedException: Cannot serialize member GetGameSessionHistory.GameSessionsValue of type System.Collections.Generic.IEnumerable`1[[GameSession, Common, Version=3.45.0.11, Culture=neutral, PublicKeyToken=null]] because it is an interface.
我还尝试了删除整个 [DataContract] 属性的方法,并专门使用 [IgnoreDataMember] 忽略受影响的成员。但不幸的是,这会导致相同的结果。
更新 1
给定代码中的 Lambda 表达式只是我计划做的一个步骤。使用以下 DataContract 时问题仍然存在:
[DataContract]
public class GetGameSessionHistory : ValueBaseCasinoIT
{
[DataMember]
public GameSession[] GameSessions { get; set; }
public IEnumerable<GameSession> GameSessionsValue { get; set; }
}
删除 IEnumerable 时,消息消失。所以问题不可能来自 GameSession 类型。
目前我正在使用 XmlSerializer。
数据用于以下服务:
IAdapterService:
[ServiceContract, XmlSerializerFormat(Style = OperationFormatStyle.Rpc, Use = OperationFormatUse.Encoded), DispatchByBodyBehavior]
public interface IAdapterService
{
[OperationContract(Name = "GetGameSessionHistoryRequest", Action = ""), DispatchBodyElement("GetGameSessionHistoryRequest", "...")]
GetGameSessionHistory GetGameSessionHistory(AuthenticationToken authenticationToken, string playerId, DateTime fromDate, DateTime toDate);
}
适配器服务:
[SoapDocumentService(SoapBindingUse.Literal, RoutingStyle = SoapServiceRoutingStyle.RequestElement)]
[ServiceBehavior(AddressFilterMode = AddressFilterMode.Any)]
public class AdapterService : IAdapterService
{
public GetGameSessionHistory GetGameSessionHistory(AuthenticationToken authenticationToken, string playerId, DateTime fromDate, DateTime toDate)
{ ... }
}
Web.config:
<basicHttpBinding>
<binding name="SoapBinding">
<security mode="None"/>
<readerQuotas maxDepth="4000" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="32768"/>
</binding>
</basicHttpBinding>
<service name="...svc.AdapterService" behaviorConfiguration="svcBehavior" >
<endpoint binding="basicHttpBinding" bindingConfiguration="SoapBinding" contract="...IAdapterService" name="AdapterSoapBinding" behaviorConfiguration="withMessageInspector"/>
</service>
还有什么可能导致这个问题?
【问题讨论】:
-
好吧,除此之外:它无法反序列化
GameSessions -
您能否确切地确认 WCF 配置为使用哪个序列化程序?有
DataContractSerializer和NetDataContractSerializer,可以通过配置选择。 (编辑:虽然我在答案的代码中尝试了NetDataContractSerializer,但它仍然运行良好)
标签: c# wcf datacontract datamember