.netwcfdatacontractmessagecontract

WCF structure with MessageContract and DataContract does't work


I have a WCF web service with multiple own datatype. This structure doesn’t work. I can call the WSDL, but if I try to call the method it throw the Exception:

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).

I had read this article WCF Web Service error: "Service endpoint binding not using HTTP protocol"?, but I don’t found my solution. I search for not set DataMember and I tried to set <httpRuntime maxRequestLength..> in the web.config, but this doesn’t change anything. What is wrong with my structure?

<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

Solution

  • Solution:

    I must add the ServiceKnownType to the class. With this it works

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