.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Melody Anderson

Home >> Articles >> SharePoint >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Web Services in SharePoint 2010

Posted By:Jean Paul       Posted Date: November 30, 2012    Points: 200    Category: SharePoint    URL: http://www.dotnetspark.com  

In this article we will see the Web Services feature of SharePoint 2010. It provides the flexibility of interoperability compared with the Server Object Model. Developers can access and manage SharePoint site from non .Net platforms like Java. The attached source code contains the example we discussed.

SharePoint Web Services provides is a good feature that allows us to access or change the SharePoint items remotely.  We can use the Web Services to add more power to our application.

Following are the core features of SharePoint Web Services:

·  Foundation and Server Web Services
·  More Interoperability compared with Server Object Model
·  Above 25 Web Services
·  Manage Sites, Lists, Libraries, and Picture Libraries etc.
·  Run queries against the server
·  Custom  Web Service creation possible

The following table contains some of the web services inside SharePoint 2010.

Creation and Deletion of sites
List Management service
List Item Events service
Authentication based service
Web sites management service
Searching service

A more detailed list can be found here:


How to find the url of a Service?

The url of a service can be located inside _vti_bin folder of the site or site collection.  Each site or site collection will be having this folder with all the web services inside it with .asmx extension.

Example: To use the search service use the following url:


Adding Reference to Project

Now we can try adding reference to the service inside Visual Studio application.  Create a new Ordinary Console Application (please note that we are not using SharePoint Console Application)

Now we need to Add Web Reference.  In Visual Studio 2010 this option is available under the Add Service Reference option as shown below.

In the appearing dialog click the Advanced button.

In the next dialog, choose Add Web Reference option.

You will get the following dialog.  This dialog is suitable for adding web service references.

Enter the url of the Lists.asmx as shown above.  You need to replace the pc name with yours.

Set a Web reference name in the second highlighted box.  This serves as the namespace.

Click the Add Reference button and your proxy class and related classes will be ready within a while.  Inside the Program.cs enter the namespace and you can see the classes inside it as shown below:

Invoking the Proxy Class

Our class of interest is the Lists proxy.  You can create an instance of it using the following code:

SPReference.Lists client = new SPReference.Lists();

Setting Credentials

Whenever we open a SharePoint site (without anonymous login enabled) the site will be prompting with user credentials.  As we are invoking through web service the prompt dialog won’t be working.  We need to pass the credentials using the property named Credentials.
client.Credentials = new NetworkCredential("appes""password"); / // using System.Net;

Getting Reference to a List

We can try getting a reference to the Manager List inside our site.  The Managers list contains items with columns:

·  Title
·  Name
·  Address

Use the following code to fetch the data and display it to the console:

SPReference.Lists client = new SPReference.Lists();
client.Credentials = new NetworkCredential("appes", "PWD");
System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();
System.Xml.XmlElement viewFields = xmlDoc.CreateElement("ViewFields");
viewFields.InnerXml = "<FieldRef Name=\"Title\" />" +
    "<FieldRef Name=\"Name\" />" +
    "<FieldRef Name=\"Address\" />";

XmlNode listItems = client.GetListItems("Manager", null, null, viewFields, null, null, null);
foreach (XmlNode node in listItems)
    if (node.Name == "rs:data")
        for (int f = 0; f < node.ChildNodes.Count; f++)
            if (node.ChildNodes[f].Name == "z:row")
                string title = node.ChildNodes[f].Attributes["ows_Title"].Value;
                string name = node.ChildNodes[f].Attributes["ows_Name"].Value;
                string address = node.ChildNodes[f].Attributes["ows_Address"].Value;

                Console.WriteLine(title + " " + name + " " + address);


On executing the application we can see the following result:

Following are the steps involved in getting list item data:

1.  Create List Proxy client
2.  Set Credentials
3.  Set the View Columns
4.  Invoke GetListItems() method
5.  Iterate through the nodes
6.  Get value of node having name z:row


Using web services, xml is used to represent the data.  For advanced programming using properties please refer to the Server Object Model and SharePoint LINQ articles.





In this article we have seen the Web Services feature of SharePoint 2010.  It provides the flexibility of interoperability compared with the Server Object Model.  Developers can access and manage SharePoint site from non .Net platforms like Java.  The attached source code contains the example we discussed.

 Subscribe to Articles


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend