2012-08-14 46 views
1

我有ServiceStack不一致ServiceStack異常處理

public class GetContactMasterDataService : IService<GetContactMasterData> 
{ 
    public object Execute(GetContactMasterData getContactMasterData) 
    {    
     return ContactApi.FetchContactMasterData(); 
    } 
} 

建在不同的命名空間一個簡單的服務:

public class GetContactMasterData 
{ 

} 

public class GetContactMasterDataResponse 
{ 
    public ResponseStatus ResponseStatus { get; set; } 
} 

public static GetContactMasterDataResponse FetchContactMasterData() 
{ 
    throw new ApplicationException("CRASH"); 
} 

當我送一個JSON請求我正確地得到:

{ 
    "ResponseStatus":{ 
    "ErrorCode":"ApplicationException", 
    "Message":"CRASH", 
} 
} 

當我用soapUI發送soap12請求時,我得到了典型的死亡黃屏

<html> 
<head> 
    <title>CRASH</title> 
... 
<h2> <i>CRASH</i> </h2></span> 
<b> Description: </b>An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
... 
<b> Exception Details: </b>System.ApplicationException: CRASH<br><br> 

這是預期的行爲?我如何得到一個類似JSON響應的整齊序列化的ResponseStatus。

在此先感謝。

+0

有什麼問題嗎? – 2012-08-14 21:40:52

+0

抱歉提前張貼。已更新爲包含問題 – Alper 2012-08-14 21:47:38

回答

1

您收到的HTML錯誤頁面看起來不像012,,請檢查您的網站是否有可能用自己的頁面劫持錯誤的東西,例如:<customErrors />

正確的行爲SOAP端點是拋出一個SOAP錯誤這如果您使用的是該Soap11ServiceClient或在看到Soap12ServiceClientgeneric service clients將被轉換爲WebServiceException這個Integration test

var client = new Soap12ServiceClient(ServiceClientBaseUri); 
try 
{ 
    var response = client.Send<AlwaysThrowsResponse>(
     new AlwaysThrows { Value = TestString }); 

    Assert.Fail("Should throw HTTP errors"); 
} 
catch (WebServiceException webEx) 
{ 
    var response = (AlwaysThrowsResponse) webEx.ResponseDto; 
    var expectedError = AlwaysThrowsService.GetErrorMessage(TestString); 
    Assert.That(response.ResponseStatus.ErrorCode, 
     Is.EqualTo(typeof(NotImplementedException).Name)); 
    Assert.That(response.ResponseStatus.Message, 
     Is.EqualTo(expectedError)); 
} 
+0

即使使用我也會得到相同的結果。將嘗試與不同的客戶端。 – Alper 2012-08-15 15:31:06