Custom SharePoint Web Service has no WSDL or DISCO

Posted: 29th July 2011 in Sharepoint 2010, Visual Studio 2010, Web Services

One I’ve been meaning to blog for a while, but just never got round to it Surprised smile

I came across an error when Creating a Custom web service for SharePoint when trying to deploy the web service to the ISAPI  folder, allowing me to access a web service through the  _vti_bin of SharePoint. 

When you create a web service and deploy it to a mapped folder the code behind, as expected goes into the GAC. However, there is no WSDL or DISCO file associated with the web service, so it doesn’t work. 

To create a web service which deploys to the _vti_bin

  1. Add a text file to the {SharePointRoot}\ISAPI mapped folder of your SharePoint project.
  2. Rename your text file to <ServiceName>.asmx. Now you have the service you now need to associate it to the code behind.
  3. Create a class and name it <ServiceName>.cs or .vb if you are that way inclined !!
  4. Add the following attributes to your class
       [WebService(Namespace = "/sharepoint/services/")]’>http://<yourdomain>/sharepoint/services/")]
       [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
       [System.ComponentModel.ToolboxItem(false)]
  5. Next, return to your asmx file created in step 2 and add the following to the top of the file
    <%@ WebService Language="C#" Class="<NameSpaceOfAssembly>.<NameOfServiceClass>, <NameSpaceOfAssembly>, Version=<VersionOfYourAssembly>, Culture=neutral, PublicKeyToken=<PublicKeyOfYourAssembly>" %>
    Note: If you don’t know the public key, build your project, open a Visual Studio command prompt and naviate to your debug folder. Then run the command sn –T <NameOfYourDll>.dll
  6. Next, you need to deploy your solution to get the asmx file into the ISAPI folder and your class into the GAC.
  7. Once deployed, navigate to the web service at <SharePointSite>_vti_bin/<PathIfAny>/<ServiceName>.asmx and you should see your service with any web method you have added.
  8. Next, you will need to create WSDL and DISCO files to allow your to add reference to the service from a project.
  9. For some reason you don’t seem to be able to do this from the ISAPI folder, you receive a file not found error seen below. image
    So,  you need to copy the deployed file from the ISAPI folder to the LAYOUTS folder.
    Then run the command from the Visual Studio command prompt, ran as Administrator

    VisualStudioCommandPrompt

    disco
    /_layouts/.asmx">http://<SiteCollectionUrl>/_layouts/<NameOfService>.asmx 

  10. Once you have successfully ran this for the instructions in the “Generating and Modifying Static Discovery and WSDL Files” section of the Creating a Custom ASP.NET Web Service page on MSDN. 
  11. Copy these newly create wsdl and disco files back into your project and redeploy.

Please note: This tedious process will have to be redone anytime you add a new web method to your service.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s