Why won't InfoPath work with SharePoint Web Services? It comes down to the fact that InfoPath doesn't recognize that some web services, such as Lists.asmx's GetListItems requires strings (which InfoPath handles just fine) and XmlNodes (which InfoPath can't seem to figure out). If you try to use this web service as a data connection, you'll get error messages, such as "Root Element is Missing" or, if you try to add some XML code to one of the fields, you'll get "Element <Query> of parameter query is missing or invalid."
The solution? Create a Proxy Web Service that takes in strings representing the Xml code and create XmlNodes from them.
Here's the code to create such as proxy:
public XmlNode GetListItems(string listName, string viewID, string query, string viewFields, string rowLimit, string queryOptions, string webID)
// Create an instance of the SharePoint Lists Web Service
ListsWebService.Lists listService = GetListsServiceClient();
// Create the XmlNodes from the given innerXml strings
XmlNode queryElement = CreateNode("Query", query);
XmlNode viewFieldsElement = CreateNode("ViewFields", viewFields);
XmlNode queryOptionsElement = CreateNode("QueryOptions", queryOptions);
// Execute the SharePoint Lists Web Service
return listService.GetListItems(listName, viewID, queryElement, viewFieldsElement, rowLimit, queryOptionsElement, webID);
private ListsWebService.Lists GetListsServiceClient()
ListsWebService.Lists listService = new ListsWebService.Lists();
listService.Credentials = System.Net.CredentialCache.DefaultCredentials;
listService.Url = SPContext.Current.Web.Url + "/_vti_bin/Lists.asmx";
private XmlNode CreateNode(string name, string innerXml)
XmlDocument xmlDoc = new XmlDocument();
XmlNode element = xmlDoc.CreateElement(name);
element.InnerXml = innerXml;
Just create a new web service with this information and follow the instructions on the proper deployment procedures in the WSS 3.0 SDK article Walkthrough: Creating a Custom Web Service. The facade method above has essentially the same method signature as the Lists.asmx web service, except that instead of XmlNode being the input types, strings are the input types.