To start off explaining, I have a model called VitalSign and one called VitalSignValues.
In my VitalSign model I have this code:
[ForeignKey("IdVitalSign")]
public virtual ICollection<VitalSignValue> VitalSignValues { get; set; }
In my VitalSignValue model:
public Guid IdVitalSign { get; set; }
And I got a default manager with basic functions like getAll(), ...
The project contains multiple web services and they all work fine, except for this one (VitalSignService). When I run the service, even with the WCF Test Client and I test the getAll function, it works.
The problem is that the getAll function only works like once, when I try to call the function again I suddenly get this error:
An error occurred while receiving the HTTP response to http://localhost/webservice/VitalSignService.svc. This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down). See server logs for more details.
I tried to check the trace logs, but for some reason the only information it gives me is:
ASP.Net hosted compilation
AppDomain unloading
Here is the error log (although it doesn't really contain good information for me)
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 IVitalSignService.GetAllVitalSigns() at VitalSignServiceClient.GetAllVitalSigns()
Inner Exception: The underlying connection was closed: An unexpected error occurred on a receive. at System.Net.HttpWebRequest.GetResponse() at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
Inner Exception: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. 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)
Inner Exception: 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)
EDIT:
Here is some more information:
In my application, I call this function:
var client = new VitalSignServiceClient();
_vitalSigns = client.GetAllVitalSignsWithValues().ToList();
client.Close();
Inside of my service, I got this function:
public ICollection<VitalSign> GetAllVitalSignsWithValues()
{
return _vitalSignManager.GetAll("VitalSignValues");
}
In my generic manager, this happens:
public ICollection<TObject> GetAll(params string[] navigationProperties)
{
var query = Context.Set<TObject>().AsQueryable();
foreach (string navigationProperty in navigationProperties)
query = query.Include(navigationProperty);
var list = query.ToList<TObject>();
return list;
}
When I try to find the problem through debugging, it does go into the service, into the generic manager and it does get the VitalSigns, it's just the moment where the client retrieves the data from the web service that the error occurs and everything fails.
Also remember that all of this actually works (but only 1 out of 10 times, so probably only when the server refreshed it or something)
SOLVED: Removed the "virtual" in front of the IList