Talk to SharePoint using Web Services

n

nmost of the times , being a typical SharePoint developer includes task likes customizing SharePoint and build your custom solutions on top of SP platform , mostly to achieve this people use SharePoint object model (Server object model)

n

nBut there are some cases where you will not be working on server where SharePoint is not installed and still you will need to get the data or communicate to SharePoint platform or sites

n

nWell to achieve such functionalities, MOSS 2007 had only one way and that’s by using SharePoint WebServices

n

nNow with the SharePoint 2010 one have lot of options available now such as SharePoint WebServices, Client object model, REST web services

n

nWe will have a quick look on how we can code using SharePoint web services,

n

nI have create a sample console application in which I am making use of SharePoint 2007 Web Services

n

nTypically all SharePoint web services (.asmx) are found in [12 hive]\ISAPI folder and can be accessed like http://servername/_vti_bin/webservicename.asmx

n

nto get started I will create a sample console application and will add Web Reference of Webs.asmx (_vti_bin/Webs.asmx)

n

nafter adding this web reference we can use web service like this, I am trying to retrieve all available webs in site collection and urls

n

n

n

nI hope this helps someone J

n
n

nstatic void Main(string[] args)

n

n{

n

n   string siteUrl = string.Empty;

n

n   Console.WriteLine(“Enter Site Name:”);

n

n   siteUrl = Console.ReadLine();

n

n   Uri _uri = new Uri(siteUrl);

n

n   try

n

n   {

n

n      WebsSvc.Webs _webs = new ConsumeWebService.WebsSvc.Webs();

n

n      _webs.Url = siteUrl + @”/_vti_bin/Webs.asmx”;

n

n      _webs.UseDefaultCredentials = true;

n

n              

n

n XmlNode _allWebs = _webs.GetAllSubWebCollection();

n

n       string _webUrl = string.Empty;

n

n       if (_allWebs != null && _allWebs.ChildNodes.Count > 0)

n

n       {

n

n         foreach (XmlNode _web in _allWebs.ChildNodes)

n

n         {

n

n           if (_web.Attributes[“Title”] != null && _web.Attributes[“Url”] != null)

n

n           {

n

n  Console.WriteLine(_web.Attributes[“Title”].Value + ” – “ + _web.Attributes[“Url”].Value);

n

n           }

n

n          }

n

n       }

n

n   }

n

n   catch (Exception ex)

n

n   {

n

n       Console.WriteLine(“Error : “ + ex.Message);

n

n   }

n

n}

n

Leave a Comment