Wednesday, August 18, 2010

SharePoint Web Services in Visual Studio 2010

When you want to add a reference to your SharePoint 2010 web services, you might be confused by the “Add Service Reference” option in Visual Studio 2010. If you choose this option, everything will seem to generate fine, but you won’t end up with what you want.

To use the SharePoint 2010 (or MOSS) web services in VS 2010, you should choose Add Service Reference, but don’t enter the URL into the address box. Instead, click the Advanced button at the bottom.

image 

Once you get to the Service Reference Settings dialog, click Add Web Reference at the bottom. This will open the familiar Web Reference dialog that you would have used in Visual Studio 2005.

image

With the good ‘ol Add Web Reference dialog open, you can feel free to enter the URL of your web services (e.g., http://servername/_vti_bin/Webs.asmx). Now you can use the same code you had previously used to leverage SharePoint web services in your applications.

image

Update: If you right-click on Web References, and choose Add Web Reference you can get to this option right away. However, you may need to create one the other way to get the Web Reference folder to appear.

If you do try to add a service reference to the SharePoint web services (e.g., http://servername/_vti_adm/Webs.asmx), you may see this error message:

There was an error downloading 'http://servername/_vti_adm/Webs.asmx'.
The request failed with the error message:
<html><head>
<title>The file you are attempting to save or retrieve has been blocked from this Web site by the server administrators.<nativehr>0x800401e6</nativehr>

3 comments:

Benbo Farkern said...

I get "The file you are attempting to save or retrieve has been blocked " by either method...

Stephen Cawood said...

Benbo, which version of Visual Studio and SharePoint are you using?

Anonymous said...

Thanks a lot cawood.. this made my day indeed! :)