我有一个使用WCF服务与数据库通信的Silverlight 3.0应用程序,当我从服务方法返回大量数据时,我得到Service Not Found错误.我相信它的解决方案是简单地更新maxItemsInObjectGraph属性,但我正在以编程方式创建服务客户端,但无法找到设置此属性的位置.这就是我现在正在做的事情:
BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.None) { MaxReceivedMessageSize = int.MaxValue,MaxBufferSize = int.MaxValue }; MyService.MyServiceServiceClient client = new MyService.MyServiceProxyServiceClient(binding,new EndpointAddress(new Uri(Application.Current.Host.source,"../MyService.svc")));
解决方法
它没有在绑定中定义,而是在服务行为中定义.
在Silveright中,maxItemsInObjectGraph默认为int.MaxValue.
这是一篇关于如何为.NET应用程序更改它的文章,但不是Silverlight:Programattically setting the MaxItemsInObjectGraph property in client
一段代码:
protected ISecurityAdministrationService GetSecAdminClient() { ChannelFactory<ISecurityAdministrationService> factory = new ChannelFactory<ISecurityAdministrationService>(wsSecAdminBinding,SecAdminendpointAddress); foreach (OperationDescription op in factory.Endpoint.Contract.Operations) { DataContractSerializerOperationBehavior dataContractBehavior =op.Behaviors.Find<DataContractSerializerOperationBehavior>() as DataContractSerializerOperationBehavior; if (dataContractBehavior != null) { dataContractBehavior.MaxItemsInObjectGraph = 2147483647; } } ISecurityAdministrationService client = factory.CreateChannel(); return client; }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。