views:

623

answers:

3

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")));
+4  A: 

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;
}
erxuan
I've looked at that, but for some reason the OperationDescription does not have a Behaviors property.
Corey Sunwold
I see. I guess because the client is a Silverilght application, the System.ServiceModel.dll is different than the .NET one.But DataContractSerializer maxItemsInObjectGraph on Silverlight defaults to int.MaxValue. Are you going to set it to a smaller value in your code?
erxuan
No. Maybe this was a misunderstanding on my part, but I thought that it defaulted to substantially less then int.MaxValue. I have had aspx pages that used WCF services and had a similar problem, and I was able to modify the maxItemsInObjectGraph in the web.config to be 2147483646 and it fixed the problem.
Corey Sunwold
Turns out you were right, there was no need to do this since in silverlight it does default to int.maxValue
Corey Sunwold
+1  A: 

Change the maxItemsInObjectGraph in your WCF service for each endpoint, changing it in Silverlight means the client will be able to support the behavior, but the service must support it aswell.

After changing it in your service, regenerate the proxy/update web service, and you will get a new ServiceReference.config, that will include the new maxItemsInObjectGraph value

Neil
The service is already updated. The problem is all of those settings that get put into the ServiceReference.config get ignored when I do I setup the client in code.
Corey Sunwold
A: 

I am also a little bit confused. From msdn, it's said the default value of maxItemsIobjectGraph is MaxValue, but without put the max int value in configuration file, it's not working... can someone explain a little bit more?

Vincent