locked
The server was unable to process the request due to an internal error. RRS feed

  • Question

  •          

    Properties set in my project are below

    namespace EmployeeService
    {

            public class Employee
            {
                private int _Id;
                private string _Name;
                private string _Gender;
                private DateTime _DateofBirth;
                public int Id
                {
                    get { return _Id; }
                    set { _Id = value; }
                }
                public string Name
                {
                    set { _Name = value; }
                    get { return _Name; }
                }
                public string Gender
                {
                    set { _Gender = value; }
                    get { return _Gender; }
                }
                public DateTime DateofBirth
                {
                    set { _DateofBirth = value; }
                    get { return _DateofBirth; }
                }

            }

    This is the service i have developed in my project 

    namespace EmployeeService
    {
        // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in both code and config file together.
        public class EmployeeService : IEmployeeService
        {

            public Employee GetEmployee(int Id)
            {
                Employee objemp = new Employee();
                string cs = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;
                using (SqlConnection con = new SqlConnection(cs))
                {
                    SqlCommand cmd = new SqlCommand("spGettblEmployeewcf", con);
                    cmd.CommandType = CommandType.StoredProcedure;
                    SqlParameter Idparameter = new SqlParameter();

                    Idparameter.ParameterName = "@Id";
                    Idparameter.Value = Id;
                    cmd.Parameters.Add(Idparameter);
                    con.Open();
                    SqlDataReader dr = cmd.ExecuteReader();
                    while (dr.Read())
                    {
                        objemp.Id = Convert.ToInt32(dr["Id"]);
                        objemp.Name = dr["Name"].ToString();
                        objemp.Gender = dr["Gender"].ToString();
                        objemp.DateofBirth = Convert.ToDateTime(dr["DateofBirth"]);
                    }

                }
                return objemp;
            }

            public void SaveEmployee(Employee objemp)
            {

                string cs = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;
                using (SqlConnection con = new SqlConnection(cs))
                {
                    SqlCommand cmd = new SqlCommand("spInsertEmployeewcf", con);
                    cmd.CommandType = CommandType.StoredProcedure;

                    SqlParameter ParameterId = new SqlParameter()
                    {
                        Value = objemp.Id,
                        ParameterName = "@Id"

                    };
                    cmd.Parameters.Add(ParameterId);

                    SqlParameter ParameterName = new SqlParameter()
                    {
                        Value = objemp.Name,
                        ParameterName = "@Name"

                    };
                    cmd.Parameters.Add(ParameterName);

                    SqlParameter ParameterGender = new SqlParameter()
                    {
                        Value = objemp.Gender,
                        ParameterName = "@Gender"

                    };
                    cmd.Parameters.Add(ParameterGender);

                    SqlParameter ParameterDateofBirth = new SqlParameter()
                    {
                        Value = objemp.DateofBirth,
                        ParameterName = "@DateofBirth"

                    };
                    cmd.Parameters.Add(ParameterDateofBirth);
                    con.Open();
                    cmd.ExecuteNonQuery();
                }

            }
        }
    }

    The Service Contract  code is

           

    namespace EmployeeService
    {
        // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together.
        [ServiceContract]
        public interface IEmployeeService
        {
            [OperationContract]
            Employee GetEmployee(int Id);

            [OperationContract]
            void SaveEmployee(Employee objemp); 

            // TODO: Add your service operations here
        }

        // Use a data contract as illustrated in the sample below to add composite types to service operations


    }

    and i deployed the EmployeeService in iis and consuming the service in my web application the code is below

                

     protected void btnsave_Click(object sender, EventArgs e)
            {
                EmployeeService.EmployeeServiceClient client = new EmployeeService.EmployeeServiceClient("basicHttpBinding");
                EmployeeService.Employee employee = new EmployeeService.Employee();
                employee.Id = Convert.ToInt32(txtid.Text);
                employee.Name = txtname.Text;
                employee.Gender = txtgender.Text;
                employee.DateofBirth = Convert.ToDateTime(txtdob.Text);
                client.SaveEmployee(employee);
            }

            protected void btnget_Click(object sender, EventArgs e)
            {
                EmployeeService.EmployeeServiceClient client = new EmployeeService.EmployeeServiceClient("basicHttpBinding");
                EmployeeService.Employee employee = client.GetEmployee(Convert.ToInt32(txtid.Text));
                txtname.Text = employee.Name;
                txtgender.Text = employee.Gender;
                txtdob.Text = employee.DateofBirth.ToShortDateString();

            }

    and  when i am entering the details of employee Id,Name,Gender,DateofBirth and clicking save button iam getting the following error 

    The server was unable to process the request due to an internal error.  For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the <serviceDebug> configuration behavior) on the server in order to send the exception information back to the client, or turn on tracing as per the Microsoft .NET Framework SDK documentation and inspect the server trace logs.


    Code in web.config file in Webapplication(Client) is the following

    <?xml version="1.0"?>

    <!--
      For more information on how to configure your ASP.NET application, please visit
      http://go.microsoft.com/fwlink/?LinkId=169433
      -->

    <configuration>
        <system.diagnostics>
            <sources>
                <source name="System.ServiceModel.MessageLogging" switchValue="Warning, ActivityTracing">
                    <listeners>
                        <add type="System.Diagnostics.DefaultTraceListener" name="Default">
                            <filter type="" />
                        </add>
                        <add name="ServiceModelMessageLoggingListener">
                            <filter type="" />
                        </add>
                    </listeners>
                </source>
                <source name="System.ServiceModel" switchValue="Warning, ActivityTracing"
                    propagateActivity="true">
                    <listeners>
                        <add type="System.Diagnostics.DefaultTraceListener" name="Default">
                            <filter type="" />
                        </add>
                        <add name="ServiceModelTraceListener">
                            <filter type="" />
                        </add>
                    </listeners>
                </source>
            </sources>
            <sharedListeners>
                <add initializeData="C:\Users\HEMANTH\Desktop\Client\Client\Web_messages.svclog"
                    type="System.Diagnostics.XmlWriterTraceListener, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
                    name="ServiceModelMessageLoggingListener" traceOutputOptions="Timestamp">
                    <filter type="" />
                </add>
                <add initializeData="C:\Users\HEMANTH\Desktop\Client\Client\Web_tracelog.svclog"
                    type="System.Diagnostics.XmlWriterTraceListener, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
                    name="ServiceModelTraceListener" traceOutputOptions="Timestamp">
                    <filter type="" />
                </add>
            </sharedListeners>
            <trace autoflush="true" />
        </system.diagnostics>
        <system.web>
            <compilation debug="true" targetFramework="4.0" />
        </system.web>

        <system.serviceModel>
            <diagnostics>
                <messageLogging logEntireMessage="true" logMalformedMessages="true"
                    logMessagesAtTransportLevel="true" />
            </diagnostics>
            <bindings>
                <basicHttpBinding>
                    <binding name="basicHttpBinding" />
                </basicHttpBinding>
                <wsHttpBinding>
                    <binding name="mexHttpBinding">
                        <security mode="None" />
                    </binding>
                </wsHttpBinding>
            </bindings>
            <client>
                <endpoint address="http://localhost/EmployeeWebServices/EmployeeService.svc/basic"
                    binding="basicHttpBinding" bindingConfiguration="basicHttpBinding"
                    contract="EmployeeService.IEmployeeService" name="basicHttpBinding" />
                <endpoint address="http://localhost/EmployeeWebServices/EmployeeService.svc/mex"
                    binding="wsHttpBinding" bindingConfiguration="mexHttpBinding"
                    contract="EmployeeService.IEmployeeService" name="mexHttpBinding" />
            </client>
        </system.serviceModel>
    </configuration>

    Things i have tried till now are 

    1)changed the name of the name of the endpoint address basicHttpBinding to  basicHttpBinding_IEmployeeService but still get the save error.

    2)Opened the Message Log Trace. Got the error as follows

    <MessageLogTraceRecord>
    <HttpResponse xmlns="http://schemas.microsoft.com/2004/06/ServiceModel/Management/MessageTrace">
    <StatusCode>InternalServerError</StatusCode>
    <StatusDescription>Internal Server Error</StatusDescription>
    <WebHeaders>
    <Content-Length>730</Content-Length>
    <Cache-Control>private</Cache-Control>
    <Content-Type>text/xml; charset=utf-8</Content-Type>
    <Date>Sat, 03 Jan 2015 12:12:24 GMT</Date>
    <Server>Microsoft-IIS/7.5</Server>
    <X-AspNet-Version>4.0.30319</X-AspNet-Version>
    <X-Powered-By>ASP.NET</X-Powered-By>
    </WebHeaders>
    </HttpResponse>
    <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
    <s:Header></s:Header>
    <s:Body>
    <s:Fault>
    <faultcode xmlns:a="http://schemas.microsoft.com/net/2005/12/windowscommunicationfoundation/dispatcher" xmlns="">a:InternalServiceFault</faultcode>
    <faultstring xml:lang="en-US" xmlns="">The server was unable to process the request due to an internal error.  For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the <serviceDebug> configuration behavior) on the server in order to send the exception information back to the client, or turn on tracing as per the Microsoft .NET Framework SDK documentation and inspect the server trace logs.</faultstring>
    </s:Fault>
    </s:Body>
    </s:Envelope>
    </MessageLogTraceRecord>

    Try to understand but could not understand because i'am new to wcf services. Please help me to find the error details.

    Thanks in advance

    Regards

    rax227 

                           
    Saturday, January 3, 2015 12:39 PM