Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net ServiceStack SOAP端点在验证时返回HTML错误_.net_Vb.net_<img Src="//i.stack.imgur.com/WM7S8.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">servicestack - Fatal编程技术网 servicestack,.net,Vb.net,servicestack" /> servicestack,.net,Vb.net,servicestack" />

.net ServiceStack SOAP端点在验证时返回HTML错误

.net ServiceStack SOAP端点在验证时返回HTML错误,.net,vb.net,servicestack,.net,Vb.net,servicestack,我用ServiceStack创建了一个简单的webservice,并使用内置的FluentValidation功能设置了一些验证。如果我使用包含无效数据的JSON请求访问服务,那么一切都会按预期返回。在我的单元测试中,我得到一个WebServiceException,我的响应DTO的ResponseStatus按预期填写。但是,如果我将完全相同的代码切换到使用Soap12客户机,服务将返回HTML,并在其末尾添加一些SOAP。我将生成的HTML保存到一个文件中,并在浏览器中打开它,这足以告诉我什

我用ServiceStack创建了一个简单的webservice,并使用内置的FluentValidation功能设置了一些验证。如果我使用包含无效数据的JSON请求访问服务,那么一切都会按预期返回。在我的单元测试中,我得到一个WebServiceException,我的响应DTO的ResponseStatus按预期填写。但是,如果我将完全相同的代码切换到使用Soap12客户机,服务将返回HTML,并在其末尾添加一些SOAP。我将生成的HTML保存到一个文件中,并在浏览器中打开它,这足以告诉我什么验证失败了。HTML后面的SOAP没有填充ResponseStatus(它被设置为i:nil=“true”)。在使用SOAP端点时是否会出现这种情况

AppHost验证设置:

请求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
测试:

_
公共子残疾长度停止返回失败()
Dim client=新的Soap12ServiceClient(“http://127.0.0.1:81/WebService")
'与JsonServiceClient完美配合
尝试
Dim响应=客户端_
.Send(属于WebServices.decoderess)(使用{.StopCode=“12”}进行新解码)
Assert.Fail(“未引发异常”)
捕获ex作为WebServiceException
Assert.IsNotNull(例如ResponseDto)“
我在使用soap12客户端时也遇到过类似的问题。在我的测试应用程序(asp.net)中,我使用几乎相同的设置调用web服务。我收到的是“响应不是格式良好的XML”。我实际上看不到响应,因为它看起来是空的。out ResponseStatus变量为null,与您的情况类似。 我在使用针对soap12/soap11 Web服务生成的wsdl文件时特别遇到了这个问题。(我正在为web服务使用服务堆栈)
解决方法:
我设法从VS中使用了“添加服务引用”,它返回了预期的fluent验证错误,没有问题,但这对我来说并不是一个真正的答案,因为我必须向可能不使用.NET的客户公开。 如果你能找到问题的根源,我将不胜感激。
T

我开始认为它不是servicestack的常见用例。解决方案可能是提交一个补丁。。。如果我有时间,我会这样做。嗨,ElRobbo,我的问题是FluentValidation正在返回一个响应对象数组,如果您引用的是一行:由于VS.NET的Add Service引用是为使用.asmx或WCF RPC方法调用而优化的,因此它不正确支持多个返回值(例如,当您还需要ResponseStatus属性时)。我最终实现了我自己版本的FluentValidation(只是我需要的方法),并将我的response DTO设置为Singleton。这确保了响应不会出错。希望这能有所帮助
<DataContract()> _
Public Class Decode
    Inherits AbstractRequest

    <DataMember()> Public Property StopCode As String

End Class
Public Class DecodeRequestValidator
    Inherits AbstractValidator(Of Decode)

    Public Sub New()
        RuleFor(Function(req) req.StopCode).Length(3)
    End Sub

End Class
<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
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()> _
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