Vishwamohan

Welcome to Vishwa's blog - Technology, Spirituality and More...

Error: System.ServiceModel.Channels

Recently I came across interesting error messages while calling a WCF Service Hosted in IIS 6.0 on Windows 2003 Server. From the error message, I could not figure out the real cause. But after doing some research and changing few configuration information and changing the code, it appears that these solutions fixed these errors.

 Errors

System.ServiceModel.Channels.ServiceChannel.ThrowIfFaultUnderstood(Message reply, MessageFault fault, String action, MessageVersion version, FaultConverter faultConverter)     at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)     at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway,  ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)     at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs)  at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService( IMethodCallMessage methodCall, ProxyOperationRuntime operation)     at System.ServiceModel.Channels.ServiceChannelProxy.Invoke (IMessage message)    Exception rethrown at [0]:   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage( IMessage reqMsg, IMessage retMsg)     at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) 
 Or
System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)     at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)      at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)     at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs)     at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)     at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)    Exception rethrown at [0]:      at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)     at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
Solutions
1.       Increase the default value of maxConcurrentCalls from 16 to 50 and maxConcurrentSessions from 10 to 50. You can increase even higher based on your need.
<serviceBehaviors>
    <behavior name=" ServiceBehavior1">
     <serviceMetadata httpGetEnabled="true" />
     <serviceDebug includeExceptionDetailInFaults="true" />
      <serviceThrottling maxConcurrentCalls="50" maxConcurrentSessions="50"/>     
     <serviceTimeouts />
    </behavior>  
   </serviceBehaviors>
 
2.       Use “Using Block” in Service Client to gracefully dispose the object. Also, explicitly close ChannelFactory and Client.
          Using svcClient As ServiceReference1.Service1Client = New ServiceReference1.Service1Client()
           ' Or  Using svcClient As ServiceReference1.Service1Client = New ServiceReference1.Service1Client("EndPointConfigName", "ServiceRemoteAddress")
            'Do the Service related stuff here
            'Before you end the process explicitly Close Client's ChannelFactory and Client
            'Note: Closing the ChannelFactory Closes Client as well but Closing Client does not close the ChannelFactory
            svcClient.ChannelFactory.Close()
            svcClient.Close()
        End Using
Loading