Using SharePoint Web Services


In addition to the object model, you can also access SharePoint Services information using web services. SharePoint Services exposes web services for remote management of nearly every aspect of SharePoint Services. Using these services, you can integrate the information in SharePoint Services with other line-of-business systems.

To use a web service in Visual Studio, follow these steps:

  1. In Visual Studio, select File New Project.

  2. In the New Project dialog, click Visual C# Projects, and then select Windows Application.

  3. Name the project and then click OK.

  4. In the Solution Explorer, right-click Web References and select Add Web Reference from the pop-up menu.

  5. In the Add Web Reference dialog box, enter http://spsportal/_vti_bin/lists.asmx to reference the list web service.

    Note

    Each web service requires a different reference.

  6. Click Go to see the web service definition.

  7. Click Add Reference to make the service available to your project.

Once the web service is referenced, you can use it in your project just like any other namespace. Values returned from the web service vary depending upon which service is called, but the calling technique is largely the same. Before calling the web service, you must authenticate the current user with the service. After authentication, you can make calls to the methods of the service. The following code shows how to authenticate the current user with the service and return a set of lists.

 spsportal.Lists service = new spsportal.Lists(); service.Credentials=System.Net.CredentialCache.DefaultCredentials; System.Xml.XmlNode node = service.GetListCollection(); textBox1.Text=node.OuterXml; 

You can also use the web services to create and manage your own document and meeting workspaces. This is perhaps the most compelling use of the available web services because it allows you to create functionality similar to the workspace pane found in Microsoft Office. You can reference the document workspace web service at spsportal/_vti_bin/Dws.asmx and the meeting workspace web service at spsportal/_vti_bin/Meetings.asmx . Creating a document or meeting workspace uses essentially the same approach with differences primarily in the arguments and return values.

Creating a document workspace is done by calling the CreateDws method of the web service. This method can be used to create the workspace, add users, and associate documents. It expects the user and document data to be in a designated XML format. It also needs the user to specify a name and a title for the new workspace. Listing 9-9 shows an example of creating a document workspace and adding users.

Listing 9-9: Creating a Document Workspace
start example
 spsportaldws.Dws dwsService = new spsportaldws.Dws(); dwsService.Credentials = System.Net.CredentialCache.DefaultCredentials; string users = "<UserInfo>" + "<item Email='" + txtMail1.Text + "' Name='" + txtName1.Text + "'/>" + "<item Email='" + txtMail2.Text + "' Name='" + txtName2.Text + "'/>" + "<item Email='" + txtMail3.Text + "' Name='" + txtName3.Text + "'/>" + "</UserInfo>"; txtResponse.Text= dwsService.CreateDws(txtName.Text,users,txtTitle.Text,""); 
end example
 

When the workspace is created, the service responds with an XML payload that states the results of the call. If a workspace already exists, for example, an error code will return. If the creation process was successful but errors occurred when adding users or documents, that information is also provided. Listing 9-10 shows a typical response to site creation.

Listing 9-10: Workspace Creation Response
start example
 <Results> <Url>http://spsportal/Workspace</Url> <DoclibUrl>Shared Documents</DoclibUrl> <ParentWeb>DataLan Corporation</ParentWeb> <FailedUsers>     <User Email="JohnArnold@sps.local" /> </FailedUsers> <AddUsersUrl>http://spsportal/Workspace/_layouts/1033/aclinv.aspx</AddUsersUrl> <AddUsersRole>Contributor</AddUsersRole> </Results> 
end example
 

Once the workspace is created, you may use other methods of the services to manage users, documents, tasks , and alerts. In this way, you can create a fully functional document or meeting workspace for any application.




Microsoft SharePoint[c] Building Office 2003 Solutions
Microsoft SharePoint[c] Building Office 2003 Solutions
ISBN: 1590593383
EAN: N/A
Year: 2006
Pages: 92

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net