Note that there are some explanatory texts on larger screens.

plurals
  1. POWCF call fails when results returned from Entity Framework
    primarykey
    data
    text
    <p>I have created a simple test solution using Entity Framework and WCF. I have only one function in the service contract, called <code>GetAllCustomers()</code> that retrieves the customers from the database and returns them to the client. The client app calls the function and writes the customer names to the console.</p> <p>When I call <code>GetAllCustomers()</code> from the client via proxy, I get a <code>CommunicationException</code> with the message, </p> <blockquote> <p><em>An error occurred while receiving the HTTP response to <code>http://localhost:8000/Service1</code>. 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.</em></p> </blockquote> <p>The inner exception is <code>System.Net.WebException</code>: </p> <blockquote> <p><em>The underlying connection was closed: An unexpected error occurred on a receive.</em></p> </blockquote> <p>Next level of inner exception is <code>System.IO.IOException</code>: </p> <blockquote> <p><em>Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.</em></p> </blockquote> <p>And the final inner exception is <code>System.Net.Sockets.SocketException</code>: </p> <blockquote> <p><em>An existing connection was forcibly closed by the remote host</em></p> </blockquote> <p>Here is the client code:</p> <pre><code>static void Main(string[] args) { Console.WriteLine("Press Enter to begin."); Console.ReadLine(); ServiceReference1.Service1Client MyService = new ServiceReference1.Service1Client(); CUSTOMER[] cl = MyService.GetAllCustomers(); foreach (CUSTOMER c in cl) { Console.WriteLine(c.CUSTFNAME + " " + c.CUSTLNAME); } Console.WriteLine("Press Enter to exit."); Console.ReadLine(); } </code></pre> <p>Here is the host application code:</p> <pre><code>static void Main(string[] args) { ServiceHost hostA = null; try { hostA = new ServiceHost(typeof(Service1), new Uri("http://localhost:8000") ); hostA.AddServiceEndpoint(typeof(IService1), new BasicHttpBinding(), "Service1"); hostA.Open(); Console.WriteLine(); Console.WriteLine("Host started. Press Enter to terminate host."); Console.ReadLine(); } finally { if (hostA.State == CommunicationState.Faulted) hostA.Abort(); else hostA.Close(); } } </code></pre> <p>Here is the service library code for the function:</p> <pre><code>public HashSet&lt;CUSTOMER&gt; GetAllCustomers() { var db = new TRS11Entities(); HashSet&lt;CUSTOMER&gt; TheCusts = new HashSet&lt;CUSTOMER&gt;(); foreach (CUSTOMER c in db.CUSTOMERs) { TheCusts.Add(c); } //CUSTOMER TestCust1 = new CUSTOMER(); //TestCust1.CUSTFNAME = "Joe"; //TestCust1.CUSTLNAME = "Schmoe"; //CUSTOMER TestCust2 = new CUSTOMER(); //TestCust2.CUSTFNAME = "Peter"; //TestCust2.CUSTLNAME = "Pumpkineater"; //TheCusts.Add(TestCust1); //System.Threading.Thread.Sleep(45000); //TheCusts.Add(TestCust2); return TheCusts; } </code></pre> <p>Strangely enough, if I bypass the database by replacing the foreach block with the commented out code below it, it works great! </p> <p>I first thought it might be a timeout issue with the database query taking too long. However, my test code has a 45-second sleep in there, and it still returns the data to the client fine. The original code gives the exception after only about 3 seconds.</p> <p>Also, if I call the original function (with the foreach block) by instantiating the WCF service directly, rather than via an endpoint/proxy, it also runs fine and returns all the customers in the database. </p> <p>Lastly, I thought it might be an issue with the returned data set being too large, so I modified the foreach block and inserted a break statement after adding the first 5 customers to the results, and I still got the exception.</p> <p>So, what else could be causing this? </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload