Friday, 23 May 2014

WCF: The maximum message size quota for incoming messages (65536) has been exceeded


Hi Friends,


Problem: 

Recently working on one WCF project we found one issue when we are reading PDF file from SERVER using WCF. There is error like

System.ServiceModel.CommunicationException : The maximum message size quota for incoming messages (65536) has been exceeded. To increase the quota, use the MaxReceivedMessageSize property on the appropriate binding element.


Solution:

To resolve this problem we increased MaxReceivedMessageSize in app.config.
We need to increase the value of two limiting parameters: maxBufferSize and maxReceivedMessageSize. In my example these values are set to 2147483647.
For max file size in WCF, we need to set following parameter in binding files.

MaxBufferPoolSize  gets or sets the maximum size of any buffer pools used by the transport.  The default is 524,288 bytes.

MaxReceivedMessageSize gets and sets the maximum message size that can be receivied. The default is 65536 bytes.

ReaderQuotas: Defines the contraints on the complexity of SOAP messages that can be processed by endpoint configured with a binding. You need to set the maxBytesPerRead, maxDepth, maxNameTableCharCount,maxStringContentLength.

<binding name="MyService"
       maxReceivedMessageSize="2147483647"
       maxBufferSize="2147483647" transferMode="Streamed" >
       <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
     maxArrayLength="2147483647" maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647"/>
<!-- other binding info here, such as security -->
</binding>


Max possible size: MaxReceivedMessageSize to 2147483647 (i.e. Int32.MaxValue), which is 2GB

Please Note:

1.       But it’s recommended that the file size should be less, as the data is transferred through network there is possibility of slow network performance.
 
 2.       We can set it to the maximum value, which is 2GB (2147483647) - or if we’re using streamed transfers we can go up to 263 bytes (almost 10,000,000 terabytes). But remember that by setting it to a value larger than necessary we may be opening our service (or client) to attacks.
3.       Only if the service is expected to receive messages larger than 65536 bytes. And in this case, we’d be increasing MaxReceivedMessageSize on the endpoints where we expect to receive such big messages.
4.     If the messages that our client/servers expect to receive are larger than the default value for MaxReceivedMessageSize, then we need to increase this quota.

Happy Programming!!

Don’t forget to leave your feedback and comments below!

If you have any query mail me to Sujeet.bhujbal@gmail.com     

Regards
Sujeet Bhujbal
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------






Wednesday, 30 April 2014

What's New in WPF 4.5


Hi Friends,

In this article I will tell  what are the new features added in WPF with 4.5
 
·         Ribbon control
o   WPF 4.5 added with a Ribbon control that hosts a Quick Access Toolbar, Application Menu, and tabs.

·             Improved performance when displaying large sets of grouped data

·             New features for the VirtualizingPanel

·             Binding to static properties
o   You can use static properties as the source of a data binding. The data binding engine recognizes when the property's value changes if a static event is raised

·             Accessing collections on non-UI Threads
o   WPF enables you to access and modify data collections on threads other than the one that created the collection. This enables you to use a background thread to receive data from an external source, such as a database, and display the data on the UI thread. By using another thread to modify the collection, your user interface remains responsive to user interaction.


·             Synchronously and Asynchronously validating data

·             Automatically updating the source of a data binding

·             Binding to types that Implement ICustomTypeProvider

·             Retrieving data binding information from a binding expression

·             Checking for a valid DataContext object

·             Repositioning data as the data's values change (Live shaping)

·             Improved Support for Establishing a Weak Reference to an Event

·             New methods for the Dispatcher class
The Dispatcher class defines new methods for synchronous and asynchronous operations.

·             Markup Extensions for Events
o   WPF 4.5 supports markup extensions for events. While WPF does not define a markup extension to be used for events, third parties are able to create a markup extension that can be used with events.



Happy Programming!!

Don’t forget to leave your feedback and comments below!

If you have any query mail me to Sujeet.bhujbal@gmail.com     

Regards
Sujeet Bhujbal
--------------------------------------------------------------------------------

----------------------------------------------------------------------------------

Saturday, 26 April 2014

Adding WPF Windows to an existing Windows Form Project



Adding WPF Windows to an existing Windows Form Project

Last week I was working on one window application. In this application we have to add WPF window to existing Window form project


Following code describes how to add WPF window to existing Window form project

There are 2 ways we can add WPF window to existing window form application


1. Using Designer  Side


1.      Add reference to System.Windows.Forms and WindowsFormsIntegration.




Select System.Windows.Forms








Once these two references are added, we have access to all windows forms controls and access to the components that will allow us to embed them in WPF.






2. In the WPF Tool Box, we can see WindowsFormsHost control




Drag and Drop the WindowsFormsHost Control in WPF Window.

Our XAML is going to be extremely simple:




<Window x:Class = "Window1" >
xmlns= "http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="278" Width="587"
<Grid>
<WindowsFormsHost Name="WindowsFormsHost1" >

</Grid>
</Window







2. Using Code Behnind file



using System;
using System.Windows.Forms;
using System.Windows.Forms.Integration;

var wpfwindow = new WPFWindow.Window1();

ElementHost.EnableModelessKeyboardInterop(wpfwindow);

wpfwindow.Show();




In the above code The EnableModelessKeyboardInterop() call is necessary to handle keyboard input in the WPF window if loaded from a non-WPF host like WinForms.

Happy Programming!!

If you have any query mail me to Sujeet.bhujbal@gmail.com     


Regards

Sujeet Bhujbal

------------------------------------------------------------------------------------------------------------
---------------