Take care of the results from a WSS Web Service (part 2)
In an earlier post I talked a little about recieving the XML result from a request to a WSS Web Service. In this post I thought I talk a bit more on this topic. I said in the previous post that I built a couple of classes to recieve the XML results.
To create these classes I also use XML attributes defined in the namespace System.Xml.Serialization. So the classes to hold i.e. LastName and FirstName from a contact list could look like this;
Imports System.Xml.Serialization
<XmlRoot(ElementName:="listitems", Namespace:="http://schemas.microsoft.com/sharepoint/soap/")> _
Public Class ListResults
<XmlElement(ElementName:="data", Namespace:="urn:schemas-microsoft-com:rowset")> _
Public Data As ListData
End Class
Public Class ListData
Public Sub New()
End Sub
<XmlAttributeAttribute("ItemCount")> _
Public ItemCount As Int32
<XmlElement(ElementName:="row", Namespace:="#RowsetSchema")> _
Public Items As ListItem()
End Class
Public Class ListItem
Private m_LastName As String
Private m_FirstName As String
Public Sub New()
End Sub
<XmlAttributeAttribute("ows_Title")> _
Public Property LastName() As String
Get
Return m_LastName
End Get
Set(ByVal Value As String)
m_LastName = Value
End Set
End Property
<XmlAttributeAttribute("ows_FirstName")> _
Public Property FirstName() As String
Get
Return m_FirstName
End Get
Set(ByVal Value As String)
m_FirstName = Value
End Set
End Property
End Class
The ListItem class can easily be extended to hold more fields from the contact list, or customized to hold data from an entirely different WSS list.
Maybe you wonder why the field for LastName has the attribute ows_Title? Well, that's WSS's behaviour that it in a newly created list always create a field called Title. You cannot delete that field, but you can change it's DisplayName. But the underlying field name remains.