Wednesday, June 19, 2013

WCF : 'There was an error deserializing the object of type Service.


WCF : 'There was an error deserializing the object of type Service. The maximum read depth (32) has been exceeded because XML data being read has more levels of nesting than is allowed by the quota. This quota may be increased by changing the MaxDepth property on the XmlDictionaryReaderQuotas object used when creating the XML reader.'.  



Recently I encountered the below exception for WCF service and to resolve this issue, I simply increased the readQuotas attribute 'max Depth ' value to max int value ( 2147483647) .


Exception detail:

An unexpected exception occured :System.ServiceModel.Dispatcher.NetDispatcherFaultException: The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter . The InnerException message was 'There was an error deserializing the object of type TheraCall.NextGen.UI.UserService.User. The maximum read depth (32) has been exceeded because XML data being read has more levels of nesting than is allowed by the quota. This quota may be increased by changing the MaxDepth property on the XmlDictionaryReaderQuotas object used when creating the XML reader.'. Please see InnerException for more details. ---> System.Runtime.Serialization.SerializationException: There was an error deserializing the object of type . The maximum read depth (32) has been exceeded because XML data being read has more levels of nesting than is allowed by the quota. This quota may be increased by changing the MaxDepth property on the XmlDictionaryReaderQuotas object used when creating the XML reader. ---> System.Xml.XmlException: The maximum read depth (32) has been exceeded because XML data being read has more levels of nesting than is allowed by the quota. This quota may be increased by changing the MaxDepth property on the XmlDictionaryReaderQuotas object used when creating the XML reader.

Binding Setting:
<binding name="netTCPBinding"
closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:05:00" maxReceivedMessageSize="2147483647">
<readerQuotas
maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647"
maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647"
/>
<security mode="None"></security>
< /binding>
This post confirms my ownership of the site and that this site adheres to Google Adsense program policies and terms and conditions

Wednesday, February 27, 2013

Difference between Build Solution, Rebuild Solution, and Clean Solution in Visual Studio

This blog will explain the difference between Build, Rebuild and Clean solution in visual studio:


difference between Build, Rebuild and Clean solution
Build vs Rebuild

Build: it complies and links only those source code files DLL /EXE that have changed since the last build. So normally build is faster than Rebuild and it build only those project, which have changed source code.

Rebuild : it clean all project artifices (clean bin folder)  and compile and link all source code files from scratch regardless of whether they changed or not.

Clean: it deletes all compiled files (DLL and EXE files)


Thanks for visiting!!

Friday, February 15, 2013

WCF : System.Net.Sockets.SocketException (0x80004005): An existing connection was forcibly closed by the remote host

WCF : System.Net.Sockets.SocketException (0x80004005): An existing connection was forcibly closed by the remote host
Exception:  'System.Net.Sockets.SocketException (0x80004005): An existing connection was forcibly closed by the remote host'



I  recently encountered WCF socketException and found that there could be majorly two reasons for this issue
  • Service Proxy was ideal for almost 10 minutes and after we can try to use the same service proxy.
  • Service is slowness, in this case, Service response time is crossed the default value of receiving timeout 
Considering the above two points, I made following changes in service config file, after that refreshed the client proxy with latest settings


1.       Increased the ReceivingTimeout   value to infinity

       <binding name="netTCPBinding"   receiveTimeout"infinite" >

2.       Increased the inactivityTimeout value to infinity in reliable session setting


<reliableSession inactivityTimeout="infinite" enabled="true" />

Thanks for visiting !!

Wednesday, February 13, 2013

Entity Framework : Managing Concurrency

When multiple users try to update the same record simultaneously and system is not having the concurrency control, then users can lose their recent update data, it is called the data concurrency issue and to avoid the this situation, Entity framework is already provide the Optimistic control to handle the concurrency issue.



There are basically 3 types of concurrency controls:
1.       Optimistic Concurrency : Record will be available for user only read , if it holds by some other user
2.       Pessimistic Concurrency  : Record will not be available for user only read , if it holds by some other user
3.       "Last in wins  : None Concurrency
Entity framework is already providing the Optimistic control to handle the concurrency issue and it provides two types of concurrency modes:
·    None – This is the default and means the property is not involved in any concurrency checks
·    Fixed – Which means that the original value of this property is sent as part of the WHERE clause in all updates or deletes.

Managing Concurrency Mode
Managing Concurrency Mode


Simply, we will apply the attribute ConcurrencyMode="fixed” to entity property (timestamp property would be best choice) to handle the concurrency issue .

Thanks for visiting!


Other entity framework releated links :
Entity Framework : Bulk Update

Friday, February 8, 2013

Elements of Programming Style

We can learn , how to write the good quality of code
Please visit @ http://tarunanand.typepad.com/punjabi_by_nature/2005/09/elements_of_pro.html#comments

Good quality of code is something that when you experience it once, you will never forget it.




Sunday, February 3, 2013

WCF CommunicationObjectFaultedException - The communication object, System.ServiceModel.Channels.ServiceChannel, cannot be used for communication because it is in the Faulted state.

WCF CommunicationObjectFaultedException -  The communication object, System.ServiceModel.Channels.ServiceChannel, cannot be used for communication because it is in the Faulted state.

Due to some unhandled exception  or some protocol exception, network issue or binding issue like timeout etc, A channel can be faulted.

If you do not close or abort the channel in your client, you wont be able to call the service operation unless your reestablished a new communication channel between your service and client.
Any subsequent call through this faulted channel will let your Service Fault or Communication Fault exception

To avoid this faulted Exception, follow the basic approach .

1. use the Abort() method to dispose the faulted service proxy instead of calling close() method.

2. Avoid to use the using pattern to create the service proxy and follow the below pattern to create and dispose the service proxy.


           CaseServiceClient proxy = ServiceProxyManager.CreateProxy();
            try
            {
                 
             }
            finally
            {
                ServiceProxyManager.DisposeProxy(proxy);
            }

Under DisposeProxy()  method, before disposing the service proxy , we check the proxy status and according to this, we use Abort() or Close() method to dispose the service proxy


public static class  ServiceProxyManager
{
        public static void DisposeProxy(T obj)
        {
            try
            {
                if (obj != null)
                {
                    Type t = obj.GetType();
                    MethodInfo closeMethod = t.GetMethod("Close");
                    MethodInfo abortMethod = t.GetMethod("Abort");
                    PropertyInfo property = t.GetProperty("State");
                    if (property.GetValue(obj, null).ToString().Equals(CommunicationState.Faulted))
                    {
                        abortMethod.Invoke(obj, null);
                    }
                    else
                    {
                        closeMethod.Invoke(obj, null);
                    }
                }
            }
            catch (Exception ex)
            {
                UIExceptionHandler.HandleException(ex);
            }
        }




Suggested best practices for WCF  in my previous blog

Wednesday, January 30, 2013

WCF Security: Transport Layer Security With Window Authentication

This blog will demonstrates how to setup the transport layer security with window aunthentication for wcf service 

1.       Add the following security configuration setting in Service config [binding configuration] file
   <security mode="Transport" >
       <transport protectionLevel="EncryptAndSign" clientCredentialType="Windows"></transport>
   </security>

2.       Add the following security configuration setting in Client config [binding configuration] file
  <security mode="Transport">

      <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />

      <message clientCredentialType="Windows" />

 </security>

3.       Remove the all maxhttpbinding endpoints ( Service Config)
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />

4.       Disabled anonymous authentication :  
    • Run AS :  inetmgr 
    • GO IIS Manager à Select Service Virtual Directory à Authentication  
    •  Authentication  à set the anonymous authentication disabled
5.       Enabled Window Authentication : 
    •         Run AS :  inetmgr
    •        GO IIS Manager à Select Service Virtual Directory à Authentication
    •        Authentication  à set the Window authentication enabled
    •        GO Advance Settings  à set the extended Protection value to Accept

SQL Server - Identify unused indexes

 In this blog, we learn about the index usage information (SYS.DM_DB_INDEX_USAGE_STATS) and analyze the index usage data (USER_SEEKS, USER_S...