Logo 
Search:

Sharepoint Link

Submit a Link
Home » Links » SharepointRSS Feeds

Talk to SharePoint Through its Web Services

  Shared By: Asia Meyers    Date: Jun 16   Category: Sharepoint    Views: 9581

Microsoft Office is very tightly integrated with SharePoint by utilizing its web services. Windows SharePoint Services comes with sixteen different web services. SharePoint Portal Server supports an additional five web services. The web services provided by SharePoint do provide a vast array of features. But not all SharePoint features are accessible through them. If required you can build your own web service on top of SharePoint leveraging the managed SharePoint server API itself. The web service interfaces make it very easy to integrate SharePoint capabilities right into your application.

This article is not a detailed documentation of every web method and web service provided by SharePoint. It is rather an introduction to its capabilities and how to use them. You can download the Windows SharePoint Services SKD or the SharePoint Portal Server SKD for a complete reference of all web services and also of the server API itself. Please refer to this article for a guide how to install and administrate SharePoint or this article for a guide how to use and customize SharePoint portals.

How to add a Windows SharePoint web service reference

You can add a web reference to each SharePoint web service through your Visual Studio .NET IDE. In your Solution Explorer right click on your project and select “Add Web Reference” from your popup menu. The table below shows the URLs to use for each web service provided by WSS. Enter the URL to the web service and click the Go button. This will show you in the dialog box a summary of all available web methods. Next enter the name of the web reference and then click Add Reference.

Setting the web service user credentials

The SharePoint web services only accept calls from existing SharePoint users and do also enforce access security. Import the System.Net namespace into your project and then use the NetworkCredential class to set the user credential to use for the web service call. Here is a code snippet:


public static XmlNode VersionsGetVersions(string SharePointHost, string
UserName,
string Password, string Domain, string FileName)
{
// proxy object to call the Versions web service
Versions.Versions VersionsService = new Versions.Versions();

// the user credentials to use
VersionsService.Credentials = new NetworkCredential(UserName, Password,
Domain);
VersionsService.Url = SharePointHost + “_vti_bin/Versions.asmx”;

// gets the file versions
XmlNode Result = VersionsService.GetVersions(FileName);

// dispose the web service object
VersionsService.Dispose();
return Result;
}

For example, first you create an instance of the Versions web service. Then you assign a new instance of the NetworkCredential class to the Credentials property on the created web service object. We pass along the user name, password and the user’s domain name to the NetworkCredential object. Next you set the web service URL, which might very well be different from the one used when you created the web reference. Finally you invoke the desired web method, in the code snippet above the GetVersions() web method. The web method takes a file name and returns a XML document with all available versions of this file (Document libraries can have versioning enabled and then keep a history for each version). At the end you call Dispose() on the web service object to free up any underlying unmanaged resources.

If the user does not exist in SharePoint or does not have the permission to perform the operation then a WebException is thrown by SharePoint. The returned HTTP status is 401, which means unauthorized request. There are some inconsistencies across all web services. For example some web methods take a XML string as input while others take an XmlNode as input. Most web methods return the result as XmlNode while others return a XML string and while others again return complex data structures. But after you get used to these inconsistencies it is very easy to use these web services and integrate SharePoint capabilities right into your application.

Share: 
 

No Answers Found. Be the First, To Post Answer.

 

Didn't find what you were looking for? Find more on Talk to SharePoint Through its Web Services Or get search suggestion and latest updates.


Your Review Comment
  • Review should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

Tagged: