2012-08-25 138 views
3

我在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总是只有两个字符:“哟”。我检查了答复,它似乎只是返回一个内容长度为2.这里发生了什么?为什么我没有收到我回复的全部内容?

回答

0

当您引发异常时,您的消息是否会截断?

public void Test() 
{ 
    HttpContext.Current.Response.StatusCode = 500; 
    throw new Exception("This is a test"); 
}