Web Service SOAP QueryListEx SharePoint 2010 - InfoPath Dev
in

InfoPath Dev

Web Service SOAP QueryListEx SharePoint 2010

Last post 09-18-2012 11:13 AM by stefanjohn010. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 07-12-2012 08:11 AM

    Web Service SOAP QueryListEx SharePoint 2010

    A few years back we hired a consultant to setup a web service on our WSS 3.0 site. We are now moving\upgrading our site to SharePoint 2010. I have successful moved this WSDL web service over to the new server but I am having difficulty connecting it to a list. I can get HelloWorld and getListGuid to work properly but I get an error message when i try QueryListEx and QuerySortEx.

    Here is the error. Any help would be appreciated.

    System.Xml.XmlException: Data at the root level is invalid. Line 1, position 1.
       at System.Xml.XmlTextReaderImpl.Throw(Exception e)
       at System.Xml.XmlTextReaderImpl.ParseRootLevelWhitespace()
       at System.Xml.XmlTextReaderImpl.ParseDocumentContent()
       at System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace)
       at System.Xml.XmlDocument.Load(XmlReader reader)
       at System.Xml.XmlDocument.LoadXml(String xml)
       at Service.QuerySortEx(String siteUrl, String listName, String orderBy) in c:\inetpub\wwwroot\RFCService\App_Code\Service.cs:line 218

  • 07-12-2012 11:12 AM In reply to

    Re: Web Service SOAP QueryListEx SharePoint 2010

    Thought the code would be helpfull.  Line 218 is myDoc.LoadXml(ex.ToString());

    using System;
    using System.Web;
    using System.Web.Services;
    using System.Web.Services.Protocols;
    using System.Xml;
    using System.Data;
    using System.Collections;
    using System.ComponentModel;
    using listQuery;
    using lists;
    using ListsService;


    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class Service : System.Web.Services.WebService
    {
        public Service () {

            //Uncomment the following line if using designed components
            //InitializeComponent();
        }

        [WebMethod]
        public string HelloWorld() {
            return "Test if WebServices are set up correctly";
        }


          
            [WebMethod]
            public string getListGuid(string siteUrl,string fullName)
            {

                lists.Lists SPList = new lists.Lists();
                SPList.Credentials = System.Net.CredentialCache.DefaultCredentials;
                SPList.Url = siteUrl + "/_vti_bin/lists.asmx";
                string resultGuid="";
                XmlNode nodeRes = SPList.GetList(fullName);
            

                try
                {
                    if (nodeRes != null)
                    {

                        resultGuid=nodeRes.Attributes["ID"].Value;
                        return resultGuid;

                    }
                    else
                    {
                        return null;
                    }
                }
                catch (Exception e)
                {
                    return e.InnerException.ToString() + e.StackTrace.ToString();
                }
            }

            // ============================================================================
            // QueryListEx - Returns List sorted by order by field  given site and listname
            // ============================================================================
            [WebMethod]
            public XmlDocument QueryListEx(string siteUrl, string listName, string orderBy, string fieldFilter)
            {
                //bool extractRows = true;
                int rowLimit = 500;
                //orderBy = "Title";
                //where = "";
                //fields = "<Fields><Field Name=’ID’/><Field Name=’Title’/></Fields>";

                //Get the Guid of the list using the WebMethod
                string listGuid = getListGuid(siteUrl, listName);

                //Initialize STSAdapter credentials and URL
                listQuery.StsAdapter myStsAd = new listQuery.StsAdapter();
                myStsAd.Credentials = System.Net.CredentialCache.DefaultCredentials;
                myStsAd.Url = siteUrl + "/_vti_bin/dspsts.asmx";

                //These are required fields that need to be set for the service
                string[] vArray = new string[1];
                vArray[0] = "1.0";
                listQuery.Versions myVersion = new listQuery.Versions();
                myVersion.version = vArray;
                myStsAd.versions = myVersion;

                //A QueryRequest and SPQuery are required
                DSQuery sQuery = new listQuery.DSQuery();
                sQuery.select = "/list[@id='" + listGuid + "']";

                QueryRequest myRequest = new QueryRequest();
                myRequest.dsQuery = sQuery;
                DspQuery spQuery = new DspQuery();
                XmlDocument xmlDoc = new System.Xml.XmlDocument();
                XmlElement ndQuery = xmlDoc.CreateElement("Eq");
                string k = "<FieldRef Name=\"" + orderBy + "\"/><Value>" + fieldFilter + "</Value>";
                ndQuery.InnerXml = k;
                sQuery.resultContent = ResultContentType.dataOnly;
               

                sQuery.Query = spQuery;
                spQuery.Where = ndQuery;
                spQuery.RowLimit = rowLimit;
                myRequest.dsQuery.Query = spQuery;

                //The ascending order is specified here.
                OrderField order = new OrderField();
                order.Direction = OrderDirection.ASC;
                order.Name = orderBy;
                spQuery.OrderBy = new OrderField[] { order };

                //Setting a header is required for the query to work
                listQuery.RequestHeader reqHeader = new listQuery.RequestHeader();
                reqHeader.document = listQuery.DocumentType.content;
                reqHeader.method = listQuery.MethodType.query;
                myStsAd.request = reqHeader;


                //Return the entire list as an XML document
                XmlDocument myDoc = new XmlDocument();
                try
                {
                    XmlNodeList myNode = myStsAd.Query(myRequest).ChildNodes;
                    string iXml = myStsAd.Query(myRequest).InnerXml.ToString();
                    myDoc.LoadXml(iXml);
                    return myDoc;

                }

                catch (System.Web.Services.Protocols.SoapException ex)
                {

                    myDoc.LoadXml(ex.ToString());

                    return myDoc;
                }


            }

            // ============================================================================
         //QuerySortEx - Returns List sorted by order by field  given site and listname
        // ============================================================================
           [WebMethod]
            public XmlDocument QuerySortEx(string siteUrl,string listName,string orderBy)
            {
                //bool extractRows = true;
                int rowLimit = 5000;
                //orderBy = "Title";
                //where = "";
                //fields = "<Fields><Field Name=’ID’/><Field Name=’Title’/></Fields>";

                //Get the Guid of the list using the WebMethod
                string listGuid = getListGuid(siteUrl, listName);

                //Initialize STSAdapter credentials and URL
                listQuery.StsAdapter myStsAd = new listQuery.StsAdapter();
                myStsAd.Credentials = System.Net.CredentialCache.DefaultCredentials;
                myStsAd.Url = siteUrl + "/_vti_bin/dspsts.asmx";

                //These are required fields that need to be set for the service
                string[] vArray = new string[1];
                vArray[0] = "1.0";
                listQuery.Versions myVersion = new listQuery.Versions();
                myVersion.version = vArray;
                myStsAd.versions = myVersion;

                //A QueryRequest and SPQuery are required
                DSQuery sQuery = new listQuery.DSQuery();
                sQuery.select = "/list[@id='" + listGuid + "']";

                QueryRequest myRequest = new QueryRequest();
                myRequest.dsQuery = sQuery;
                DspQuery spQuery = new DspQuery();
                XmlDocument xmlDoc = new System.Xml.XmlDocument();
                //XmlElement ndQuery = xmlDoc.CreateElement("Eq");
                //string k = "<FieldRef Name=\"" + orderBy + "\"/><Value>" + "A" + "</Value>";
                //ndQuery.InnerXml = k;
                sQuery.resultContent = ResultContentType.dataOnly;


                sQuery.Query = spQuery;
                //spQuery.Where = ndQuery;
                spQuery.RowLimit = rowLimit;
                myRequest.dsQuery.Query = spQuery;

                //The ascending order is specified here.
                OrderField order = new OrderField();
                order.Direction = OrderDirection.ASC;
                order.Name = orderBy;
                spQuery.OrderBy = new OrderField[] { order };

                //Setting a header is required for the query to work
                listQuery.RequestHeader reqHeader = new listQuery.RequestHeader();
                reqHeader.document = listQuery.DocumentType.content;
                reqHeader.method = listQuery.MethodType.query;
                myStsAd.request = reqHeader;


                //Return the entire list as an XML document
                XmlDocument myDoc = new XmlDocument();
                try
                {
                    XmlNodeList myNode = myStsAd.Query(myRequest).ChildNodes;
                    string iXml = myStsAd.Query(myRequest).InnerXml.ToString();
                    myDoc.LoadXml(iXml);
                    return myDoc;

                }

                catch (System.Web.Services.Protocols.SoapException ex)
                {

                    myDoc.LoadXml(ex.ToString());

                    return myDoc;
                }


            }


          
    }

  • 09-18-2012 11:13 AM In reply to

    Re: Web Service SOAP QueryListEx SharePoint 2010

    [WebMethod] public string getListGuid(string siteUrl,string fullName) { lists.Lists SPList = new lists.Lists(); SPList.Credentials = System.Net.CredentialCache.DefaultCredentials; SPList.Url = siteUrl + "/_vti_bin/lists.asmx"; string resultGuid=""; XmlNode nodeRes = SPList.GetList(fullName); try { if (nodeRes != null) Refraction Aids
Page 1 of 1 (3 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.