我懷疑我是非常愚蠢的在這裏,但我有以下設置返回一個繼承類的基類與Web服務
Class MustInherit myBaseClass
'some stuff
End Class
Class myInheritedClassA
inherits myBaseClass
'some more stuff
End Class
Class myInheritedClassB
inherits myBaseClass
'some more stuff
End Class
我再有,有一個方法Web服務
Function getSomeClass(id) as myBaseClass
'a factory here dependent on the id will generate a myInherited Class
return CType(aInstanceOfInheritedClass, mybaseClass)
End function
運行這將導致以下錯誤
Unhandled Exception: System.InvalidOperationException:
There was an error generating the XML document. --->
System.InvalidOperationException:
The type <type> was not expected.
Use the XmlInclude or SoapInclude attribute to specify types
that are not known statically."
所以我的問題是,是否有什麼辦法將繼承的類「擴展」到基類,這樣可以工作嗎?編輯:RE:關於XmlInclude(typeof inheritedClass)的建議,目前這種方法可能會返回一些類型的繼承類(即myInheritedClassA和myInheritedClassB)是它只需要添加每個繼承類型在這個標籤?
我修改了例子,希望讓事情更清晰
@Ramesh中使用的屬性的語法是,C#(OP需要VB.NET),但足夠接近。現在,很好的結果,我假定OP使用SOAP編碼,但是在使用「純文本」編碼的情況下,XmlInclude就是票據。我會相應地修復我的迴應。 – mjv 2009-09-25 13:29:21
@mjv你是對的! C#剛剛回答時自然而然,因爲它已經好幾年了,我停止vb ....將現在更新... – RameshVel 2009-09-25 13:56:34