Click here to Skip to main content
15,907,905 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
The complete error iam getting is

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.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.

Why iam gettig this error?

my Properties in this Project Used are

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



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

<configuration>
<system.diagnostics>
<sources>

<listeners> <add type="System.Diagnostics.DefaultTraceListener" name="Default">
<filter type="">

<add name="ServiceModelMessageLoggingListener">
<filter type="">



propagateActivity="true">
<listeners> <add type="System.Diagnostics.DefaultTraceListener" name="Default">
<filter type="">

<add name="ServiceModelTraceListener">
<filter type="">



<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 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="">


<trace autoflush="true">
<system.web>
<compilation debug="true" targetframework="4.0">


<system.servicemodel>
<diagnostics>
<messagelogging logentiremessage="true" logmalformedmessages="true">
logMessagesAtTransportLevel="true" />

<bindings>
<basichttpbinding>
<binding name="basicHttpBinding">

<wshttpbinding>
<binding name="mexHttpBinding">
<security mode="None">



<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" />




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
<statusdescription>Internal Server Error
<webheaders>
<content-length>730
<cache-control>private
<content-type>text/xml; charset=utf-8
<date>Sat, 03 Jan 2015 12:12:24 GMT
<server>Microsoft-IIS/7.5
<x-aspnet-version>4.0.30319
<x-powered-by>ASP.NET


<s:envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:header>
<s:body>
<s:fault>
<faultcode xmlns:a="http://schemas.microsoft.com/net/2005/12/windowscommunicationfoundation/dispatcher" xmlns="">a:InternalServiceFault
<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.





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
Posted
Updated 3-Jan-15 2:36am
Comments
ZurdoDev 3-Jan-15 11:27am    
You need to get the full error.

1 solution

Just a quick bounce back on some advice for this. An Internal Error is where an error has not been caught and has made it up through the levels of the application stack trace to the application level. The application no longer has specifics on how it occurred, so the exception is marked general and logged in IIS and Event Viewer or wherever you are writing your logs.

My guess is that you are having some trouble in your bindings in your config file. The general errors are often because the config file interpreter is not that smart and so when xml does not parse right, it just blows up and bubbles up to the application level quickly as the xml interpreter for the config files is at application level already. Your strong hint is xml in your error logs. WCF does not use XML by default, it uses SOAP. Therefore XML issues are usually a flag to the config file not being setup right and blowing up as a result.

I believe you are not linking your binding and configuration right. I know that you don't have to name your binding in your client code. When you choose a client object, it tells which service contract you will be using (e.g. the client tells which interface class to use). The interface is a setting in the binding.

Most important thing when doing web services is continuity. In other words, best practice is to generate all parts of the web service directly out of the wizards. I say wizards because we are talking about a project wizard for your service, and a service reference wizard that generates your settings file (e.g. disco, and so on) in your client. What you can't do is just start typing away at your data and features until you are absolutely sure that the client and service are talking successfully. You may have some setup issues in your operating system, IIS, and so on. I use a command line client most times, and make absolutely sure that my environment is setup correctly and that my client and service are talking successfully. Once you have this, you can start to enhance your service in baby steps, then refresh your client reference to reveal web service new methods to your client.

I would also not worry about security initially. Working on security will take time away from your build and bring a whole new set of problems. Show your progress in new data methods, then convince your managers that security must be handled. Security methods out there require about a week or so to research and read, and build a separate prototype to practice and learn on a whole lot of info. Tackle it separately, then merge code for your testing process and testing environment as it may require some IIS updating and messing around that will at least temporarily stop your regular WCF development for a while.

There are tons of step by step tutorials in codeproject and in youtube.

One other piece of advice, use tryparse rather than force a cast when you convert from your textfields to typed data such as dates, times, integers, etc. That way you can respond to your user inputting bad data without blowing up. Granted you likely have validators on your page, but it is still a good idea to protect your service.

You will also have to have heavy validation code with a lot of if statements to help warn your automated users of issues. Web Services are meant to be used between sites as well as page support, so code for that or pay the price later.

Happy Coding!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900