导致此错误是因为正在使用NetDataContractSerializer (NetDCS),但引用程序集没有共享并包含在客户端中。这个问题与此无关。
这个问题是关于防止NetDataContractSerializer被使用,或者至少找出客户端使用它的原因。
使用WCF测试客户端(它总是使用DCS?)“工作得很好”,这让我相信当前的问题与使用来自项目的服务时发生的NetDCS反序列化有关。我可能误解了WCF测试客户端的工作方式。
下面是错误消息(可以通过添加NetDCS的引用程序集来解决,但我不想这样做),以确保我没有误解这个问题。我95%肯定这是在反序列化的客户端。
格式化程序在试图反序列化消息时抛出一个异常。 “类型的使用”因为NetDataContractSerializer.不支持get-only集合。考虑用CollectionDataContractAttribute属性或SerializableAttribute属性标记类型,或者向属性添加一个setter。
以及堆栈摘要:
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.InvokeServiceWCF客户端配置是“简单”默认配置,没有在运行时修改行为的代码。
<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中托管。
发布于 2015-01-08 17:33:38
可以应用XmlSerializerFormatAttribute (http://msdn.microsoft.com/en-us/library/system.servicemodel.xmlserializerformatattribute.aspx)强制类使用XML序列化程序。
https://stackoverflow.com/questions/27845011
复制相似问题