I created a simple web service with ServiceStack, and I configured some validation using the built-in FluentValidation functionality. If I find a service with a JSON request with invalid data, everything returns as expected. In my unit test, I get a WebServiceException, and the ResponseStatus of my DTO response is populated as expected. But if I then switch the same code to using the Soap12 client, the service will return the HTML back with some SOAP at the end of it. I saved the received HTML file to a file and opened it in the browser, and, of course, this means that the check was checked. The SOAP that appears after the HTML does not populate the ResponseStatus (it is set to i: nil = "true"). Is this expected when using a SOAP endpoint?
AppHost validation setup:
Plugins.Add(New ValidationFeature()) container.RegisterValidators(GetType(AppHost).Assembly)
DTO request:
<DataContract()> _ Public Class Decode Inherits AbstractRequest <DataMember()> Public Property StopCode As String End Class
Request Validator:
Public Class DecodeRequestValidator Inherits AbstractValidator(Of Decode) Public Sub New() RuleFor(Function(req) req.StopCode).Length(3) End Sub End Class
DTO answer:
<DataContract()> _ Public Class DecodeResponse Implements ServiceStack.ServiceInterface.ServiceModel.IHasResponseStatus <DataMember()> Public Property StopName As String <DataMember()> Public Property ResponseStatus As ServiceStack.ServiceInterface.ServiceModel.ResponseStatus Implements ServiceStack.ServiceInterface.ServiceModel.IHasResponseStatus.ResponseStatus End Class
Class of service:
Public Class DecodeService Inherits Service Public Function Any(request As Decode) As Object Dim response As New DecodeResponse() response.StopName = "test" Return response End Function End Class
Test:
<Test()> _ Public Sub InvalidLengthStopReturnsFailure() Dim client = New Soap12ServiceClient("http://127.0.0.1:81/WebService") ' Works perfectly with JsonServiceClient Try Dim response = client _ .Send(Of WebServices.DecodeResponse)(New Decode With {.StopCode = "12"}) Assert.Fail("No exception thrown") Catch ex As WebServiceException Assert.IsNotNull(ex.ResponseDto) ' <-- FAIL - ex.ResponseDto is null End Try End Sub
source share