我有一个WCF服务,它托管在一台服务器上,这个服务有一个这样的类,
[DataContract]
[Serializable()]
public class FruitObject
{
[DataMember]
public string fruitName;
[DataMember]
public byte[] data;
}
[ServiceContract]
public interface IFruits
{
[OperationContract]
FruitObject[] GetFruitsFromCrate(string cratePosition, string[] fruitNames);
}
现在我通过它在另一台服务器上使用代理来调用它,
SomeProject.WebServices.Inside.FruitObject[] fruits = proxy.GetFruitsFromCrate(cratePosition, fruitNames);
例外
描述:输入 ' System.ServiceModel.Dispatcher.NetDispatcherFaultException'在 Assembly' System.ServiceModel,Version = 4.0.0.0,Culture = neutral, PublicKeyToken ="我删除了它"'未标记为可序列化。
服务器堆栈跟踪:at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitSerialize(对象 obj,ISurrogateSelector surrogateSelector,StreamingContext context, SerObjectInfoInit serObjectInfoInit,IFormatterConverter转换器, ObjectWriter objectWriter,SerializationBinder binder)
答案 0 :(得分:0)
通过将此添加到web.config,
来修复它 1: <configuration>
2: <system.serviceModel>
3: <bindings>
4: <basicHttpBinding>
5: <binding name="myBindingForBigArrays"
6: maxReceivedMessageSize="2147483647">
7: <readerQuotas
8: maxDepth="64"
9: maxStringContentLength="2147483647"
10: maxArrayLength="2147483647"
11: maxBytesPerRead="4096"
12: maxNameTableCharCount="16384"/>
13: </binding>
14: </basicHttpBinding>
15: </bindings>
问题出在readerQuotas上,因为它设置为默认值,服务在反序列化时失败。