To provide integration to other systems, found that the webservice of SharePoint with a variety of different, simply write their own point, but also as a record of their own study. Of course, the content is relatively simple, I hope heroes do not mind, do not scold me ah. All right, let's get to the point.
1. First, use VS2008 to create a new WebService project, select the ASP.net Web Service application, and then enter the project name
2. Add Reference
Add a reference to the Microsoft.SharePoint.dll file because we need to use the SharePoint object model to read the list information, where the DLL file is C:\Program files\common Files\Microsoft Shared\Web Server Extensions\12\isapi\microsoft.sharepoint.dll
3. Add function
The function is preceded by a [WebMethod] tag, and then defines the method we need, the parameter and the return value of the method, the method in which to write our call, my code is a simple example, and the return is a string type, and if the operation fails, the return is null.
Getlistitem (string weburl,string listname,int ID)//Get list items, including Web address, list name, ID
public string Getwebid (string weburl)//Get WebID property of Web site
[WebMethod]
public string GetWebID(string WebUrl)
{
try
{
SPSite site = new SPSite(WebUrl);
SPWeb web = site.OpenWeb();
return web.ID.ToString();
}
catch (Exception ex)
{
return "";
}
}
[WebMethod]
public string GetListItem(string WebUrl, string ListName, int ID)
{
try
{
SPSite site = new SPSite(WebUrl);
SPWeb web = site.OpenWeb();
SPListItem item = web.Lists[ListName].Items[ID];
String rt = "标题:" + item["Title"].ToString() + "内容:" + item["内容"].ToString();
return rt;
}
catch (Exception ex)
{
return "";
}
}
4, Post WebService test
After you publish to IIS, open our webservice and see our custom two methods, all in WebService.