不能得到FaultExceptions信息(JavaScript的) [英] Cant get info from FaultExceptions (javascript)
问题描述
到现在为止我已经使用的web服务ASMX这是我从JavaScript调用。据工作正常,但因为我需要在系列化一些控制,我想切换到DataContracts和WCF。 但是,我相信,有件事我有误解,因为我试着去追赶从客户端code(JavaScript)的faultexceptions,但Ç林接受的唯一错误$ C $是: (翻译,所以可能不准确)
Until now I have used an webservice ASMX which I call from javascript. It has been working fine, but because I needed some control over the serialization, I am trying to switch to DataContracts and WCF. However, I do believe that there is something I have misunderstood, because Im trying to catch faultexceptions from the client code (javascript), but the only errorcode Im receiving is: (translated, so might not be accurate)
由于实习错误服务器无法处理请求。你可以得到有关被激活IncludeExceptionDetailInFaults错误的详细信息...
"The server could not handle the request because of an intern error. You can get more info about the error by activate IncludeExceptionDetailInFaults..."
我试图设置IncludeExceptionDetailInFauls为true这就给一些信息,但据我了解,整点投掷FaultExceptions是对用户隐藏例外,只丢一点点的信息?我试着用IErrorHandler,但我有 创建一个简单的例子:
I have tried to set IncludeExceptionDetailInFauls to true which gives some info, but as far as I understood, the whole point by throwing FaultExceptions is to hide exceptions from the user, and only throw a little info? Im trying with a IErrorHandler, but I have created a simpler example:
[ServiceContract(Namespace = "")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class WcfTest
{
// To use HTTP GET, add [WebGet] attribute. (Default ResponseFormat is WebMessageFormat.Json)
// To create an operation that returns XML,
// add [WebGet(ResponseFormat=WebMessageFormat.Xml)],
// and include the following line in the operation body:
// WebOperationContext.Current.OutgoingResponse.ContentType = "text/xml";
[OperationContract]
public string DoOk()
{
// Add your operation implementation here
return "Success";
}
[OperationContract]
public string DoFail()
{
FaultReason reason = new FaultReason("Fail <- This is good :)");
throw new FaultException(reason);
return "Success";
}
}
这是包含在一个ScriptManager,并呼吁通过以下的javascript:
<a href="java script:void(0);" onclick="DoOk()">OK</a><br />
<a href="java script:void(0);" onclick="DoFail()">Fail</a>
<script>
function DoOk() {
WcfTest.DoOk(
function (result) {
alert("DoOk Success: "+result);
},
function (result) {
alert("DoOk Failed: " + result);
})
}
function DoFail() {
WcfTest.DoFail(
function (result) {
alert("DoFail Success: " + result);
},
function (result) {
alert("DoFail Failed: " + result);
})
}
</script>
和服务模式:
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="WcfTestAspNetAjaxBehavior">
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="WcfTestAspNetAjaxBehavior">
<enableWebScript />
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"
multipleSiteBindingsEnabled="true" />
<services>
<service name="WcfTest">
<endpoint address="" behaviorConfiguration="WcfTestAspNetAjaxBehavior"
binding="webHttpBinding" contract="WcfTest" />
</service>
</services>
</system.serviceModel>
香港专业教育学院还试图以纪念DoFail方法的组合:
Ive also tried to mark the DoFail method with combinations of:
[FaultContract(typeof(FaultException))]
[FaultContract(typeof(FaultReason))]
我有没有误解的东西吗?不应该你能得到的异常信息回抛出一个的FaultException
,而无需设置 IncludeExceptionDetailInFaults
来真的吗?
Have I misunderstood something? Shouldnt you be able to get exception info back by throwing an FaultException
without having to set IncludeExceptionDetailInFaults
to true?
推荐答案
Useful resources:
- Getting jQuery and WCF to talk
- Error handling with WebHttpBinding for Ajax/JSON
- 将impelemting IErrorHandler接口创建自己的错误处理程序
- 创建WebHttpBehavior的子类,替换默认的错误处理,你自己的错误处理程序
- 插件自定义/延长使用自定义ServiceHostFactory或定义为behaviorExtension在web.config中的行为
这篇关于不能得到FaultExceptions信息(JavaScript的)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!