SharePoint 2007 (MOSS/WSS) using Lists.asmx - GetListItems

Requirement: I have a custom desktop application and I have created an installer for it. During installation it needs to connect trough Internet to receive the key. Now I have stored these keys in a SharePoint List as given below:

image

The user will provide the Activation Key and Registration Number and will receive the Unlock Key to proceed with the software installation. We can use the OOB Lists.asmx web service to achieve this. The web method we are going to use is GetListItems.

I have created a Windows Application to test. Here I'll add Activation Key and Registration Number and will receive the Unlock Key.

image

In the application I add web reference of https://<site_url>/_vti_bin/lists.asmx with a name ListProxy.

Here is the code of my application:

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

using System.Xml;

namespace TestKeyApp

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }

        private void Form1_Load(object sender, EventArgs e)

        {

        }

        private void button1_Click(object sender, EventArgs e)

        {

            ListProxy.Lists newListProxy = new ListProxy.Lists();

            //change the username, password and domain with the value of a use who has permission to the list

            newListProxy.Credentials = new System.Net.NetworkCredential("<username>", "<password>", "<domain>");

            XmlDocument xmlDoc = new XmlDocument();

            XmlNode ndQuery = xmlDoc.CreateNode(XmlNodeType.Element, "Query", "");

            XmlNode ndViewFields = xmlDoc.CreateNode(XmlNodeType.Element, "ViewFields", "");

            ndViewFields.InnerXml = "<FieldRef Name='Unlock_x0020_Key'/>";

            ndQuery.InnerXml = "<Where><And><Eq><FieldRef Name='Activation_x0020_Key' /><Value Type='Text'>" + textBox1.Text + "</Value></Eq><Eq><FieldRef Name='Registration_x0020_Number' /><Value Type='Text'>" + textBox2.Text + "</Value></Eq></And></Where>";

            try

            {

                XmlNode ndListItems = newListProxy.GetListItems("KeyList", null, ndQuery, ndViewFields, null, null, null);

                //MessageBox.Show(ndListItems.OuterXml);

                XmlNamespaceManager nsManager = new XmlNamespaceManager(ndListItems.OwnerDocument.NameTable);

                nsManager.AddNamespace("z", "#RowsetSchema");

                nsManager.AddNamespace("s", "uuid:BDC6E3F0-6DA3-11d1-A2A3-0AA00C14882");

                nsManager.AddNamespace("dt", "uuid:C2F41010-65B3-11d1-A29F-00AA00C14882");

                nsManager.AddNamespace("rs", "urn:schemas-microsoft-com:rowset");

                XmlNodeList nodes = ndListItems.SelectNodes("rs:data/z:row", nsManager);

                foreach (XmlNode node in nodes)

      {

//label4 is where I am showing the unlock key

label4.Text += node.Attributes["ows_Unlock_x0020_Key"].Value;

      }

               

            }

            catch (Exception ex)

            {

                MessageBox.Show("Please Enter correct activation key and registration number, message: " + ex.Message);

            }

        }

    }

}