ServiceStack SOAP endpoint returning HTML for validation error

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 
+4
source share
1 answer


I am having similar problems when using the soap12 client. In my test application (asp.net), I call the web service with almost the same setup. I get "The answer is not properly formed XML." In fact, I do not see the answer as it seems to be null. The original ResponseStatus variable is null, similar to your situation. I ran into a problem, especially when using the wsdl file created using the soap12 / soap11 web service. (I use the service stack for the web service).
Decision:
I managed to use the "Add Service Link" from VS and it returned the expected smooth validation errors without any problems, but this is not an answer for me, since I have to show a client that may not use .NET. If you find the source of the problem, I would appreciate it. T

0
source

Source: https://habr.com/ru/post/1488953/


All Articles