gpt4 book ai didi

c# - '使用类型 .. 不支持 NetDataContractSerializer' - 为什么要使用 NetDataContractSerializer?

转载 作者:太空宇宙 更新时间:2023-11-03 15:46:42 26 4
gpt4 key购买 nike

此错误是因为正在使用 NetDataContractSerializer (NetDCS),但引用程序集未共享并包含在客户端中。这个问题与此无关。

这个问题是关于防止 NetDataContractSerializer 被使用;或者至少找出客户使用它的原因。

  • 为什么客户端使用 NetDCS 而我没有配置它这样做?

    根据文章/帖子我找到了这个is an explicit step ;我没有为项目或 WCF 客户端手动启用此功能 - 是否有机器/框架覆盖某处对我有利?

  • 我可以强制客户端使用正常 DataContractSerializer (DCS) 吗?

    如果是这样,我可以在每个类型或每个 namespace 的基础上强制执行此操作吗?通用框架“基本类型”已经在引用的程序集中;理想情况下,我可以使用 NetDCS 解决这些问题 - 但我会放弃所有的 NetDCS 来“修复”这个问题。

    如果没有,是否有任何更严厉的措施可用,例如修改响应/响应 XML?

    (我可以手动添加任何必需的契约(Contract)解析器并处理损坏的生成名称。)

使用 WCF 测试客户端(总是使用 DCS?)“工作正常”,这让我相信当前问题与使用项目服务时发生的 NetDCS 反序列化有关。我可能误解了 WCF 测试客户端的工作方式。

这是错误消息(可以通过为 NetDCS 添加引用程序集来解决,但我不想这样做)以确保我没有误解问题。我 95% 确定这是在客户端反序列化

The formatter threw an exception while trying to deserialize the message ..

'The use of type '..' as a get-only collection is not supported with NetDataContractSerializer. Consider marking the type with the CollectionDataContractAttribute attribute or the SerializableAttribute attribute or adding a setter to the property.'

堆栈总结:

Server stack trace: 
at System.ServiceModel.Channels.ServiceChannel.ThrowIfFaultUnderstood(Message reply, MessageFault fault, String action, MessageVersion version, FaultConverter faultConverter)
at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ref ProxyRpc rpc)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService

WCF 客户端配置是“简单”的默认配置,没有代码可以在运行时修改行为。

<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_myServiceBinding" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="endPoint.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_myServiceBinding"
contract="MyServive.IMyServiceEndPoint" name="BasicHttpBinding_serviceEndPoint" />
</client>
</system.serviceModel>

服务引用在 VS 2013 中生成,项目目标为 .NET 4。具有服务引用的项目和测试项目都是简单的类库 - 即。它们不在 IIS 中托管。

最佳答案

您可以应用 XmlSerializerFormatAttribute ( http://msdn.microsoft.com/en-us/library/system.servicemodel.xmlserializerformatattribute.aspx ) 强制您的类使用 XML 序列化程序。

关于c# - '使用类型 .. 不支持 NetDataContractSerializer' - 为什么要使用 NetDataContractSerializer?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27845011/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com