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?