代码之家  ›  专栏  ›  技术社区  ›  Corey Sunwold

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

  •  8
  • Corey Sunwold  · 技术社区  · 16 年前

    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")));
    
    3 回复  |  直到 16 年前
        1
  •  28
  •   erxuan    16 年前

    它不是在绑定中定义的,而是在服务行为中定义的。

    在Silverlight中,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;
    }
    
        2
  •  3
  •   Perrin    14 年前

    下面是我在继承自的客户机对象中使用的函数

    System.ServiceModel.ClientBase(Of IServiceName)
    

    该方法的目的是通过编程为每个操作设置MaxItemsInObjectGraph值。这让我有更复杂的结构。

        Private Sub IncreaseObjectCount()
            For Each op As System.ServiceModel.Description.OperationDescription In Me.Endpoint.Contract.Operations
                For Each dscob As System.ServiceModel.Description.DataContractSerializerOperationBehavior In op.Behaviors.FindAll(Of System.ServiceModel.Description.DataContractSerializerOperationBehavior)()
                    dcsob.MaxItemsInObjectGraph = Integer.MaxValue
                Next dcsob
            Next op
        End Sub
    

        3
  •  1
  •   Neil    16 年前

    在WCF服务中为每个端点更改maxItemsInObjectGraph,在Silverlight中更改它意味着客户端将能够支持该行为,但服务也必须支持它。

    在您的服务中更改它之后,重新生成代理/更新web服务,您将获得一个新的ServiceReference.config,其中将包含新的maxItemsInObjectGraph值

    推荐文章