1
votes

I'm having a difficult time implementing a web service client. I'm querying a SharePoint 2010 web service using a web reference. The code below throws an exception on the line within the try block.

SoapService.Lists service = new SoapService.Lists();
service.Credentials = CredentialCache.DefaultCredentials;
XmlDocument doc = new XmlDocument();
XmlNode query = doc.CreateNode(XmlNodeType.Element,"Query","");
XmlNode viewFields = doc.CreateNode(XmlNodeType.Element,"ViewFields","");
XmlNode queryOptions = doc.CreateNode(XmlNodeType.Element,"QueryOptions","");
query.InnerXml = @"<Where><IsNotNull><FieldRef Name='Vendor Name'/></IsNotNull></Where>";
viewFields.InnerXml = @"<FieldRef Name='Vendor Name'/>";
queryOptions.InnerXml = @"<QueryOptions/>";

try
{
    XmlNode response = service.GetListItems("DLA-Suppliers", null, query, viewFields, null, queryOptions, null); // exception thrown
}
catch (System.Web.Services.Protocols.SoapException e)
{
    Console.WriteLine(e.Message);
    Console.WriteLine(e.Detail);
    Console.WriteLine(e.StackTrace);
}

Here is the exception (SoapServerException) stack trace:

at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)
at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
at DLAUpdateSP.SoapService.Lists.GetListItems(String listName, String viewName, XmlNode query, XmlNode viewFields, String rowLimit, XmlNode queryOptions, String webID) in c:\users\user\documents\visual studio 2010\Projects\DLAUpdateSP\Web References\SoapService\Reference.cs:line 455
at DLAUpdateSP.Program.UpdateSuppliers(String fileLocation) in C:\Users\user\Documents\Visual Studio 2010\Projects\DLAUpdateSP\Program.cs:line 58

Does anyone have any ideas on this? Aside from the stack trace, the exception's properties were almost all null. I've never done SOAP before so this is really new to me. Any help is really appreciated.

3

3 Answers

1
votes
query.InnerXml = @"<Where><IsNotNull><FieldRef Name='Vendor Name'/></IsNotNull></Where>";
viewFields.InnerXml = @"<FieldRef Name='Vendor Name'/>";

The issue is your FieldRef Name. I had the same issue and solved it using the internal name which can be found in your List browser URL. Probably VendorName (without space).

Correct your code as follows

    SoapService.Lists service = new SoapService.Lists();
    service.Credentials = CredentialCache.DefaultCredentials;
    XmlDocument doc = new XmlDocument();
    XmlNode query = doc.CreateNode(XmlNodeType.Element,"Query","");
    XmlNode viewFields = doc.CreateNode(XmlNodeType.Element,"ViewFields","");
    XmlNode queryOptions = doc.CreateNode(XmlNodeType.Element,"QueryOptions","");
    query.InnerXml = @"<Where><IsNotNull><FieldRef Name='VendorName'/></IsNotNull>          </Where>";
    viewFields.InnerXml = @"<FieldRef Name='VendorName'/>";
    queryOptions.InnerXml = @"<QueryOptions/>";

    try
    {
    XmlNode response = service.GetListItems("DLA-Suppliers", null, query, viewFields,  null,  queryOptions, null); // exception thrown
    }
    catch (System.Web.Services.Protocols.SoapException e)
    {
    Console.WriteLine(e.Message);
    Console.WriteLine(e.Detail);
    Console.WriteLine(e.StackTrace);
    }
0
votes

I'd have to see more of the code to get a better idea of which methods are yours and such, but at first glance I can see that you are passing in a few nulls into the service's GetListItems method. While this may be completely innocent, I'd have a look at the service's code/documentation if you can access it and see if it is expecting actual values instead of null.

As a side note, if you are the one who created the service, I would try to make it in a way that I wouldn't have to manually build XML queries. I would try to make a WCF service that provides methods to accomplish what you want with minimal headaches.

0
votes

On second thoughs, you may be suffering because of the where clause. I.e. the fieldname is almost guaranteed not to work with a space. (The FieldRef Name attribute requires the Internal Name of the field)

Get a copy of SharePoint Caml Query Helper this will allow you to make sure the values are correct and data will be returned.