Monday, September 27, 2004

VJs Tip Of The Day - September 27th 2004

SoapInclude Attribute

In case of webservice programming you can allow SoapInclude Attribute on your webmethod to make sure that the specific type gets passed by... You use this attribute on your webmethod when in normal circumstances that type would not get passed...
For instance, if you have a class inheriting for a base class and a member is declared of the type base class and later instantiated as derieved, then the derieved class will not get passed across in that scenario on your webmethod you would apply this attribute...

Look at the example below...

&ltWebMethod(), SoapInclude(GetType(Circle)), XmlInclude(GetType(Circle))&gt _
Public Function ReturnSomething(ByVal key As String) As Shape
If (key = "Circle") Then
Dim circl As Shape = New Circle()
circl.area = 2
Return circl
End If
End Function

&ltSerializable()&gt _
Public Class Shape
Public area As Double
End Class

&ltSerializable()&gt _
Public Class Circle
Inherits Shape
Public radius As Double
End Class