Brief Introduction: it provides integration for other systems and finds that the WebService provided by Sharepoint is not easy to use. Simply write it yourself and use it as a learning record. Of course, the content is relatively simple. I hope you don't mind or scold me. Now, let's go to the topic.
1. First, use vs2008 to create a WebService project, select Asp.net web service application, and enter the project name
2. Add reference
Add Microsoft. sharepoint. DLL file reference, because we need to use the SharePoint object model to read the list information, the DLL file location is C: \ Program Files \ common files \ microsoft shared \ Web Server Extensions \ 12 \ ISAPI \ Microsoft. sharepoint. DLL
3. Add a function
Before the function, write the [webmethod] Mark, and then define the methods, method parameters, and return values we need. In the method, write our calls. My code is a simple example, the return value is of the string type. If the operation fails, the return value is null.
Getlistitem (string weburl, string listname, int ID) // you can call this operation to obtain the list items, including the website address, list name, and ID.
Public String getwebid (string weburl) // obtain the webid attribute of the website
[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 = "title:" + item ["title"]. tostring () + "content:" + item ["content"]. tostring (); Return RT; } Catch (exception ex) { Return ""; } } |
4. Test WebService release
After publishing to IIS, open our WebService and we can see that our custom methods are all in WebService.
5. Use two functions
We can test our two functions separately. Click our functions to enter the following interface, enter our parameters, and call them.
6. Call results
If we can see the call results, the first figure below is the getlistitem (string weburl, string listname, int ID) function, and the second figure is the result of getwebid (string weburl.
Summary
Now, my blog record is written here today. We have a lot of comments on the environment to combat the self-confidence I just gave birth!
**************************************** **************************************
Author: Yu
Source: http://www.cnblogs.com/jianyus
The copyright of this article is shared by Yu and the blog Park. You are welcome to reprint it, but please indicate the source.