0

I have a WCF client application that transmits data to a 3rd party vendor with a large .Net collection (25 mb).

The client always times out, but the vendor's service keeps running to completion.

I need the client to get a response back from the vendor service so I can go on with the next collection.

I have placed the following code at the beginning of my client application, but it still does no good. I get the same result.

"serviceClient" is my client app and "hhOutBoundClient" is the Vendor's service.

ShopProcessService.ShopProcessServiceClient serviceClient = new ShopProcessService.ShopProcessServiceClient();

            HHOutBoundService.RyderServiceClient hhOutBoundClient = new HHOutBoundService.RyderServiceClient();

            var customBinding = new CustomBinding(serviceClient.Endpoint.Binding);
            var transportElement = customBinding.Elements.Find<HttpTransportBindingElement>();
            transportElement.KeepAliveEnabled = true;
            serviceClient.Endpoint.Binding = customBinding;

Can someone please inform me how I can keep the session alive for my client so it won't time out?

Here is my client config file. Mine is the one with the wsHttpBinding.

<system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicHttpBinding_RyderService" closeTimeout="02:00:00"
                  openTimeout="02:00:00" receiveTimeout="02:00:00" sendTimeout="02:00:00"
                  allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                  maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
                  textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true"
                  messageEncoding="Text">
                    <readerQuotas maxDepth="32" maxStringContentLength="2147483647"
                      maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
                    <security mode="Transport">
                        <transport clientCredentialType="Basic" proxyCredentialType="None"
                          realm="" />
                        <message clientCredentialType="UserName" algorithmSuite="Default" />
                    </security>
                </binding>
            </basicHttpBinding>
            <wsHttpBinding>
                <binding name="WsHttpBinding_IShopProcessService" closeTimeout="02:00:00"
                  openTimeout="02:00:00" receiveTimeout="02:00:00" sendTimeout="02:00:00"
                  maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
                    <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
                      maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
                    <security mode="None" />
                </binding>
                <binding name="WSHttpBinding_IShopProcessService">
                    <security mode="None" />
                </binding>
            </wsHttpBinding>
        </bindings>
        <diagnostics wmiProviderEnabled="true">
            <messageLogging logMessagesAtTransportLevel="true" logMessagesAtServiceLevel="true" logMalformedMessages="true" logEntireMessage="true" maxSizeOfMessageToLog="2147483647" maxMessagesToLog="100" />
        </diagnostics>
        <client>
            <endpoint address="https://abc.xyz.com/RyderDataPortal/RyderService.svc"
              behaviorConfiguration="BasicHttpBinding_RyderService" binding="basicHttpBinding"
              bindingConfiguration="BasicHttpBinding_RyderService" contract="HHOutBoundService.IRyderService"
              name="BasicHttpBinding_RyderService" />
            <endpoint address="http://999.999.9.999/RyderShopProcessService/ShopProcessService.svc"
              binding="wsHttpBinding" bindingConfiguration="WsHttpBinding_IShopProcessService"
              contract="ShopProcessService.IShopProcessService" name="WsHttpBinding_IShopProcessService" />
        </client>
        <behaviors>
            <endpointBehaviors>
                <behavior name="WsHttpBinding_IShopProcessService">
                    <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
                </behavior>
                <behavior name="webhttp">
                    <webHttp/>
                </behavior>
                <behavior name="BasicHttpBinding_RyderService">
                    <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
                </behavior>
            </endpointBehaviors>
        </behaviors>
    </system.serviceModel>

I've tried everything from setting reliablemessaging properties in the binding in conjunction with the above source code in the client and vice-versa; None of it works.

I would very much appreciate somebody who has experienced this before and has come up with a definite solution.

Thanks in advance.

Exact error msg:

Message: { strMessage = Class: ShopProcessServiceClient
Method: Main
Error: The underlying connection was closed: A connection that was expected to be kept alive was closed by the server.
InnerException: System.Net.WebException: The underlying connection was closed: A connection that was expected to be kept alive was closed by the server. ---> System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
   at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
   at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
   --- End of inner exception stack trace ---
   at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
   at System.Net.FixedSizeReader.ReadPacket(Byte[] buffer, Int32 offset, Int32 count)
   at System.Net.Security._SslStream.StartFrameHeader(Byte[] buffer, Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest)
   at System.Net.Security._SslStream.StartReading(Byte[] buffer, Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest)
   at System.Net.Security._SslStream.ProcessRead(Byte[] buffer, Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest)
   at System.Net.TlsStream.Read(Byte[] buffer, Int32 offset, Int32 size)
   at System.Net.PooledStream.Read(Byte[] buffer, Int32 offset, Int32 size)
   at System.Net.Connection.SyncRead(HttpWebRequest request, Boolean userRetrievedStream, Boolean probeRead)
   --- End of inner exception stack trace ---
   at System.Net.HttpWebRequest.GetResponse()
   at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
Source: mscorlib
StackTrace: 
Server stack trace: 
   at System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebException webException, HttpWebRequest request, HttpAbortReason abortReason)
   at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
   at 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.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)
   at Ryder.ShopProcessService.Outbound.HHOutBoundService.IRyderService.PostFuelTankConversionCharts(TankConversionChartCollection conversion_charts)
   at Ryder.ShopProcessService.Outbound.HHOutBoundService.RyderServiceClient.PostFuelTankConversionCharts(TankConversionChartCollection conversion_charts) in c:\Development\SMO_VS_2013\HHOutboundClient\SOASolutionA\Ryder.ShopProcessService.Outbound\Service References\HHOutBoundService\Reference.cs:line 2856
   at Ryder.ShopProcessService.Outbound.ShopProcessServiceClient.Main(String[] args) in c:\Development\SMO_VS_2013\HHOutboundClient\SOASolutionA\Ryder.ShopProcessService.Outbound\ShopProcessServiceClient.cs:line 87, strProject = Ryder.ShopProcessService.Outbound, strRemedyTktResponse = INC000000091926 }

Extended Properties:
sagesky36
  • 4,542
  • 19
  • 82
  • 130
  • What is the timeout message you get? Is TCP binding on aoption? – PatFromCanada Sep 20 '14 at 14:53
  • This must be done using wsHttpBinding. The message is the usual where it says the client had to be forcibly closed because of a connection could not remain open, etc... – sagesky36 Sep 20 '14 at 23:44
  • Why do you think it is timing out? It could be erroring while processing a particular bit of data, does this help? http://stackoverflow.com/questions/7209823/an-existing-connection-was-forcibly-closed-by-the-remote-host-wcf – PatFromCanada Sep 21 '14 at 14:55
  • This worked fine with test data since the sample size was a lot smaller. Now, using production data, the sample size is a lot bigger somehow forcing a client timeout. – sagesky36 Sep 21 '14 at 16:54
  • This is apparently a firewall issue on our side. Upping the tcp idle firewall timeout would do the job, but it has potential for a security risk. We are exploring other options such as simply sending the file over to the vendor and for them not to do any processing. They were doing dynamic processing on their side once they received the file instead of processing it offline. – sagesky36 Sep 23 '14 at 22:21
  • Did you try compression? I achieved better than 90% compression today on a DTO collection that had a lot of repeated data. Transmission times shrank considerably as well. – PatFromCanada Sep 24 '14 at 02:01
  • Pat, the files will make it over there if the vendor doesn't do any dynamic processing on their end. In other words, I get the data, send the .Net collection, and receive a response back from the vendor. Then, they can do their processing offline with the files. – sagesky36 Sep 24 '14 at 17:39

2 Answers2

1

You have to increase send timeout.

<binding name="BasicHttpBinding_RyderService" sendTimeout="20:00:00" closeTimeout="02:00:00"
                  openTimeout="02:00:00" receiveTimeout="02:00:00" 
                  allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                  maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
                  textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true"
                  messageEncoding="Text">

or

serviceClient.Endpoint.Binding = customBinding;
serviceClient.Endpoint.Binding.SendTimeout = new TimeSpan(0, 25, 0);
Mohsen Esmailpour
  • 11,224
  • 3
  • 45
  • 66
  • I know it just takes 1.5 hours to get the data from my client and send the data from my client to the service vendor. So, I don't think increasing the sendtimeout to 20 hours would suffice. 2 hours should be enough. Don't you agree? – sagesky36 Sep 20 '14 at 23:42
  • Ya 1h 45min is enough. – Mohsen Esmailpour Sep 21 '14 at 17:54
0

in WCF either client can affect Session settings like timeout. i mean either in Client side Web.config set timeout see :


<bindings> <wsHttpBinding> <binding name="WSHttpBinding_I" maxReceivedMessageSize="2000000" sendTimeout="[some value]"/> </wsHttpBinding> </bindings>