如何从Silverlight应用程序以编程方式设置maxItemsInObjectGraph属性?

Cor*_*old 8 wcf wcf-client silverlight-3.0 .net-3.5

我有一个使用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")));
Run Code Online (Sandbox Code Playgroud)

erx*_*uan 28

它没有在绑定中定义,而是在服务行为中定义.

在Silveright中,maxItemsInObjectGraph默认为int.MaxValue.

这篇文章是关于如何为.NET应用程序更改它,但不是Silverlight:在客户端中以编程方式设置MaxItemsInObjectGraph属性

一段代码:

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;
}
Run Code Online (Sandbox Code Playgroud)