Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
556 views
in Technique[技术] by (71.8m points)

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

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 methods I get Service Not Found errors. I am fairly confident that the solution to it is to simply update the maxItemsInObjectGraph property, but I am creating the service client progrogrammatically and cannot find where to set this property. Here is what I am doing right now:

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")));
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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<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;
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...