views:

2996

answers:

1

I'm getting the following exception while sending ( or receiving ) a byte array to a C# service.

There was an error deserializing the object of type System.Byte[]. 
The maximum array length quota (16384) has been exceeded while reading XML data. 
This quota may be increased by changing the MaxArrayLength property on the XmlDictionaryReaderQuotas object used when creating the XML reader. 
Line 6, position 34838.'.  
Please see InnerException for more details

For what I can understand the XmlDictionaryreader is created automatically by the webservice.

So, how can I change the "MaxArrayLength" property?

This is the implementation code:

    public string addFile(string sharePointServer, string documentLibrary, 
                          byte[] content, string fileName) 
    {
        try
        {
            SPWeb spWeb = new SPSite(sharePointServer).OpenWeb();
            SPFolder spFolder = spWeb.GetFolder(documentLibrary);
            SPFileCollection spFileCollection = spFolder.Files;
            SPFile spFile = spFileCollection.Add(fileName, content, true);
            return spFile.TimeCreated.ToLongDateString() + "::" + spFile.Title;
        } 
            catch (Exception ex) 
        {
            throw ex;
        }
    }

Files < 16kb are uploaded.

Files > 16kb are not.

Files > 10mb are downloaded without problem.

Where is that property configured?

+2  A: 

Is it a WCF service? If so, you can change the maxarraylength in the binding as seen on this SO post:

post

P.S. Why would you use a custom Service when there are OOTB Sharepoint services that can upload files? i.e. the Lists.asmx like in this article:

article

Colin
@Colin: It may be too obvious to you, but I didn't quite get it. Are you saying the configuration is in the file posted by the question: http://bit.ly/QMhME ? which file is that. The accepted answer for that question redirects to another post which in turn redirects to a download. If you know the answer to my problem would you mind post it here? Is this a WCF service? I guess. I'm the client invoking that service with Java, not really creating the ws. I'll take a look at the List.asmx you posted. Why wasn't taht used? I guess nobody knew it existed.
OscarRyz
OK, so you are using Java. Please update your question so that is clear. My question meant, is the Service you are calling an "old-fashioned" C# webservice, or a "new" Windows Communication Foundation" Service. My answer only helps if the second is true.The exception you are showing, is that from C# or Java?P.S. This is a code example for changing qouta:EndpointAddress endPoint = new EndpointAddress("http://address/Service");WSHttpBinding binding = new WSHttpBinding();XmlDictionaryReaderQuotas readerQuotas = XmlDictionaryReaderQuotas.Max;binding.ReaderQuotas = readerQuotas;
Colin
P.S. The Lists.asmx (http://urlofsite/_vti_bin/Lists.asmx) is really the way to go, seeing as it is out of the box functionality.
Colin