I have images and videos I will need to pass from the client to the server side where I will save the image/video on the server and a link to it in the database. When I try to pass the image (very small picture) I get:
The maximum array length quota (16384) has been exceeded while reading XML data
Here is my code
ServicesReverences.ClientConfig file
<configuration> <system.serviceModel> <bindings> <customBinding> <binding name="CustomBinding_wcfDataLayer"> <binaryMessageEncoding /> <httpTransport maxReceivedMessageSize="5242880" maxBufferSize="5242880" /> </binding> </customBinding> </bindings> <client> <endpoint address="http://localhost:59582/wcfDataLayer.svc" binding="customBinding" bindingConfiguration="CustomBinding_wcfDataLayer" contract="dataProxy.wcfDataLayer" name="CustomBinding_wcfDataLayer" /> </client> </system.serviceModel> </configuration>
Code on button to pass the image to the WCF
Private Sub btnFindPictureDialog_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) ' Create an instance of the open file dialog box. Dim openFileDialog1 As OpenFileDialog = New OpenFileDialog openFileDialog1.Filter = "Jpeg (*.jpg)|*.jpg|Gif (*.gif)|*.gif|Png (*.png)|*.png" openFileDialog1.FilterIndex = 1 Dim UserClickedOK As Boolean = openFileDialog1.ShowDialog If UserClickedOK Then If openFileDialog1.File.ToString().Trim() <> "" Then txtResults.Text = openFileDialog1.File.ToString() btnAddPictureToAlbum.IsEnabled = True 'build the image file to store Dim stream As Stream = DirectCast(openFileDialog1.File.OpenRead(), Stream) Dim bytes As Byte() = New Byte(stream.Length) {} stream.Read(bytes, 0, CInt(stream.Length)) Dim fileName As String = openFileDialog1.File.Name Dim imagefile As New dataProxy.clsImageFile imagefile.ImageName = fileName imagefile.Imagestream = bytes Dim albumEntity As New dataProxy.AlbumEntity albumEntity.AlbumName = DirectCast(grdAlbums.Columns(0).GetCellContent(grdAlbums.SelectedItem), TextBlock).Text() 'album name from datagrid albumEntity.ID = DirectCast(grdAlbums.Columns(1).GetCellContent(grdAlbums.SelectedItem), TextBlock).Text() 'album id from the data grid Dim galleryEntity As New dataProxy.GalleryEntity galleryEntity.PicType = "P" galleryEntity.PicDate = Today.ToShortDateString() galleryEntity.PicTime = TimeOfDay().ToString("t") _proxy.UploadAsync(imagefile, albumEntity, galleryEntity) <============= I get the error message here AddHandler _proxy.UploadCompleted, AddressOf _proxy_UploadCompleted End If End If End Sub Any help is greatly appreciated
Answer: 1
Hi skifreak,
You need to set the readerquotas on the binding both on the server side and the client side, to allow bigger arrays, you need to change 2 config files, the client's app.config and the Server's config file.
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
For details, you can refer from here:
http://scorpiotek.com/blog/?p=393
Best Regards,
by :Answer: 2
OK I was able to add to the web.config per the link you gave me but I don't have an app.config. I have 3 projects (Web, SL, Business logic). I have a web.config in my web project
I have a ServicesReferences.ClientConfig in my SL project
I have an app.config in my Business Logic and all it has are listeners and connection string information.
What am I missing?
Mark
by :Answer: 3
You wil need to adjust the httpRuntime maxRequestLength value in you web.config to increase the file upload max size. Read here for more info:
http://msdn.microsoft.com/en-us/library/e1f13641(v=vs.71).aspx
Here is an example web.config I use for large file uploads:
<!-- Allows for large files to be passed into the service. --> <!-- Default is 4mb, below is setting it to 40mb. --> <system.web> <httpRuntime maxRequestLength="40960" /> </system.web> <bindings> <customBinding> <!-- Defines the http binding for the WCF services with qoutas maxed out. --> <!-- Uses Negotiate authentication, see here for other options: http://msdn.microsoft.com/en-us/library/ms789031.aspx --> <binding name="binaryHttpBinding" closeTimeout="00:20:00" openTimeout="00:20:00" receiveTimeout="00:20:00" sendTimeout="00:20:00"> <binaryMessageEncoding maxReadPoolSize="2147483647" maxWritePoolSize="2147483647" maxSessionSize="2147483647"> <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" /> </binaryMessageEncoding> <httpTransport maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" authenticationScheme="Negotiate" maxBufferSize="2147483647" transferMode="Buffered" /> </binding> </customBinding> </bindings> <!-- Sets up the behaviors for the WCF services allowing for http traffic --> <!-- and sets the maxItemsInObjectGraph attribute to handle large service calls. --> <behaviors> <serviceBehaviors> <behavior name="WCFServiceBehavior"> <serviceMetadata httpGetEnabled="true" /> <serviceDebug includeExceptionDetailInFaults="true" /> <dataContractSerializer maxItemsInObjectGraph="2147483647" /> </behavior> </serviceBehaviors> </behaviors> <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" /> <-- Sets a WCF service to use the above defined web.config entries. --> <services> <service behaviorConfiguration="WCFServiceBehavior" name="WCFService"> <endpoint address="" binding="customBinding" bindingConfiguration="binaryHttpBinding" contract="WCFService" /> </service> </services>
Answer: 4
I used your binding settings (I was close but I saw where I couldn't find the settings) and I made it past that nasty error! Thanks a ton!
by :
No comments:
Post a Comment
Send us your comment related to the topic mentioned on the blog