0

I'm connecting to a web service created by a company which validates emails. When I run it locally I'm not getting any errors but when I uploaded the module to my QA and Production computers I'm getting a timeout, I increased the timeout to 00:05:00 from 00:01:00 and now I'm getting the error:

The underlying connection was closed: A connection that was expected to be kept alive was closed by the server.mscorlibVoid HandleReturnMessage(System.Runtime.Remoting.Messaging.IMessage, System.Runtime.Remoting.Messaging.IMessage) Server stack trace: at System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebException webException, HttpWebRequest request, HttpAbortReason abortReason) at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout) at System.ServiceModel.Channels.RequestChannel.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 Redacted.Common.SI.EmailVerificationSoap.VerifyEmail(VerifyEmailRequest request) at Redacted.Common.SI.EmailVerificationSoapClient.Redacted.Common.SI.EmailVerificationSoap.VerifyEmail(VerifyEmailRequest request) at Redacted.Common.SI.EmailVerificationSoapClient.VerifyEmail(LicenseInfo LicenseInfo, String Email, Int32 Timeout, SIWsOutputOfVerifyEmailRecord& VerifyEmailResult) at Redacted.Common.ValidationHelper.ValidateEmailByService(String email) at Redacted.WindowServices.Form3.RunSpFirstTime()The underlying connection was closed: A connection that was expected to be kept alive was closed by the server.SystemSystem.Net.WebResponse GetResponse() at System.Net.HttpWebRequest.GetResponse() at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.SystemInt32 Read(Byte[], Int32, Int32) at System.Net.Sockets.NetworkStream.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)An existing connection was forcibly closed by the remote hostSystemInt32 Read(Byte[], Int32, Int32) at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)

Here is my code that connects to the web service:

using (SI.EmailVerificationSoapClient client = new EmailVerificationSoapClient())
        {

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

         client.Endpoint.Binding = customBinding;
         LicenseInfo authHeader = new LicenseInfo();

         RegisteredUser regUser = new RegisteredUser
           {
           UserID = ConfigurationHelper.GetValue("SIUsername"),
            Password = ConfigurationHelper.GetValue("SIPassword")
           };
         authHeader.RegisteredUser = regUser;
         SIWsOutputOfVerifyEmailRecord result;
         client.VerifyEmail(authHeader, email, 60, out result);
         bool hasSucceeded = 
    result.ServiceStatus.StatusNbr == 200 ||
     result.ServiceStatus.StatusNbr == 202 ||  
    result.ServiceStatus.StatusNbr == 203;
         client.Close();
         return hasSucceeded;
         }

Notice that I've set Keep Alive to false and I create and dispose the client with each call according to advice I've read on other forums regarding this problem and it still does not work.

I added a tracer and read the trace log and there is no information, it just displays the same error I pasted above. I couldn't find the webrequest in the reference.cs file to change it to keep-alive (it's a wcf service) and I'm only getting this error on production and qa, not my local machine.

Is there anything else I can do?

Eitan
  • 1,370
  • 5
  • 20
  • 49
  • what is the code running on the service - would you expect it to take longer than a minute? if not is something else going on in the service that could be the root of the problem? – Richard Blewett Jan 22 '12 at 12:06
  • It shouldn't by any chance take longer than a minute, I added the timeout just to see if it would work and I got a different error message – Eitan Jan 22 '12 at 12:09
  • 1
    my guess is you've managed to shift one problem to have it now masked by another network timeout. The issue is with what is happening inside the service so it takes so long. Do you see anything if you turn on tracing in the service? – Richard Blewett Jan 22 '12 at 13:06
  • You shouldn't place a WCF proxy into a `using` block. See http://stackoverflow.com/questions/23867/closing-and-disposing-a-wcf-service – John Saunders Jan 22 '12 at 18:14
  • I agree with Richard - something in the service is taking longer than you expected. Take a look at your environment - you said it works on local but not in QA or Production. What's different between your local box and the other two environments? That may give you an idea of what's causing your service to run longer than expected. – Tim Jan 22 '12 at 19:49

0 Answers0