I have the method below in a class in a test application (to validate that we can change our custom app regarding this thread). I'm encountering a strange behavior: the first time I call my AuthenticateUser() method, I get a successful response. The second time I call it, I get an exception when calling UserManagementServiceProxy.AuthenticateUser(). This pattern then repeats itself indefinitely, alternating success and failure. It doesn't appear to matter how quick or far apart (< 30 secs) subsequent requests are made.
The exception text is "The underlying connection was closed: A connection that was expected to be kept alive was closed by the server."
I found some references from a web search that identify overriding the GetWebRequest method and disabling turning off KeepAlives, and that method works if I create a class and inherit from UserManagementServiceProxy. My question is, should I have to do this, or am I doing something wrong in my client code?
Note that my example is with AuthenticateUser - which I won't be calling that frequently - but this pattern exists for any web service methods I am calling.
Thanks,
Jonathan
Code:
UserManagementServiceProxy WebServiceProxy;
Nullable<Guid> NullableGuid;
Guid AdminGuid;
private Boolean AuthenticateUser(String UserID, String Password, String WebServiceUrl)
{
InitializeWebServiceProxy(WebServiceUrl);
NullableGuid = WebServiceProxy.AuthenticateUser(UserID, Password);
if (NullableGuid != null)
{
AdminGuid = NullableGuid.Value;
return true;
}
return false;
}
private void InitializeWebServiceProxy(String WebServiceUrl)
{
if (WebServiceProxy == null)
{
WebServiceProxy = new UserManagementServiceProxy();
}
WebServiceProxy.Url = WebServiceUrl;
}