由于内部错误,服务器无法处理请求。怎么解决? [英] The server was unable to process the request due to an internal error. How to solve it?

查看:281
本文介绍了由于内部错误,服务器无法处理请求。怎么解决?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到的完整错误是



由于内部错误,服务器无法处理请求。有关错误的更多信息,请在服务器上启用IncludeExceptionDetailInFaults(来自ServiceBehaviorAttribute或来自< servicedebug>配置行为),以便将异常信息发送回客户端,或者根据Microsoft .NET打开跟踪Framework SDK文档并检查服务器跟踪日志。由于内部错误,服务器无法处理请求。有关错误的更多信息,请在服务器上启用IncludeExceptionDetailInFaults(来自ServiceBehaviorAttribute或来自< servicedebug>配置行为),以便将异常信息发送回客户端,或者根据Microsoft .NET打开跟踪Framework SDK文档并检查服务器跟踪日志。



为什么iam gettig这个错误?



我的属性在这个项目中使用



项目中设置的属性在下面



命名空间EmployeeService

{



公共班级员工

{

private int _Id;

private string _Name;

private string _Gender;

private DateTime _DateofBirth;

public int Id

{

得到{return _Id; }

set {_Id = value; }

}

公共字符串名称

{

set {_Name = value; }

get {return _Name; }

}

公共字符串性别

{

set {_Gender = value; }

得到{return _Gender; }

}

公共日期时间DateofBirth

{

set {_DateofBirth = value; }

得到{return _DateofBirth; }

}



}



这是我开发的服务在我的项目中



命名空间EmployeeService

{

//注意:您可以使用重命名命令在重构菜单上,将代码和配置文件中的类名Service1一起更改。

公共类EmployeeService:IEmployeeService

{



公共员工GetEmployee(int Id)

{

员工对象=新员工();

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 SqlPa rameter();



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(博士[DateofBirth]);

}



}

返回objemp;

}



public void SaveEmployee(Employee objemp)

{



string cs = ConfigurationManager.ConnectionStrings [DBCS]。连接字符串;

使用(SqlConnection con = new SqlConnection(cs))

{

SqlCommand cmd = new SqlCommand(spInsertEmployeewcf,con) ;

cmd.CommandType = CommandType.StoredProcedure;



SqlParameter ParameterId = new SqlParameter()

{< br $>
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();

}



}

}

}



服务合同代码是





命名空间EmployeeService

{

//注意:您可以使用重构菜单上的重命名命令来ch将代码和配置文件中的接口名称IService1一起ange。

[ServiceContract]

公共接口IEmployeeService

{

[OperationContract]

员工GetEmployee(int Id);



[OperationContract]

无效SaveEmployee(Employee objemp);



// TODO:在这里添加您的服务操作

}



//使用下面示例中所示的数据合同将复合类型添加到服务操作中





}

和我在iis中部署了EmployeeService并在我的web应用程序中使用了服务,代码在下面





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(员工);

}



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 ();



}



当我输入员工ID,姓名,性别的详细信息时,DateofBirth并单击保存按钮我收到以下错误



由于内部错误,服务器无法处理请求。有关错误的更多信息,请在服务器上启用IncludeExceptionDetailInFaults(来自ServiceBehaviorAttribute或来自< servicedebug>配置行为),以便将异常信息发送回客户端,或者根据Microsoft .NET打开跟踪Framework SDK文档并检查服务器跟踪日志。





Webapplication(Client)中web.config文件中的代码如下所示/>






<! -

有关如何配置的更多信息您的ASP.NET应用程序,请访问

http://go.microsoft.com/fwlink/?LinkId=169433

- >



< configuration>

< system.diagnostics>

< sources>

< source name =System.ServiceModel.MessageLoggingswitchvalue =Warning,ActivityTracing/>

< listeners> < add type =System.Diagnostics.DefaultTraceListenername =Default>

< filter type =>



< add name =ServiceModelMessageLoggingListener>

< filter type =>





< source name =System.ServiceModelswitchvalue =Warning,ActivityTracing/>

propagateActivity =true>

< listeners> < add type =System.Diagnostics.DefaultTraceListenername =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\Clien t \Client\Web_tracelog.svclog>

type =System.Diagnostics.XmlWriterTraceListener,System,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089

name =ServiceModelTraceListenertraceOutputOptions =Timestamp>

< filter type =>





< trace autoflush =true>

< system.web>

< compilation debug =truetargetframework =4.0>





< system.servicemodel>

< diagnostics>

< messagelogging logentiremessage =truelogmalformedmessages =true >

logMessagesAtTransportLevel =true/>



< bindings>

< basichttpbinding>

< binding name =basicHttpBinding>



< wshttpbinding>

<绑定名称=mexHttpBinding>

< security mode =None>







< client>

< endpoint address =http://localhost/EmployeeWebServices/EmployeeService.svc/basic>

bind ing =basicHttpBindingbindingConfiguration =basicHttpBinding

contract =EmployeeService.IEmployeeServicename =basicHttpBinding/>

< endpoint address =http:/ /lhosthost/EmployeeWebServices/EmployeeService.svc/mex\">

binding =wsHttpBindingbindingConfiguration =mexHttpBinding

contract =EmployeeService.IEmployeeServicename =mexHttpBinding />









我到现在为止所尝试过的事情是


1)将端点地址basicHttpBinding的名称更改为basicHttpBinding_IEmployeeService,但仍然收到保存错误。



2)打开消息日志跟踪。得到如下错误



< messagelogtracerecord>

< httpresponse xmlns =http://schemas.microsoft.com/2004 / 06 / ServiceModel / Management / MessageTrace>

< statuscode> InternalServerError

< statusdescription>内部服务器错误

< webheaders> ;

< content-length> 730

< cache-control> private

< content-type> text / xml; charset = utf-8

< date>星期六,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 / dispatcherxmlns => a:InternalServiceFault

< faultstring xml:lang =en-USxmlns =>服务器是由于内部错误,无法处理请求。有关错误的更多信息,请在服务器上启用IncludeExceptionDetailInFaults(来自ServiceBehaviorAttribute或来自< servicedebug>配置行为),以便将异常信息发送回客户端,或者根据Microsoft .NET打开跟踪Framework SDK文档并检查服务器跟踪日志。











尝试理解,但无法理解,因为我是wcf服务的新手。请帮我查一下错误信息。



提前致谢



问候



rax227

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>
<source name="System.ServiceModel.MessageLogging" switchvalue="Warning, ActivityTracing" />
<listeners> <add type="System.Diagnostics.DefaultTraceListener" name="Default">
<filter type="">

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


<source name="System.ServiceModel" switchvalue="Warning, ActivityTracing" />
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

推荐答案

快速反复一些建议。内部错误是指未捕获错误并通过应用程序堆栈跟踪到应用程序级别的错误。应用程序不再具有如何发生的具体信息,因此异常标记为一般,并记录在IIS和事件查看器中或您编写日志的任何位置。



我的猜测是你在配置文件中的绑定有问题。一般错误通常是因为配置文件解释器不那么聪明,因此当xml不能正确解析时,它只会爆炸并迅速冒泡到应用程序级别,因为配置文件的xml解释器已经处于应用程序级别。您的错误提示中的强提示是xml。 WCF默认不使用XML,它使用SOAP。因此,XML问题通常是配置文件的标志,因为配置文件没有正确设置并且因此而爆炸。



我相信您没有正确链接绑定和配置。我知道您不必在客户端代码中命名绑定。当您选择客户端对象时,它会告诉您将使用哪个服务合同(例如,客户端告诉您使用哪个接口类)。界面是绑定中的一个设置。



执行Web服务时最重要的是连续性。换句话说,最佳实践是直接从向导生成Web服务的所有部分。我说向导是因为我们正在讨论服务的项目向导,以及在客户端中生成设置文件(例如disco等)的服务引用向导。你不能做的只是开始键入你的数据和功能,直到你完全确定客户端和服务正在成功说话。您的操作系统,IIS等可能存在一些安装问题。我大多数时候使用命令行客户端,并确保我的环境设置正确,我的客户端和服务正在成功通话。一旦你有了这个,你可以开始以婴儿步骤增强你的服务,然后刷新你的客户参考,向你的客户揭示网络服务的新方法。



我也会最初不担心安全问题。处理安全性需要花费一些时间来构建并带来一系列新问题。显示您在新数据方法中的进度,然后说服您的经理必须处理安全性。安全方法需要大约一周时间来研究和阅读,并构建一个单独的原型来练习和学习大量信息。单独解决它,然后为您的测试过程和测试环境合并代码,因为它可能需要一些IIS更新和搞乱,至少会暂时停止您的常规WCF开发一段时间。



在codeproject和youtube中有大量的分步教程。



另一条建议,使用tryparse而不是强制转换时转换从您的文本字段到键入的数据,如日期,时间,整数等。这样您就可以响应您的用户输入错误数据而不会爆炸。您可能在页面上有验证器,但保护您的服务仍然是一个好主意。



您还必须拥有大量的验证码。 if语句,以帮助警告您的自动化用户的问题。 Web服务旨在用于站点之间以及页面支持,因此可以代码或者稍后付费。



Happy Coding!
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!


这篇关于由于内部错误,服务器无法处理请求。怎么解决?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆