我在IIS中使用以下方法运行WCF服务:
public void Test()
{
HttpContext.Current.Response.StatusCode = 500;
HttpContext.Current.Response.Write("You cannot do this.");
}
在我的客户端HTML页面上,我有以下内容:
$(document).ready(function () {
$.ajax({
type: "POST",
url: 'MyService.svc/Test',
data: '',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
alert('success');
},
error: function (result) {
alert(result.responseText);
}
});
});
调用错误回调,但responseText始终只有两个字符:“Yo”。我检查了响应,似乎只返回了内容长度为2.这里发生了什么?为什么我没有收到回复的全部内容?
答案 0 :(得分:0)
引发异常时,您的消息会截断吗?
public void Test()
{
HttpContext.Current.Response.StatusCode = 500;
throw new Exception("This is a test");
}