01 November 2012

Silverlight and SharePoint connection with MVVM

  BasicHttpBinding binding = new BasicHttpBinding();
                EndpointAddress Address = new EndpointAddress(new Uri("http:///_vti_bin/lists.asmx"));
                // Required to initialize variables        

                ListsSoapClient proxy = new ListsSoapClient(binding, Address);
                proxy.GetListItemsCompleted += new EventHandler(proxy_GetListItemsCompleted);
                
                //Define the parameters for the service call
                XElement query = new XElement("Query");
                XElement queryOptions = new XElement("QueryOptions");
                XElement viewFields = new XElement("ViewFields");

                proxy.GetListItemsAsync("",
                    null,
                    query,
                    viewFields,
                    null,
                    queryOptions,
                    null);

Handler :

void proxy_GetListItemsCompleted(object sender, GetListItemsCompletedEventArgs e)
        {
            XDocument doc = XDocument.Parse(e.Result.ToString());

            var rst = from item in doc.Descendants(XName.Get("row", "#RowsetSchema"))
                      select new OpenTktValue
                      {
                          Column1 = item.Attribute("ows_Column1").Value.ToString(),
                          ColumnN = item.Attribute("ows_ColumnN").Value.ToString()
                      };

            rst.First().Column1.ToString() + "-" + rst.First().Column1.ToString());
        }

Rate Now: