<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>Footprints in the snow of a warped mind - ASP.Net|Web Service</title>
    <link>http://blogs.thesitedoctor.co.uk/test/</link>
    <description>newtelligence powered</description>
    <language>en-us</language>
    <copyright>Tim</copyright>
    <lastBuildDate>Thu, 12 Aug 2010 08:32:44 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.3.9074.18820</generator>
    <managingEditor>timgaunt@gmail.com</managingEditor>
    <webMaster>timgaunt@gmail.com</webMaster>
    <item>
      <trackback:ping>http://blogs.thesitedoctor.co.uk/test/Trackback.aspx?guid=6a9ca083-94b9-4ba3-b7e6-d29948179db9</trackback:ping>
      <pingback:server>http://blogs.thesitedoctor.co.uk/test/pingback.aspx</pingback:server>
      <pingback:target>http://blogs.thesitedoctor.co.uk/test/PermaLink,guid,6a9ca083-94b9-4ba3-b7e6-d29948179db9.aspx</pingback:target>
      <dc:creator>Tim</dc:creator>
      <wfw:comment>http://blogs.thesitedoctor.co.uk/test/CommentView,guid,6a9ca083-94b9-4ba3-b7e6-d29948179db9.aspx</wfw:comment>
      <wfw:commentRss>http://blogs.thesitedoctor.co.uk/test/SyndicationService.asmx/GetEntryCommentsRss?guid=6a9ca083-94b9-4ba3-b7e6-d29948179db9</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Ever needed to take a large list and split it into smaller subsets of data for processing?
Well this is the Extension Method for you. Tonight we had to split a small dataset
(500 items) into even smaller sets of 10 so the provider’s web service wouldn’t timeout.
</p>
        <p>
Seeing as I was going to miss out on my evening, I thought I’d see if I could do it
a little differently using Linq and this is what I came up with:
</p>
        <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:edfa829e-a3df-4997-be7e-4316894bab44" class="wlWriterEditableSmartContent">
          <pre class="brush: c#;">/// &lt;summary&gt;
/// Simple method to chunk a source IEnumerable into smaller (more manageable) lists
/// &lt;/summary&gt;
/// &lt;param name="source"&gt;The large IEnumerable to split&lt;/param&gt;
/// &lt;param name="chunkSize"&gt;The maximum number of items each subset should contain&lt;/param&gt;
/// &lt;returns&gt;An IEnumerable of the original source IEnumerable in bite size chunks&lt;/returns&gt;
public static IEnumerable&lt;IEnumerable&lt;TSource&gt;&gt; ChunkData&lt;TSource&gt;(this IEnumerable&lt;TSource&gt; source, int chunkSize)
{
    for (int i = 0; i &lt; source.Count(); i += chunkSize)
        yield return source.Skip(i).Take(chunkSize);
} 
</pre>
        </div>
        <p>
It should extend any IEnumerable and allow you to split it into smaller chunks which
you can then process to your heart’s content.
</p>
        <p>
Here’s a quick example of it in use:
</p>
        <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:3f0bfd82-a5c2-45bf-9584-48811d7f8f46" class="wlWriterEditableSmartContent">
          <pre class="brush: c#;">var list = new List&lt;string&gt;() { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5", "Item 6", "Item 7", "Item 8", "Item 9", "Item 10" };
Console.WriteLine("Original list is {0} items", list.Count);
var chunked = list.ChunkData(3);
Console.WriteLine("Returned the data in {0} subsets", chunked.Count());
int i = 1;
foreach (var subset in chunked)
{
    Console.WriteLine("{0} items are in subset #{1}", subset.Count(), i++);
    int si = 1;
    foreach (var s in subset)
        Console.WriteLine("\t\tItem #{0}: {1}", si++, s);
}
</pre>
        </div>
        <p>
And this will output
</p>
        <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:b91a7f83-6305-4649-af61-23796d4215fd" class="wlWriterEditableSmartContent">
          <pre class="brush: text;">Original list is 10 items
Returned the data in 4 subsets
3 items are in subset #1
		Item #1: Item 1
		Item #2: Item 2
		Item #3: Item 3
3 items are in subset #2
		Item #1: Item 4
		Item #2: Item 5
		Item #3: Item 6
3 items are in subset #3
		Item #1: Item 7
		Item #2: Item 8
		Item #3: Item 9
1 items are in subset #4
		Item #1: Item 10
</pre>
        </div>
        <p>
2 lines of code to do all that work -Neat
</p>
        <img width="0" height="0" src="http://blogs.thesitedoctor.co.uk/test/aggbug.ashx?id=6a9ca083-94b9-4ba3-b7e6-d29948179db9" />
      </body>
      <title>Using Linq and Extension Methods to chunk large data sets</title>
      <guid isPermaLink="false">http://blogs.thesitedoctor.co.uk/test/PermaLink,guid,6a9ca083-94b9-4ba3-b7e6-d29948179db9.aspx</guid>
      <link>http://blogs.thesitedoctor.co.uk/test/2010/08/12/UsingLinqAndExtensionMethodsToChunkLargeDataSets.aspx</link>
      <pubDate>Thu, 12 Aug 2010 08:32:44 GMT</pubDate>
      <description>&lt;p&gt;
Ever needed to take a large list and split it into smaller subsets of data for processing?
Well this is the Extension Method for you. Tonight we had to split a small dataset
(500 items) into even smaller sets of 10 so the provider’s web service wouldn’t timeout.
&lt;/p&gt;
&lt;p&gt;
Seeing as I was going to miss out on my evening, I thought I’d see if I could do it
a little differently using Linq and this is what I came up with:
&lt;/p&gt;
&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:edfa829e-a3df-4997-be7e-4316894bab44" class="wlWriterEditableSmartContent"&gt;&lt;pre class="brush: c#;"&gt;/// &amp;lt;summary&amp;gt;
/// Simple method to chunk a source IEnumerable into smaller (more manageable) lists
/// &amp;lt;/summary&amp;gt;
/// &amp;lt;param name="source"&amp;gt;The large IEnumerable to split&amp;lt;/param&amp;gt;
/// &amp;lt;param name="chunkSize"&amp;gt;The maximum number of items each subset should contain&amp;lt;/param&amp;gt;
/// &amp;lt;returns&amp;gt;An IEnumerable of the original source IEnumerable in bite size chunks&amp;lt;/returns&amp;gt;
public static IEnumerable&amp;lt;IEnumerable&amp;lt;TSource&amp;gt;&amp;gt; ChunkData&amp;lt;TSource&amp;gt;(this IEnumerable&amp;lt;TSource&amp;gt; source, int chunkSize)
{
    for (int i = 0; i &amp;lt; source.Count(); i += chunkSize)
        yield return source.Skip(i).Take(chunkSize);
} 
&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;
It should extend any IEnumerable and allow you to split it into smaller chunks which
you can then process to your heart’s content.
&lt;/p&gt;
&lt;p&gt;
Here’s a quick example of it in use:
&lt;/p&gt;
&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:3f0bfd82-a5c2-45bf-9584-48811d7f8f46" class="wlWriterEditableSmartContent"&gt;&lt;pre class="brush: c#;"&gt;var list = new List&amp;lt;string&amp;gt;() { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5", "Item 6", "Item 7", "Item 8", "Item 9", "Item 10" };
Console.WriteLine("Original list is {0} items", list.Count);
var chunked = list.ChunkData(3);
Console.WriteLine("Returned the data in {0} subsets", chunked.Count());
int i = 1;
foreach (var subset in chunked)
{
    Console.WriteLine("{0} items are in subset #{1}", subset.Count(), i++);
    int si = 1;
    foreach (var s in subset)
        Console.WriteLine("\t\tItem #{0}: {1}", si++, s);
}
&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;
And this will output
&lt;/p&gt;
&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:b91a7f83-6305-4649-af61-23796d4215fd" class="wlWriterEditableSmartContent"&gt;&lt;pre class="brush: text;"&gt;Original list is 10 items
Returned the data in 4 subsets
3 items are in subset #1
		Item #1: Item 1
		Item #2: Item 2
		Item #3: Item 3
3 items are in subset #2
		Item #1: Item 4
		Item #2: Item 5
		Item #3: Item 6
3 items are in subset #3
		Item #1: Item 7
		Item #2: Item 8
		Item #3: Item 9
1 items are in subset #4
		Item #1: Item 10
&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;
2 lines of code to do all that work -Neat
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blogs.thesitedoctor.co.uk/test/aggbug.ashx?id=6a9ca083-94b9-4ba3-b7e6-d29948179db9" /&gt;</description>
      <comments>http://blogs.thesitedoctor.co.uk/test/CommentView,guid,6a9ca083-94b9-4ba3-b7e6-d29948179db9.aspx</comments>
      <category>ASP.Net</category>
      <category>ASP.Net/Web Service</category>
      <category>C#</category>
      <category>The Site Doctor</category>
      <category>Web Development</category>
    </item>
    <item>
      <trackback:ping>http://blogs.thesitedoctor.co.uk/test/Trackback.aspx?guid=cccc56c3-df32-4c82-be11-e029106f93f8</trackback:ping>
      <pingback:server>http://blogs.thesitedoctor.co.uk/test/pingback.aspx</pingback:server>
      <pingback:target>http://blogs.thesitedoctor.co.uk/test/PermaLink,guid,cccc56c3-df32-4c82-be11-e029106f93f8.aspx</pingback:target>
      <dc:creator>Tim</dc:creator>
      <wfw:comment>http://blogs.thesitedoctor.co.uk/test/CommentView,guid,cccc56c3-df32-4c82-be11-e029106f93f8.aspx</wfw:comment>
      <wfw:commentRss>http://blogs.thesitedoctor.co.uk/test/SyndicationService.asmx/GetEntryCommentsRss?guid=cccc56c3-df32-4c82-be11-e029106f93f8</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
We had an interesting problem the other day while integrating with a web service hosted
on an apache server. Every time we called the WSDL methods we could see a valid request
being sent and a valid response being returned (ok there were a few syntax errors
but nothing that would stop it converting) but despite this every time, without fail,
it would return null at code level.
</p>
        <p>
The solution was actually amazingly simple. In short, since our last flurry with web
services we've upgraded to Visual Studio 2008 and installed ReSharper (see below for
how that's relevant). In VS2008 they've sneakily added a new menu "Add Service
Reference" and although it's in the same menu location and a similar wording
etc does something different. If you add your WSDL reference this way it will more
than likely fail.
</p>
        <p>
To add a "Web Reference" in Visual Studio 2008 follow the instructions below and hopefully
you won't go down the same routes that I did trying to debug the XML...
</p>
        <p>
Click the "Add Service Reference" menu option (obviously!) 
</p>
        <p>
          <img height="93" src="http://blogs.sitedoc.co.uk/tim/img/VS2008AddServiceReference.png" width="242" />
        </p>
        <p>
The screen below should appear, instead of entering the address of the web service
into the address bar, click the advanced button at the bottom (highlighted)
</p>
        <p>
          <img height="508" src="http://blogs.sitedoc.co.uk/tim/img/AddServiceReference1.png" width="631" />
        </p>
        <p>
That'll then bring up the screen below, on which you need to click the "Add Web Reference"
button at the bottom.
</p>
        <p>
          <img height="601" src="http://blogs.sitedoc.co.uk/tim/img/AddServiceReference2.png" width="649" />
        </p>
        <p>
You should then be presented with the usual "Add Web Reference" screen (see below).
</p>
        <p>
          <img height="572" src="http://blogs.sitedoc.co.uk/tim/img/VS2008WebServiceReference.png" width="825" />
        </p>
        <p>
Why did I mention ReSharper? Well I've notice that as well as adding to the IDE they've
also updated some of the menu items, most noticeably "Go to Definition"
which is now "go to Declaration" (see below) so I figured this new menu
option was thanks to them.
</p>
        <p>
ReSharper: <img height="73" src="http://blogs.sitedoc.co.uk/tim/img/VS2008GoToDeclaration.png" width="195" /></p>
        <p>
Without ReSharper: <img height="71" alt="VS2008GoToDeclarationWithoutResharper.png" src="http://blogs.sitedoc.co.uk/tim/img/VS2008GoToDeclarationWithoutResharper.png" width="165" /></p>
        <p>
So the next time your WSDL is returning a null object even though a valid response
is being retrieved, check how you added it in Visual Studio,.
</p>
        <img width="0" height="0" src="http://blogs.thesitedoctor.co.uk/test/aggbug.ashx?id=cccc56c3-df32-4c82-be11-e029106f93f8" />
      </body>
      <title>WSDL returning a valid response but object is null</title>
      <guid isPermaLink="false">http://blogs.thesitedoctor.co.uk/test/PermaLink,guid,cccc56c3-df32-4c82-be11-e029106f93f8.aspx</guid>
      <link>http://blogs.thesitedoctor.co.uk/test/2008/11/01/WSDLReturningAValidResponseButObjectIsNull.aspx</link>
      <pubDate>Sat, 01 Nov 2008 18:28:49 GMT</pubDate>
      <description>&lt;p&gt;
We had an interesting problem the other day while integrating with a web service hosted
on an apache server. Every time we called the WSDL methods we could see a valid request
being sent and a valid response being returned (ok there were a few syntax errors
but nothing that would stop it converting) but despite this every time, without fail,
it would return null at code level.
&lt;/p&gt;
&lt;p&gt;
The solution was actually amazingly simple. In short, since our last flurry with web
services we've upgraded to Visual Studio 2008 and installed ReSharper (see below for
how that's relevant). In VS2008 they've sneakily added a new menu &amp;quot;Add Service
Reference&amp;quot; and although it's in the same menu location and a similar wording
etc does something different. If you add your WSDL reference this way it will more
than likely fail.
&lt;/p&gt;
&lt;p&gt;
To add a "Web Reference" in Visual Studio 2008 follow the instructions below and hopefully
you won't go down the same routes that I did trying to debug the XML...
&lt;/p&gt;
&lt;p&gt;
Click the "Add Service Reference" menu option (obviously!) 
&lt;/p&gt;
&lt;p&gt;
&lt;img height="93" src="http://blogs.sitedoc.co.uk/tim/img/VS2008AddServiceReference.png" width="242" /&gt;
&lt;/p&gt;
&lt;p&gt;
The screen below should appear, instead of entering the address of the web service
into the address bar, click the advanced button at the bottom (highlighted)
&lt;/p&gt;
&lt;p&gt;
&lt;img height="508" src="http://blogs.sitedoc.co.uk/tim/img/AddServiceReference1.png" width="631" /&gt;
&lt;/p&gt;
&lt;p&gt;
That'll then bring up the screen below, on which you need to click the "Add Web Reference"
button at the bottom.
&lt;/p&gt;
&lt;p&gt;
&lt;img height="601" src="http://blogs.sitedoc.co.uk/tim/img/AddServiceReference2.png" width="649" /&gt;
&lt;/p&gt;
&lt;p&gt;
You should then be presented with the usual "Add Web Reference" screen (see below).
&lt;/p&gt;
&lt;p&gt;
&lt;img height="572" src="http://blogs.sitedoc.co.uk/tim/img/VS2008WebServiceReference.png" width="825" /&gt;
&lt;/p&gt;
&lt;p&gt;
Why did I mention ReSharper? Well I've notice that as well as adding to the IDE they've
also updated some of the menu items, most noticeably &amp;quot;Go to Definition&amp;quot;
which is now &amp;quot;go to Declaration&amp;quot; (see below) so I figured this new menu
option was thanks to them.
&lt;/p&gt;
&lt;p&gt;
ReSharper: &lt;img height="73" src="http://blogs.sitedoc.co.uk/tim/img/VS2008GoToDeclaration.png" width="195" /&gt;
&lt;/p&gt;
&lt;p&gt;
Without ReSharper: &lt;img height="71" alt="VS2008GoToDeclarationWithoutResharper.png" src="http://blogs.sitedoc.co.uk/tim/img/VS2008GoToDeclarationWithoutResharper.png" width="165" /&gt;
&lt;/p&gt;
&lt;p&gt;
So the next time your WSDL is returning a null object even though a valid response
is being retrieved, check how you added it in Visual Studio,.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blogs.thesitedoctor.co.uk/test/aggbug.ashx?id=cccc56c3-df32-4c82-be11-e029106f93f8" /&gt;</description>
      <comments>http://blogs.thesitedoctor.co.uk/test/CommentView,guid,cccc56c3-df32-4c82-be11-e029106f93f8.aspx</comments>
      <category>ASP.Net</category>
      <category>ASP.Net/Web Service</category>
      <category>ASP.Net/WSDL</category>
      <category>C#</category>
      <category>Software/Visual Studio</category>
      <category>The Site Doctor</category>
      <category>WebDD</category>
    </item>
  </channel>
</rss>