1
votes

I have a simple service built with ServiceStack

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

In a different namespace:

public class GetContactMasterData
{

}

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

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

When I send a JSON request I correctly get:

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

When I send a soap12 request with soapUI, I get the typical yellow screen of death

<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>

Is this the expected behavior? How can I get a neatly serialized ResponseStatus similar to the JSON response.

Thanks in advance.

1
Sorry prematurely posted. Updated to include the question - Alper

1 Answers

1
votes

The HTML error page you get doesn't looks like it's coming from ServiceStack, check to see if your website has something that could be hijacking the errors with its own page, e.g: <customErrors />.

The correct behavior for SOAP endpoints is to throw a SOAP fault which if you're using either the Soap11ServiceClient or Soap12ServiceClient generic service clients will be converted to a WebServiceException as seen in this 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));
}