具有 MessageContract 和 DataContract 的 WCF 结构不起作用

WCF structure with MessageContract and DataContract does't work

我有一个具有多种数据类型的 WCF Web 服务。这种结构不起作用。我可以调用 WSDL,但如果我尝试调用该方法,它会抛出异常:

An error occurred while receiving the HTTP response to http://adress. This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down).

我读过这篇文章 ,但我没有找到我的解决方案。我搜索 not set DataMember 并尝试在 web.config 中设置 <httpRuntime maxRequestLength..>,但这并没有改变任何东西。我的结构有什么问题?

<ServiceContract(Name:="service", Namespace:="http://namespace")>
Public Interface IService1

   <OperationContractAttribute(Action:="http://namespace/methodRequest", name:="method", ReplyAction:="http://namespace/methodResponse")> _
    Function method(input As methodRequest) As methodResponse
End Interface

<MessageContract()>
Public Class methodResponse

    Public result As Object

    <MessageBodyMember(Name:="return", Namespace:="")> 
    Public Property resultP() As Object
        Get
            Return Me.result
        End Get
        Set(value As Object)
            Me.result = value
        End Set
    End Property
End Class

<DataContract()>
Public Class typeArray

    Public typeArrayD As ownType()    

    <DataMember(Name:="value", Order:=1)>
    Public Property value() As ownType()

        Get
            Return typeArrayD
        End Get

        Set(value As ownType ())
            typeArrayD = value
        End Set

    End Property

End Class

<DataContract()>
Public Class ownType
    Private stringValueD As String    

    <DataMember(Name:="stringValue", Order:=1)>
    Public Property stringValue() As String

        Get
            Return stringValueD
        End Get

        Set(value As String)
            stringValueD= value
        End Set

    End Property
End Class

<ServiceBehavior(Namespace:="http://namespace", Name:="service")>
Public Class Service1
    Implements IService1

        Public Function method(input As methodRequest) As methodResponse Implements IService1.method

            Dim result As New methodResponse()
            result.result = New typeArray
            result.result.value = valueOfOwnType

            Return result
     End Function
 End Class

解决方案:

我必须将 ServiceKnownType 添加到 class。有了这个就可以了

<ServiceContract(Name:="service", Namespace:="http://namespace")>
<ServiceKnownType(GetType(typeArray))>
<ServiceKnownType(GetType(ownType))>
Public Interface IService1
...
End Interface