How can I set the maxItemsInObjectGraph property programmatically from a Silverlight Application?

前端 未结 3 846
悲&欢浪女
悲&欢浪女 2020-12-18 00:17

I have a Silverlight 3.0 application that is using a WCF service to communicate with the database, and when I have large amounts of data being returned from the service meth

3条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-18 01:12

    It's not defined in binding, but in Service Behavior.

    In Silveright, maxItemsInObjectGraph defaults to int.MaxValue.

    Here is an article on how to change it for .NET application, but not Silverlight: Programattically setting the MaxItemsInObjectGraph property in client

    A snippet of the code:

    protected ISecurityAdministrationService GetSecAdminClient()
    {
         ChannelFactory factory = new    ChannelFactory(wsSecAdminBinding, SecAdminEndpointAddress);
         foreach (OperationDescription op in factory.Endpoint.Contract.Operations)
         {
           DataContractSerializerOperationBehavior dataContractBehavior =op.Behaviors.Find() as DataContractSerializerOperationBehavior;
           if (dataContractBehavior != null)
           {
                 dataContractBehavior.MaxItemsInObjectGraph = 2147483647;
           }
         }
        ISecurityAdministrationService client = factory.CreateChannel();
        return client;
    }
    

提交回复
热议问题