Creating Custom WebService In SharePoint 2007
Posted by Ali Khan on August 7, 2009
In this post i am going to show you how to create a custom webservice in sharepoint 2007. There is already an article (Hello World Webservice) on msdn about this.
http://msdn.microsoft.com/en-us/library/ms464040.aspx
Except the fact, the article on MSDN wants you to create the WSDL and DISCO file for yourself, which I found out to be very hectic and time consuming. Instead we can just use any tool that will generate the WSDL and DISCO file for us.
1. As First Step, Create a class library in Visual Studio
2. Add the references to the “Microsoft.Sharepoint.dll” and “System.Web.Services” dll
3. Add a new class and inherit it from “Webservice” class
4. Sign the assembly. As it will be deployed in GAC
5. Write your code for the custom webserivce. Here are just two methods for renaming the folder in a document library
6. Build your project and install it in GAC.
7. Create a custom SPFolderWS.asmx file which will point to the SPFolderWS.cs (which you defined in the class library, and is installed in GAC). Note this file “SPFolderWS.asmx” doesn’t need to be in the project.
8. Use the SPDev Tool to generate the DISCO and WSDL file for you. ( You can download the SPDev Tool from the following website)
http://www.crsw.com/spdev/Wiki%20Pages/GenWS.aspx
9. Here are your generated WSDL and DISCO file.
10. Copy these files to the “C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\ISAPI” directory
11. Browse the URL to make sure the webservice is properly deployed
12. That’s it.
Now to test the above webservice, we will create a console application.
1. Create a Console Application, and add the reference to the webservice as shown below
2. Write the following code snippet to call the methods of the custom webservice.
3. If everything works fine, the folder should be re-named.
4. That’s All
You can also download this code from the following location.
MS CRM 4.0 Plugin Integeration With Sharepoint using Sharepoint.dll « Muhammad Ali Khan said
[…] Creating Custom WebService In SharePoint 2007 […]
Dipti Chhatrapati said
Thank you very much , this article has removed my confusions regarding Deployment of web service in sharepoint
Thanks Again 🙂
Denis said
Thanks a lot for this example!
One question though: what should we do with http://tempuri.org? What should it link to precisely?
All the best
Ali Khan said
Hi Denis, It’s just the namespace, you can change it to whatever, like your company name e.g. http://yourcompany.org.
Abraham said
Hi Ali,
It was incredible. simple and sweet, I have been messing with this issue for the last 3 days and this article helped to fix it. Great work.
Rajesh said
It was really a nice well complied article without any confusion..keep posting
Yourfan said
Great article! Helped me lot.
Dan said
I get a message that web service .disco file in not a valid disco file. Any pointers?
Rahul Vartak said
Very nice explanation !!