Calling a SharePoint web service with C#

Jen53403

Guest
Jan 17, 2008
10
0
0
I'm trying to write a little C# Windows app in Visual Studio that will call a web service procedure from a SharePoint site. I have no experience with this.

After reading this tutorial I wrote the following code. I assume it's supposed to return a list of the documents on the site in xNode.Attributes, but it returns zero for xNodes.Attributes.Count.

WebSite site = new WebSite();
Lists.Lists listsWebService = new Lists.Lists();
listsWebService.Url = "http://some sharepoint site url/_vti_bin/lists.asmx";
NetworkCredential creds = new NetworkCredential();
creds .Domain = "some domain";
creds .UserName = "some username";
creds .Password = "some password";
listsWebService.Credentials = creds ;
XmlNode xNodes = listsWebService.GetListCollection();
listBox1.Items.Add(xNodes.Attributes.Count);
label1.Text = "complete";

Did I assign the URL correctly? Where is the list of documents? Is there something else I'm missing?

Thanks to anyone who can help!
 

Markbnj

Elite Member <br>Moderator Emeritus
Moderator
Sep 16, 2005
15,682
14
81
www.markbetz.net
Looks like this one slipped through the cracks. I'd take another look at that code. You'll only get attributes back for things that are actually attributes.

<element attr1="1" attr2="2" attr3="3">
<child1></child1>
</element>

In the above example attr1, attr2, and attr3 are attributes, while child1 is a child element. You should confirm the structure of the XML you're expecting to get back, and see if what you have is attributes or child nodes.
 

Jen53403

Guest
Jan 17, 2008
10
0
0
Thanks for the reply. Is there an attribute of xNodes or something that contains the raw Xml returned by the web service? Then I can see what the structure is and fix my code to match.
 

Markbnj

Elite Member <br>Moderator Emeritus
Moderator
Sep 16, 2005
15,682
14
81
www.markbetz.net
Yes, check the InnerXml property of the top-level node, it will contain the raw text enclosed by that element.
 

Jen53403

Guest
Jan 17, 2008
10
0
0
Great! Thanks very much for your help. I now see that I needed to be looking for children instead of attributes.