2015-09-23 64 views
0

我有一個具有多個自己的數據類型的WCF Web服務。這種結構不起作用。我可以調用WSDL,但是如果我嘗試調用它拋出異常的方法:帶有MessageContract和DataContract的WCF結構不起作用

接收到對http://adress的HTTP響應時發生錯誤。 這可能是由於服務端點綁定未使用HTTP 協議。這也可能是由於服務器中止了HTTP請求上下文 (可能是由於服務關閉)。

我已經讀過這篇文章WCF Web Service error: "Service endpoint binding not using HTTP protocol"?,但我沒有找到我的解決方案。我搜索未設置的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 

回答

0

解決方案:

我必須ServiceKnownType添加到類。有了它,它可以工作

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