• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Calling a SharePoint web service with C#

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!
 
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.
 
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.
 
Yes, check the InnerXml property of the top-level node, it will contain the raw text enclosed by that element.
 
Back
Top