views:

190

answers:

1

I'm trying to learn to call SharePoint Web Services from an external C# client. I'm using MOSS 2007 and VS 2008. There are lots of examples on the web of doing so, but most of them seem to be using a different form of each of the Web Service APIs than what I'm seeing in Visual Studio. My question is...what up wit dat?

When, for example, I launch Visual Studio 2008, create a new C# Console Application project, and then do a "Add Service Reference..." to add a reference to "http://myspserver/_vti_bin/Lists.asmx", the resulting namespace (with whatever name I chose to give it) contains the classes ListsSoap, ListsSoapChannel, and ListsSoapClient but no Lists class.

But many of the examples I see expect there to be a Lists class in that namespace. I keep seeing code like this:

sharepoint.lists.Lists l = new sharepoint.lists.Lists();
System.Net.NetworkCredential cred = new System.Net.NetworkCredential("your username here", "your password here");
l.Credentials = cred;
XmlNode n = l.GetListItems("your calendar name here", null, null, null, null, null, null);

This code doesn't compile for me. I wouldn't expect it to as browsing the binding to the Lists service ("sharepoint.lists" in this case) shows me these other classes I mention above but no Lists class.

And it doesn't work to replace the use of Lists() with one of the other classes, like ListsClient(). If I do that, I have problems later on. For example, the ListsClient object has no "Credentials" property, but rather a "ClientCredentials" property.

It's almost as if I'm using an older or newer form of the APIs, but I'm using MOSS 2007 (WSS 3.0) and the examples I'm seeing say they're written against the same SP versions.

What am I missing or doing wrong here? Where does this Lists class come from?

Humble TIA for any help.

PS: The code above comes from here: http://geekswithblogs.net/mcassell/archive/2007/08/22/Accessing-Sharepoint-Data-through-Web-Services.aspx

+2  A: 

"Add Service Reference" uses WCF, and what you see are the expected results of compiling the WSDL. Read up more on Windows Communication Foundation to find out how to use those classes.

If you want to generate a Lists class (more common as you've found out), use the "Add Web Reference" dialogs instead - these use the System.Web.Services classes, not WCF.

-Oisin

x0n
Thanks Oisin! That makes sense. I knew it would be something like that. Only one problem...I can't find the "Add Web Reference dialogs" :( My only choices are "Add Reference" and "Add Service Reference", and "Add Reference" does not seem to do it.
Steve
Found it by doing some Googling. It's kinda round-about. You have to add the first Web Service reference by going into the "Add Service Reference", click "Advanced" and then click "Add Web Reference...". This will let you add a classic Web Services version of the service.Once you've done this with one web service, the "Add Web Reference" choice will show up on the context menus where "Add Reference" shows up. Strange.
Steve
Just confirmed your answer by successfully using Lists() and Webs()!!!Thanks so much Oisin!
Steve