Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 25064

Web Service Performance VS Object Model

$
0
0

I wrote code to pull data from a SharePoint list using the SharePoint API and the SharePoint web service. I compared the performance of the code and the web service was around five times faster. I hit the same list with the same CAML query and made sure all results were returned each time. I was a little surprised. Is there a more efficient way to right my API code? Why would the web service be so much more efficient?

My API code looks like this.

using

(SPSite site = new SPSite(url))

{

   

using (SPWeb web = site.OpenWeb())

    {

        SPList list = web.Lists[listName];

        SPQuery query =

new SPQuery();

        query.Query = listQuery;

        query.ViewFields = listQueryView;

        SPListItemCollection items = list.GetItems(query);

        itemCount = items.Count;

       

       

foreach (SPListItem item in items)

        {

           

string title = GetValue(item["Title"]);

        }

    }

}

My web service code looks like this:

Lists listsService =

new Lists();

listsService.Url = url;

listsService.UseDefaultCredentials =

true;

XmlNode resultsNode = listsService.GetListItems(listName,

string.Empty, queryNode, queryViewNode,"400", queryOptionsNode, null);

XmlNodeReader resultsNodeReader =

new XmlNodeReader(resultsNode);


int

itemCount = 0;


while

(resultsNodeReader.Read())

{

   

string title = resultsNodeReader["ows_Title"];

}

Thanks,

Mike


Viewing all articles
Browse latest Browse all 25064

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>