jQuery success callback called with empty response when WCF method throws an Exception

前端 未结 5 1845
既然无缘
既然无缘 2021-02-05 11:55

I\'m tearing my hair out over this one, so bear with me (it\'s a long post).

Basic Info

  • ASP.NET 3.5 with WCF service in ASP.NET compatibility mode
5条回答
  •  心在旅途
    2021-02-05 12:01

    Here is another shot. I'll leave my original attempt incase that solution helps someone else.

    To fire the error condidition for the $.ajax call you will need an error code in your response

       protected virtual void ApplyHttpResponseSettings(ref Message fault, System.Net.HttpStatusCode statusCode, string statusDescription) 
        { 
            var httpResponse = new HttpResponseMessageProperty() 
            { 
                //I Think this could be your problem, if this is not an error code
                //The error condition will not fire
                //StatusCode = statusCode, 
                //StatusDescription = statusDescription 
    
                //Try forcing an error code
                StatusCode = System.Net.HttpStatusCode.InternalServerError;
            }; 
    
            httpResponse.Headers[HttpResponseHeader.ContentType] = "application/json"; 
            httpResponse.Headers["jsonerror"] = "true"; 
    
            fault.Properties.Add(HttpResponseMessageProperty.Name, httpResponse); 
        } 
    

    Heres hoping my second attmpt is more useful to you!

提交回复
热议问题