Muhammad Ali Khan

MS CRM 3.0, MS CRM 4.0, Sharepoint 2007 & Sharepoint 2010

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 

1

2.    Add the references to the “Microsoft.Sharepoint.dll” and “System.Web.Services” dll

  2

 

3.    Add a new class and inherit it from “Webservice” class

3

4.    Sign the assembly. As it will be deployed in GAC

  

4

 

5.    Write your code for the custom webserivce. Here are just two methods for renaming the folder in a document library

 

0

 

6.    Build your project and install it in GAC.

 

5

 

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.

 

16

 

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

 

6

 

9.    Here are your generated WSDL and DISCO file.

 7

 

10. Copy these files to the “C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\ISAPI” directory

 

11

 

11. Browse the URL to make sure the webservice is properly deployed

 9

 

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

 

12

 

2.    Write the following code snippet to call the methods of the custom webservice.

 

15

 

3.    If everything works fine, the folder should be re-named.

 

14

 4.    That’s All

You can also download this code from the following location.

Custom WebService Code
 

9 Responses to “Creating Custom WebService In SharePoint 2007”

  1. […] Creating Custom WebService In SharePoint 2007 […]

  2. Dipti Chhatrapati said

    Thank you very much , this article has removed my confusions regarding Deployment of web service in sharepoint

    Thanks Again 🙂

  3. 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

  4. 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.

  5. Rajesh said

    It was really a nice well complied article without any confusion..keep posting

  6. Yourfan said

    Great article! Helped me lot.

  7. Dan said

    I get a message that web service .disco file in not a valid disco file. Any pointers?

  8. Very nice explanation !!

Leave a comment