Home > development, Sharepoint > Error When talking to SharePoint Web Services in code

Error When talking to SharePoint Web Services in code

January 4th, 2012

I’ve been trying to talk to SharePoint’s web services in C# for a couple of hours now. Something I do in JS all the time, but rarely in a clients C# app.

I’ve been getting the same error over and over again, but keep getting an error when trying to do anything.

Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).

I had dutifully copied the example code from the MSDN site and got a web reference to the Lists Web Service of course

and commented out the URL code in the example because that points at their site, not mine, which is pointed to by my web reference.

/*Set the Url property of the service for the path to a subsite.*/ listService.Url = http://MyServer/sites/MySiteCollection/_vti_bin/Lists.asmx;

WRONG!!!!!

If you are getting this error then it is because you commented out the URL.

When you add a web reference you are adding a WSDL file which is then compiled.  The WSDL is not specific to your site location,

if you open up the WSDL XML the section right at the bottom is pointing to elsewhere, the root of the WebApplciation not the RootWeb / Site you are interested in.

<wsdl:service name="Lists">     <wsdl:port name="ListsSoap" binding="tns:ListsSoap">       <soap:address location="http://my.binaryjam.com/_vti_bin/lists.asmx" />     </wsdl:port>     <wsdl:port name="ListsSoap12" binding="tns:ListsSoap12">       <soap12:address location="http://my.binaryjam.com/_vti_bin/lists.asmx" />     </wsdl:port>
</wsdl:service>

You need that line in the code that sets the listService.Url value, without it you are going to go mad trying to track down this bug, cos I didn’t find the answer online, I had to use fiddler.  Of course this article will now exist. :-)

 

Categories: development, Sharepoint Tags:
  1. April 25th, 2012 at 12:13 | #1

    I’ve noticed that you also use SPServices. What I’ve done in the past was run my SPServices call, but put a break point right before the ajax request. You can then log the SOAP envelope to the console.

    Makes your life easy…

    Cheers,
    Matt

Comments are closed.