I have a wcf service published on my windows server.
I have a simple method which makes a simple db query in the service :
public bool HasActifContract(string accountNumber)
{
try
{
using (MyEntitites dc = new MyEntitites())
{
var client = (from ro in dc.MyClientTable where ro.AccountNumber == accountNumber select ro).FirstOrDefault();
return client != null && client.ContractExpirationDate > DateTime.Now.Date;
}
}
catch (Exception ex)
{
return false;
}
}
In my wpf application, I am calling this method like:
using (var sc = Tools.GenerateServiceReference())
{
var result = sc.HasActifContract(client.Vers_AccountNumber);
if (!result)
{
return;
}
}
Generation of the service reference :
public static ServiceClient GenerateServiceReference()
{
MyUtilities.Utility utility = new MyUtilities.Utility();
var serviceURL = ConnectionUrl + "Service.svc";
EndpointAddress ep = new EndpointAddress(new Uri(serviceURL));
BasicHttpsBinding bind = new BasicHttpsBinding(
BasicHttpsSecurityMode.TransportWithMessageCredential);
bind.MaxReceivedMessageSize = int.MaxValue;
bind.MaxBufferPoolSize = int.MaxValue;
bind.MaxBufferSize = int.MaxValue;
bind.ReceiveTimeout = new TimeSpan(0, 0, 10);
bind.SendTimeout = new TimeSpan(0, 0, 5 * 60);
bind.BypassProxyOnLocal = true;
bind.UseDefaultWebProxy = true;
bind.Security.Message.ClientCredentialType =
BasicHttpMessageCredentialType.UserName;
//construct client
ServiceClient myServiceRef = new ServiceClient(bind, ep);
//pass custom credentials
myServiceRef.ClientCredentials.UserName.UserName = utility.ServiceUserName;
myServiceRef.ClientCredentials.UserName.Password = utility.ServicePassword;
return myServiceRef;
}
The weired behavior is that the second time I call this code :
var result = sc.HasActifContract(client.Vers_AccountNumber);
there is no response the server doesn't get any call and at the end I have a timeout message.
Why the first time it works always?
Edit: I tested the same method in another seperated wpf app, it works any time I call it. The problem comes from my applicaiton I think.
Any idea, please ?