locked
WCF forcibly closed by remote host RRS feed

  • Question

  • User-2144571781 posted

    Hi everyone I hope someone finds the time to shed some light on this problem. I am new to WCF and so I am working with a simple database that adds diseases to a database through a WCF service. I am using LINQ to SQL to map my database entities (Diseases and Severities).

    My problem is when I go through the business layer which is my WCF service, upon retrieving my Severity levels (low, medium, high) my WCF host is not succesfully packaging the severity levels message and the host forcibly closes. I am populating a drop down list with the severity levels so that when a user would add a disease it would insert that disease record with that severity level.

    The interesting thing about this problem is that it works the first time through the service. Meaning before I've added any records to the database, my drop down list gets populated just fine with the severity levels returned by the service. Once I have added a disease record or multiple disease, if I try to reload the same page, it will say "An error occurred while receiving the HTTP response to http://localhost:1234/Mindtree/MedBAL/MedService/MedService. 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." It actually crashes on:
    Line 73: public MedDAL.SEVERITY[] GetSeverityLevels() { Line 74:  return base.Channel.GetSeverityLevels(); 

    When I debug this I can see that it successfully pulls the records and stores them in the Severities[] array, something just goes wrong when it packages the message to send it back. I just don't understand why it works when my Disease table is empty. As soon as I add diseases to my DB and reload the page to add more diseases, it then has a problem getting the severity levels which don't change ever.

     

    app.config

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <system.web>
        <compilation debug="true"></compilation>
      </system.web>
      <system.serviceModel>
        <behaviors>
          <serviceBehaviors>
            <behavior name="SvcBehavConfig">
              <serviceMetadata/>
              <serviceDebug includeExceptionDetailInFaults="true" />
            </behavior>
          </serviceBehaviors>
        </behaviors>
        <services>
          <service behaviorConfiguration="SvcBehavConfig" name="MedBAL.MedService" >
            <endpoint address="MedService"
                      binding="wsHttpBinding"
                      contract="MedBAL.IMedService"
                      name="mainHttpEp"></endpoint>
            <endpoint address="mex"
                      binding ="mexHttpBinding"
                      contract="IMetadataExchange"
                      name="mexHttpEp"></endpoint>
            <host>
              <baseAddresses>
                <add baseAddress="http://localhost:1234/Mindtree/MedBAL/MedService"/>
              </baseAddresses>
            </host>
          </service>
        </services>
      </system.serviceModel>
    </configuration>
    

    methods used in Data Access Layer

    public SEVERITY[] GetSeverityLevels()
            {
    
                SEVERITY[] severityLevels = null;
                MedDALDataContext db = null;
                try
                {
                    db = new MedDALDataContext();
                    db.Connection.Open();
                    severityLevels = db.SEVERITies.ToArray();
    
                }
                catch (Exception ex)
                {
                    CustomErrorWrapper wrapper = new CustomErrorWrapper();
                    wrapper.ErrorText = ex.ToString();
                    FaultReason fR = new FaultReason("Error in Service Class");
                    FaultException<CustomErrorWrapper> fEx = new FaultException<CustomErrorWrapper>(wrapper, fR);
                    throw fEx;
    
                    throw ex;
    
                }
                finally
                {
                  
                    db.Connection.Close();
                }
                return severityLevels;
    
            }
    public void InsertNewDisease(int severityid, string name, string cause, string description)
            {
                //int rowsAdded = 0;
    
                MedDALDataContext database = null;
                try
                {
                    database = new MedDALDataContext();
                    DISEASE disObj = new DISEASE();
                    database.Connection.Open();
                    disObj.Name = name;
                    disObj.Severity_ID = severityid;
                    disObj.Cause = cause;
                    disObj.Description = description;
                    database.DISEASEs.InsertOnSubmit(disObj);
                    database.SubmitChanges();
                                    
    
                }
                catch (SqlException ex)
                {
                    throw ex;
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    database.Connection.Close();
                }
            }


    Hope someone understands what i'm facing here. I would just like to better understand what the problem could be. I just think that it's so unusual that it would work fine the first time when the Disease table is empty but if I reload it after records have been added to the database Disease table, then the service has problems.. hmmm

     

    Tuesday, March 19, 2013 10:39 AM

Answers

  • User-2144571781 posted

    I had to set DeferredLoadingEnable to false on my LinqToSQL DataContext file in the Data Access Layer. Since the Severity mapping had a Entity Set of Diseases, it was trying to send all the diseases for each severity level back over the wire and must have had a problem serializing all that data. Thankfully setting the DefferedLoadingEnabled property to false didn't pass all the Diseases along with it allowing it to go back over the wire successfully. Hope this might help someone else.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, March 19, 2013 12:08 PM

All replies

  • User-2144571781 posted

    The reason I'm using linq to sql is to learn for work. I changed my Data acess layer to use ADO.NET instead of linq directly. So now my Data access layer returns a DataTable first and in the BAL I convert it into a Severities array. Doing this, my service has no problem returning the message and allowing me to reload the page and continue to add diseases normally. All that has changed is the way I get the data in the Data Access Layer. There must be something I have overlooked when using Linq to SQL. But in either case  I'm returning a Severities array..

    my db structure is Disease(id, severity_id, name, cause, description) references Severity(id, severity)

     

    Tuesday, March 19, 2013 11:06 AM
  • User-2144571781 posted

    I had to set DeferredLoadingEnable to false on my LinqToSQL DataContext file in the Data Access Layer. Since the Severity mapping had a Entity Set of Diseases, it was trying to send all the diseases for each severity level back over the wire and must have had a problem serializing all that data. Thankfully setting the DefferedLoadingEnabled property to false didn't pass all the Diseases along with it allowing it to go back over the wire successfully. Hope this might help someone else.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, March 19, 2013 12:08 PM
  • User-1000095884 posted

    Hi,

    Thanks for your userful feedback.

    Best Regards.

    Wednesday, March 20, 2013 6:16 AM