2013-02-05 3 views
2

내 코드에서 예외가 발생하면 REST 또는 SOAP인지 여부에 따라 FaultException/WebFaultException으로 반환하려고합니다. 다음 문제는 내 프로젝트의 REST 구성 요소에 있습니다. 예외가 트리거되고 디버그 창 (그림 참조)에 나타납니다.WCF Rest 나머지 WebFaultException 항상 202

enter image description here

우리는 명확하게 WebFaultException가 트리거되고 있지만, JSON 내 응답이 아님을 참조하십시오 HTTP badrequest도 내 예외 메시지가있다, 그러나 항상 다음 : 다음은

{"readyState":4,"responseText":"","status":202,"statusText":"Accepted"} 

내 인터페이스 :

: 여기

[WebInvoke(Method = "POST", UriTemplate = "/Package/", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)] 
[FaultContract(typeof(FaultException))] 
[OperationContract] 
string CopyZip(Stream zippedPackage); 

는 구현

public string CopyZip(Stream zippedPackage) 
{ 
    try 
    { 
     ZipCreator pck = new ZipCreator(); 
     pck.CopyUploadedZip(zippedPackage); 
     return "Zipped"; 
    } 
    catch (Exception ex) 
    { 
    //throw new FaultException(ex.Message); 
     throw new WebFaultException<string>(ex.Message,    HttpStatusCode.BadRequest); 
    } 

}

+0

이 문제를 해결할 수 있었습니까? 나는 (있는 그대로) 붙어있다. –

답변

0

나는 문제가 WcfRestContrib 사용자 지정 오류 처리에 있던 일부 게시물을 본 적이있다. 이러한 경우 Service 클래스 속성을 [ServiceConfiguration ("Rest", true)]에서 [ServiceConfiguration ("Rest", false)]로 변경하면 문제가 해결됩니다. 또는 이것을 그대로두고 WebFaultException 대신 WebException을 사용해보십시오.

throw new 
    WcfRestContrib.ServiceModel.Web.Exceptions.WebException(HttpStatusCode.BadRequest, "My custom error!");