4
votes

I've created a simple webservice with ServiceStack, and I've set up some validation using the built-in FluentValidation functionality. If I hit the 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 response DTO is filled in as expected. But, if I then switch the exact same code over to use the Soap12 client the service returns back HTML with some SOAP at the end of it. I saved the resulting HTML to a file and opened it in the browser, and sure enough that tells me what validation has been tripped. The SOAP that comes after the HTML doesn't have the ResponseStatus filled in (it's set to i:nil="true"). Is that expected when using the SOAP endpoint?

AppHost validation setup:

Plugins.Add(New ValidationFeature())
container.RegisterValidators(GetType(AppHost).Assembly)

Request DTO:

<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

Response DTO:

<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

Service Class:

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
1

1 Answers

0
votes


I've experienced similar issues when using the soap12 client. In my test app(asp.net) I am calling the web service with pretty much the same setup. I am receiving "Response is not well-formed XML." I can't actually see the response as it appears to be null. The out ResponseStatus variable is null similar to your situation. I am experiencing the problem specifically when using a wsdl file generated against the soap12/soap11 webservice. (I'm using service stack for the web service).
Workaround:
I managed to use "Add service reference" from within VS and it returned the expected fluent validation errors without a problem but this is not really an answer for me as I have to expost to client who may not be using .NET. If you do discover the source of the problem I'd appreciate it. T