<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://codebetter.com/utility/FeedStylesheets/atom.xsl" media="screen"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en"><title type="html">Peter&amp;#39;s Gekko </title><subtitle type="html">public Blog MyNotepad : Imho
{
}</subtitle><id>http://codebetter.com/blogs/peter.van.ooijen/atom.aspx</id><link rel="alternate" type="text/html" href="http://codebetter.com/blogs/peter.van.ooijen/default.aspx" /><link rel="self" type="application/atom+xml" href="http://codebetter.com/blogs/peter.van.ooijen/atom.aspx" /><generator uri="http://communityserver.org" version="4.1.31106.3070">Community Server</generator><updated>2008-11-13T08:53:09Z</updated><entry><title>Reporting against a domain model</title><link rel="alternate" type="text/html" href="/blogs/peter.van.ooijen/archive/2009/07/01/reporting-against-a-domain-model.aspx" /><id>/blogs/peter.van.ooijen/archive/2009/07/01/reporting-against-a-domain-model.aspx</id><published>2009-07-01T08:44:00Z</published><updated>2009-07-01T08:44:00Z</updated><content type="html">&lt;p&gt;I have a love it /hate it relationship with reports. In many an application the reports are the main output. They are the prints which get filed or the invoices which have to ensure the ROI of the application. A good looking output rich with information does increase customer satisfaction. The downside is that fine tuning a report is tedious and requires quite different skills than coding. Building a system with a lot of reports can be pretty boring. So the tools better be good. &lt;a href="http://codebetter.com/blogs/peter.van.ooijen/archive/2005/07/21/129605.aspx"&gt;Switching from Crystal Reports to sql server&amp;nbsp; reporting services&lt;/a&gt; (RS) was quite a relief. &lt;/p&gt;
&lt;p&gt;But&amp;nbsp; RS still has two drawbacks. First is that it accesses data using plain sql. My application is built around a domain model using nHibernate to hide all db details. The domain model includes calculated properties which are to be included in the report. The calculations are done in the domain object. It would be repetitive and prone to error to repeat them in sql or reporting expressions. It would be quite a relief to report straight from the domain model itself. &lt;/p&gt;
&lt;p&gt;The other drawback is that RS requires an ms sql server instance with installed reporting services. The actual data is just a sqlexpress instance and I don&amp;rsquo;t want to set up a full blown reporting services server.&lt;/p&gt;
&lt;p&gt;New in Visual Studio 2005 were client side reports (rdlc&amp;rsquo;s). They are very much like RS reports (rdl&amp;rsquo;s) but can work with any data source and don&amp;rsquo;t require a sql reporting server instance. To include these reports in an app two client side report viewers are include in the .NET framework, one for WinForms and one for asp.net. This looked like the best of both worlds so I decided to give the winforms version a try. &lt;/p&gt;
&lt;p&gt;For a good overview on the reports check the &lt;a href="http://www.gotreportviewer.com/"&gt;got reportviewer&lt;/a&gt; site. In name it supports VS 2008, but (some of ?) the samples are based on VS 2005. Moving to 2008 there has been a change in the namespace for the classes, after fixing the reference the samples run in VS 2008. How to work with a non sql datasource is covered but not that clear. Here I will describe my minimalistic approach to work with a domain model fed by nHibernate.&lt;/p&gt;
&lt;h3&gt;The domain model&lt;/h3&gt;
&lt;p&gt;The intent of the application is to print invoices. This class diagram describes the model&lt;/p&gt;
&lt;p&gt;&lt;a href="http://codebetter.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/peter.van.ooijen/Rep1_5F00_709A0A5B.png"&gt;&lt;img height="575" width="490" src="http://codebetter.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/peter.van.ooijen/Rep1_5F00_thumb_5F00_0E981850.png" alt="Rep1" border="0" title="Rep1" style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;An invoice is for a contact, has a number of lines and an enumerated property. That is a number of values which contain a tax rate and have a clear name describing this value. Which gives the model additional value, something which would get lost when viewing the data as raw db data. An invoice has a reference to a contact and many Invoice lines. The (&lt;a href="http://wiki.fluentnhibernate.org/show/HomePage"&gt;fluent&lt;/a&gt;) nHibernate mappings express this.&lt;/p&gt;
&lt;div style="font-family:consolas;background:white;color:black;font-size:10pt;"&gt;
&lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;InvoiceMap&lt;/span&gt; : &lt;span style="color:#2b91af;"&gt;ClassMap&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af;"&gt;Invoice&lt;/span&gt;&amp;gt;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;{&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:blue;"&gt;public&lt;/span&gt; InvoiceMap()&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; WithTable(&lt;span style="color:#a31515;"&gt;&amp;quot;Factuur&amp;quot;&lt;/span&gt;);&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Id(x =&amp;gt; x.Id);&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Map(x =&amp;gt; x.Number).ColumnName(&lt;span style="color:#a31515;"&gt;&amp;quot;Nummer&amp;quot;&lt;/span&gt;);&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Map(x =&amp;gt; x.OnDate).ColumnName(&lt;span style="color:#a31515;"&gt;&amp;quot;Dedato&amp;quot;&lt;/span&gt;);&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Map(x =&amp;gt; x.BtwPercentage).CustomTypeIs&amp;lt;&lt;span style="color:#2b91af;"&gt;BtwPercentage&lt;/span&gt;&amp;gt;();&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Map(x =&amp;gt; x.Description).ColumnName(&lt;span style="color:#a31515;"&gt;&amp;quot;Inleiding&amp;quot;&lt;/span&gt;);&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; HasMany(x =&amp;gt; x.Lines).KeyColumnNames.Add(&lt;span style="color:#a31515;"&gt;&amp;quot;idFactuur&amp;quot;&lt;/span&gt;).Cascade.All();&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; References(x =&amp;gt; x.ForContact).ColumnName(&lt;span style="color:#a31515;"&gt;&amp;quot;idRelatie&amp;quot;&lt;/span&gt;);&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Map(x =&amp;gt; x.PrintIt).ColumnName(&lt;span style="color:#a31515;"&gt;&amp;quot;Printen&amp;quot;&lt;/span&gt;);&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;
&lt;p style="margin:0px;"&gt;}&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;So we have a &lt;em&gt;customtype&lt;/em&gt;, a &lt;em&gt;hasmany &lt;/em&gt;and a &lt;em&gt;references&lt;/em&gt;. Let&amp;rsquo;s see how these are used in the report.&lt;/p&gt;
&lt;h3&gt;The report&lt;/h3&gt;
&lt;p&gt;There are several ways to include a report in an application. The default when adding&amp;nbsp; a new report (Add &amp;ndash;&amp;gt; New Item &amp;ndash;&amp;gt; Reporting &amp;ndash;&amp;gt; report) is embedded. Which is clear and easy in deployment. When you need more flexibility you can switch to rdlc file or (back to) server side report.&lt;/p&gt;
&lt;p&gt;The report needs a datasource. It will accept any datasource including an object datasource. &lt;/p&gt;
&lt;p&gt;Add a new object datasource to the project and pick the Invoice domain object. &lt;/p&gt;
&lt;p&gt;&lt;a href="http://codebetter.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/peter.van.ooijen/Rep2_5F00_320496E8.png"&gt;&lt;img height="355" width="462" src="http://codebetter.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/peter.van.ooijen/Rep2_5F00_thumb_5F00_285C28B2.png" alt="Rep2" border="0" title="Rep2" style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;Just pick your POCO domain class. There is no need to set up any methods to get data, it is enough to have a model of the data.&lt;/p&gt;
&lt;p&gt;This object data source is the datasource for your report. Having done so the domain invoice is available in the report designer. (To be precise the datasource has to be attached to a List, see the &lt;a href="http://www.gotreportviewer.com/lists/index.html"&gt;reportviewer docs&lt;/a&gt; for more information on that.)&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://codebetter.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/peter.van.ooijen/Rep3_5F00_3B30AC5C.png"&gt;&lt;img height="290" width="478" src="http://codebetter.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/peter.van.ooijen/Rep3_5F00_thumb_5F00_58565466.png" alt="Rep3" border="0" title="Rep3" style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;A report is built from VB-like expressions. A simple one looks&amp;nbsp; like this:&lt;/p&gt;
&lt;div style="font-family:consolas;background:white;color:black;font-size:10pt;"&gt;
&lt;p style="margin:0px;"&gt;=Fields!Description.Value&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Which displays the plain content of a property. But expressions can be more complicated. The report designer has a good expression builder which even includes intellisense. The next expression uses both the meaningful name and the value of my tax enumeration property in a string&lt;/p&gt;
&lt;div style="font-family:consolas;background:white;color:black;font-size:10pt;"&gt;
&lt;div style="font-family:consolas;background:white;color:black;font-size:10pt;"&gt;
&lt;p style="margin:0px;"&gt;=&lt;span style="color:#a31515;"&gt;&amp;quot;BTW &amp;quot;&lt;/span&gt; &amp;amp; Fields!BtwPercentage.Value.ToString &amp;amp; &lt;span style="color:#a31515;"&gt;&amp;quot; &amp;quot;&lt;/span&gt;&amp;nbsp; &amp;amp; Fields!BtwPercentage.Value &amp;amp; &lt;span style="color:#a31515;"&gt;&amp;quot;%&amp;quot;&lt;/span&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The result is a string like &amp;ldquo;&lt;em&gt;BTW Hoog 19%&amp;rdquo;.&lt;/em&gt; &lt;/p&gt;
&lt;p&gt;Things get really interesting when displaying the contact information. In the domain model this expressed as&lt;/p&gt;
&lt;div style="font-family:consolas;background:white;color:black;font-size:10pt;"&gt;
&lt;p style="margin:0px;"&gt;invoice.ForContact.AddressLine1&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;In the report the expression is quite similar&lt;/p&gt;
&lt;div style="font-family:consolas;background:white;color:black;font-size:10pt;"&gt;
&lt;p style="margin:0px;"&gt;=Fields!ForContact.Value.AddressLine1&lt;/p&gt;
&lt;/div&gt;

&lt;h3&gt;The subreport&lt;/h3&gt;
&lt;p&gt;The lines in the invoice are a one to many relation. The invoice datasource has a &lt;em&gt;lines&lt;/em&gt; property but this property is not usable in the report. To display the lines I need a subreport. The subreport is based on invoice lines. After adding the &lt;em&gt;InvoiceLine&lt;/em&gt; class as a datasource the subreport is drawn. It is a simple table displaying the lines.&lt;/p&gt;
&lt;p&gt;A subreport is linked to its parent report using parameters. In my case an invoice and its lines are linked through a parameter named &lt;em&gt;FactuurNummer&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://codebetter.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/peter.van.ooijen/Rep4_5F00_4F1A1925.png"&gt;&lt;img height="400" width="520" src="http://codebetter.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/peter.van.ooijen/Rep4_5F00_thumb_5F00_33951722.png" alt="Rep4" border="0" title="Rep4" style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;All of this works just as in &amp;ldquo;traditional&amp;rdquo; reports. In the main invoice report this parameter is assigned the value of the invoice number&lt;/p&gt;
&lt;p&gt;&lt;a href="http://codebetter.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/peter.van.ooijen/Rep5_5F00_2AC50ED6.png"&gt;&lt;img height="362" width="513" src="http://codebetter.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/peter.van.ooijen/Rep5_5F00_thumb_5F00_694A5C7C.png" alt="Rep5" border="0" title="Rep5" style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;Check the &lt;a href="http://www.gotreportviewer.com/masterdetail/index.html"&gt;gotreportviewer&lt;/a&gt; site for further information.&lt;/p&gt;
&lt;h3&gt;&lt;/h3&gt;
&lt;h3&gt;&lt;/h3&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h3&gt;Binding the data to the report&lt;/h3&gt;
&lt;p&gt;Now the reports are ready. The next step is to get some real life data into them. &lt;/p&gt;
&lt;p&gt;It takes code to bind real data to a report and display the result in the viewer. Also the subreport has to be fed with data. To wrap things up I have built a helper class which takes a reportviewer component and a list of invoices and wires them up.&lt;/p&gt;
&lt;div style="font-family:consolas;background:white;color:black;font-size:10pt;"&gt;&lt;span style="color:blue;"&gt;
&lt;div style="font-family:consolas;background:white;color:black;font-size:10pt;"&gt;
&lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;internal&lt;/span&gt; &lt;span style="color:blue;"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;InvoiceReporter&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;{&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:blue;"&gt;internal&lt;/span&gt; InvoiceReporter(&lt;span style="color:#2b91af;"&gt;ReportViewer&lt;/span&gt; viewer, &lt;span style="color:#2b91af;"&gt;IList&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af;"&gt;Invoice&lt;/span&gt;&amp;gt; reportData)&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _reportData = reportData;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _viewer = viewer;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:blue;"&gt;private&lt;/span&gt; &lt;span style="color:blue;"&gt;readonly&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;IList&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af;"&gt;Invoice&lt;/span&gt;&amp;gt; _reportData;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:blue;"&gt;private&lt;/span&gt; &lt;span style="color:blue;"&gt;readonly&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;ReportViewer&lt;/span&gt; _viewer;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:blue;"&gt;internal&lt;/span&gt; &lt;span style="color:blue;"&gt;void&lt;/span&gt; ShowReport()&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _viewer.LocalReport.ReportEmbeddedResource = &lt;span style="color:#a31515;"&gt;&amp;quot;Gekko.Administratie.FactuurPrinten.Invoice.rdlc&amp;quot;&lt;/span&gt;;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _viewer.LocalReport.DataSources.Add(&lt;span style="color:blue;"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;ReportDataSource&lt;/span&gt;(&lt;span style="color:#a31515;"&gt;&amp;quot;Gekko_Administratie_DomainModel_Invoice&amp;quot;&lt;/span&gt;, _reportData));&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _viewer.LocalReport.SubreportProcessing += SubreportProcessing;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _viewer.RefreshReport();&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:blue;"&gt;private&lt;/span&gt; &lt;span style="color:blue;"&gt;void&lt;/span&gt; SubreportProcessing(&lt;span style="color:blue;"&gt;object&lt;/span&gt; sender, &lt;span style="color:#2b91af;"&gt;SubreportProcessingEventArgs&lt;/span&gt; e)&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:blue;"&gt;var&lt;/span&gt; invoiceNumber = e.Parameters[&lt;span style="color:#a31515;"&gt;&amp;quot;FactuurNummer&amp;quot;&lt;/span&gt;].Values[0];&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:blue;"&gt;var&lt;/span&gt; invoice = _reportData.First(fakt =&amp;gt; fakt.Number == invoiceNumber);&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; e.DataSources.Add(&lt;span style="color:blue;"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;ReportDataSource&lt;/span&gt;(&lt;span style="color:#a31515;"&gt;&amp;quot;Gekko_Administratie_DomainModel_InvoiceLine&amp;quot;&lt;/span&gt;, invoice.Lines));&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;
&lt;p style="margin:0px;"&gt;}&lt;/p&gt;
&lt;/div&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;p&gt;The code requires some explanation. The constructor should be clear, it receives viewer and data.&lt;/p&gt;
&lt;p&gt;The ShowReport method does the real work. The first line loads the report in the viewer. The second line loads the report data. This line is tricky. The name of the &lt;em&gt;ReportDataSource&lt;/em&gt; &lt;strong&gt;has&lt;/strong&gt; to match exactly the name of the datasource class used as model. The Invoice class name is &lt;em&gt;Gekko.Administratie.DomainModel.Invoice&lt;/em&gt; which gets formatted as &lt;em&gt;Gekko_Administratie_DomainModel_Invoice&lt;/em&gt;. This required magic string is not clear from any documentation, it took me quite some time to find out how essential it was. &lt;/p&gt;
&lt;p&gt;All these datasource properties in the report definition are confusing. The model of the data is saved in the report definition. Changing the datasource&amp;nbsp; to another &amp;ldquo;dataset&amp;rdquo; will also lead to errors at run time. The report will complain about the former datasources. To get rid of the error messages you have to check the report defintion by hand. The report definition file (.rdlc) is plain xml. The last part contains dataset definitions. What helps is just deleting the unused nodes by hand.&lt;/p&gt;
&lt;p&gt;Upon rendering a subreport an event is fired. In the third line of &lt;em&gt;ShowReport&lt;/em&gt; a handler is attached. This &lt;em&gt;SubReportProcessing&lt;/em&gt; method feeds the subreport with data. From the parameters the number of the invoice is read. Which is used to find the corresponding invoice. The datasource for the subreport is set just like the datasource of the main report. Again spelling the name of the reportdatasource right is essential. The data is the Lines property. Which is an IList of InvoiceLines.&lt;/p&gt;
&lt;h3&gt;&lt;/h3&gt;
&lt;h3&gt;Putting it all together&lt;/h3&gt;
&lt;p&gt;With all pieces in place it&amp;rsquo;s time to get some results. I have a windows form with a reportviewer on it. &lt;/p&gt;
&lt;div style="font-family:consolas;background:white;color:black;font-size:10pt;"&gt;
&lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;var&lt;/span&gt; repo = &lt;span style="color:blue;"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;InvoiceRepository&lt;/span&gt;();&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;var&lt;/span&gt; reporter = &lt;span style="color:blue;"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;InvoiceReporter&lt;/span&gt;(reportViewer1, repo.ListPrintableInvoices());&lt;/p&gt;
&lt;p style="margin:0px;"&gt;reporter.ShowReport();&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;This reads the invoices from the repository and sends them with the reportviewer to the helper class.&lt;/p&gt;
&lt;p&gt;There is one more thing to watch. The repository is an nHibernate repository. By default nHibernate lazy loads related objects, like the &lt;em&gt;Contact&lt;/em&gt; and the &lt;em&gt;Lines&lt;/em&gt; of the &lt;em&gt;Invoice&lt;/em&gt;. The contact and the invoicelines will not be read from the database until they are actually used. This default setting has some serious drawbacks. &lt;/p&gt;
&lt;p&gt;In the first place the reportviewer&amp;lsquo;s datareader does not operate very well (at all ?) with nHibernate&amp;rsquo;s proxies. In the report all the contact fields will contain error messages. The subreport on the&amp;nbsp; lines will work. But still the lines are not read from the database until rendering the sub-report. So for this lazy loading to work the report has to be run against a dataset with an open dataconnection. That&amp;rsquo;s bad, I try do do as little as possible, and most likely not presenting a report, with an open connection. A far better scenario would be to fetch all data in one go, close the connection to the database and render the report after that. This can be done by eagerly loading the Contact and Lines properties and disposing of the session before returning the data.&lt;/p&gt;
&lt;p&gt;In the nHibernate API the fetch mode can be set on a property level. The code in the repository takes care of fetching all data in one big snapshot. &lt;/p&gt;
&lt;div style="font-family:consolas;background:white;color:black;font-size:10pt;"&gt;&lt;span style="color:blue;"&gt;
&lt;div style="font-family:consolas;background:white;color:black;font-size:10pt;"&gt;
&lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;IList&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af;"&gt;Invoice&lt;/span&gt;&amp;gt; ListPrintableInvoices()&lt;/p&gt;
&lt;p style="margin:0px;"&gt;{&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:blue;"&gt;using&lt;/span&gt; (&lt;span style="color:blue;"&gt;var&lt;/span&gt; session = &lt;span style="color:#2b91af;"&gt;SessionFactory&lt;/span&gt;.GetFactory.OpenSession())&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:blue;"&gt;var&lt;/span&gt; query = session.CreateCriteria(&lt;span style="color:blue;"&gt;typeof&lt;/span&gt;(&lt;span style="color:#2b91af;"&gt;Invoice&lt;/span&gt;));&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; query.AddOrder(&lt;span style="color:#2b91af;"&gt;Order&lt;/span&gt;.Asc(&lt;span style="color:#a31515;"&gt;&amp;quot;Number&amp;quot;&lt;/span&gt;));&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; query.Add(&lt;span style="color:#2b91af;"&gt;Restrictions&lt;/span&gt;.Eq(&lt;span style="color:#a31515;"&gt;&amp;quot;PrintIt&amp;quot;&lt;/span&gt;, &lt;span style="color:blue;"&gt;true&lt;/span&gt;));&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; query.SetFetchMode(&lt;span style="color:#a31515;"&gt;&amp;quot;Lines&amp;quot;&lt;/span&gt;, &lt;span style="color:#2b91af;"&gt;FetchMode&lt;/span&gt;.Eager);&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; query.SetFetchMode(&lt;span style="color:#a31515;"&gt;&amp;quot;ForContact&amp;quot;&lt;/span&gt;, &lt;span style="color:#2b91af;"&gt;FetchMode&lt;/span&gt;.Eager);&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:blue;"&gt;return&lt;/span&gt; query.List&amp;lt;&lt;span style="color:#2b91af;"&gt;Invoice&lt;/span&gt;&amp;gt;();&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;
&lt;p style="margin:0px;"&gt;}&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;/div&gt;
&lt;p style="margin:0px;"&gt;&lt;/p&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;p&gt;The repository reads all data from the database and closes the connection. After that the collected data are input to the reportviewer. Which now works completely as hoped for. &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://codebetter.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/peter.van.ooijen/Rep6_5F00_405F4773.png"&gt;&lt;img height="531" width="408" src="http://codebetter.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/peter.van.ooijen/Rep6_5F00_thumb_5F00_3384F155.png" alt="Rep6" border="0" title="Rep6" style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I have my report complete with printing and export functionality and am still working with my beloved domain objects.&lt;/p&gt;
&lt;p&gt;This way reporting can almost be pure fun.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://codebetter.com/aggbug.aspx?PostID=249499" width="1" height="1"&gt;</content><author><name>pvanooijen</name><uri>http://codebetter.com/members/pvanooijen/default.aspx</uri></author><category term="Data" scheme="http://codebetter.com/blogs/peter.van.ooijen/archive/tags/Data/default.aspx" /></entry><entry><title>A small web design rant: beware of the RADical designer</title><link rel="alternate" type="text/html" href="/blogs/peter.van.ooijen/archive/2009/06/22/a-small-web-design-rant-beware-of-the-radical-designer.aspx" /><id>/blogs/peter.van.ooijen/archive/2009/06/22/a-small-web-design-rant-beware-of-the-radical-designer.aspx</id><published>2009-06-22T10:09:39Z</published><updated>2009-06-22T10:09:39Z</updated><content type="html">&lt;p&gt;A web designer is responsible for the look of a web site. She designs how the information is displayed on the pages, what illustrations are used and how the parts look together. Working with Visual Studio the collaboration between developer and designer can be streamlined. What usually works quite well is the designer creating an html page and style sheet with the look of the site. The places with dynamic content are marked as plain div’s, in the first draft usually filled with some dummy content to get a first impression. As a developer I turn this page into the master page substituting the content div’s with content placeholders. The classes in the style sheet are used in all the views and pages and I am freed from worries about the look. A clear separation of concerns. &lt;/p&gt;  &lt;p&gt;Over time some adaptations might be necessary, due to content not fitting or specifications changing. This is usually no problem, I get a new css or updated html. Many a good designer does understand asp.net markup, making round tripping even easier. In the process both visual designers are used (by the designer) and mark up is edited (by me). This is no problem as good tools used are two way designers: when you change the look visually the markup changes and when you change the markup the visual appearance changes.&lt;/p&gt;  &lt;p&gt;All of this is of course pretty obvious. But recently I had an experience where it did not work. Describing the scenario our designer assured us it was no problem. She (actually he) would make a good design and his tool would provide us with plain html and a decent css stylesheet. The visual appearance, in the browser, was nice and the design was approved. But alas the markup behind was not that nice. The html was over complicated with things like div’s whose only purpose was to wrap up yet another div. The css did contain a lot of classes. Most of them were quite verbose and defined many many style attributes. A later analysis of their usage showed they were not &lt;em&gt;cascading&lt;/em&gt; style sheets, many an attribute was repeated, usually with exactly the same value. Trying to change the appearance of the site was hard. We had to wrestle our way through the trees of markup. And trying to change the font of a particular part was a quest through styles. Changing which one(s) would do the trick ?&lt;/p&gt;  &lt;p&gt;Going back to the designer did not solve that much, his knowledge of the mark up side of web design was not sufficient for an effective communication. The lessons learned were several. First of all make sure that your designer does not only have good esthetical judgment but can communicate his ideas in a shared language, that of html and css. And when she has a tool which generates that make sure it is a two way tool, so proposals for change can be dealt with.&lt;/p&gt;  &lt;p&gt;All reminded me very much of the RAD discussions. With again the same conclusion. RAD on itself smells but a good 2-way visual designer can still be nice. Coming from Delphi I used to believe that kind of tool existed. Having seen the haystacks of code Visual Studio produces led to serious doubt. And having seen what a visual design tool can do has shattered my last hope.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://codebetter.com/aggbug.aspx?PostID=249211" width="1" height="1"&gt;</content><author><name>pvanooijen</name><uri>http://codebetter.com/members/pvanooijen/default.aspx</uri></author></entry><entry><title>A first glimpse of virtualization in Windows 7</title><link rel="alternate" type="text/html" href="/blogs/peter.van.ooijen/archive/2009/05/20/a-first-glimpse-of-virtualization-in-windows-7.aspx" /><id>/blogs/peter.van.ooijen/archive/2009/05/20/a-first-glimpse-of-virtualization-in-windows-7.aspx</id><published>2009-05-20T14:29:00Z</published><updated>2009-05-20T14:29:00Z</updated><content type="html">&lt;p&gt;For some time now I&amp;rsquo;m using a laptop running 64 bits Server 2008 for mobile software development. The main reason for picking that particular OS were the great virtualization possibilities. In a &lt;a href="http://codebetter.com/blogs/peter.van.ooijen/archive/2008/09/15/nice-laptop-for-a-developer-running-windows-workstation-2008.aspx"&gt;more detailed post&lt;/a&gt; I described setting up the machine and &lt;a href="http://codebetter.com/blogs/peter.van.ooijen/archive/2008/10/28/hyper-v-virtual-networks-and-a-handy-usb-ethernet-gadget.aspx"&gt;working with the diverse network configurations&lt;/a&gt; I met on the road. The machine still works great, the only disadvantage is the relatively long time it takes to boot or shutdown.&lt;/p&gt;
&lt;p&gt;This time my desktop needed a repave. As everybody seems to be wild about Windows 7 I decided to give that a spin. I can be short on Windows 7 itself. It &lt;em&gt;is&lt;/em&gt; really great ! The usual bundle, VS 2008 with MVC and SL, Resharper 4.5, Visual SVN, runs without a glitch. Very smooth, very fast. Just like my server 2008 experiences. Both OS&amp;rsquo;s share the same kernel and this shows. &lt;/p&gt;
&lt;p&gt;Another great thing thing is the overall navigation in Windows 7. The way Windows dock is subtly different but does save a lot of mouse movements. Good in the battle against RSI. And the quality of zooming, most notably in IE8, is terrific. Very good against eye-strain. It will keep an older developer like me up and running. My favorite new feature is&amp;nbsp; the &amp;ldquo;Close all but this&amp;rdquo; &lt;a href="http://www.winsupersite.com/win7/ff_aero_shake.asp"&gt;Aero Shake&lt;/a&gt;. Grab a window bar with the mouse and shake it. Hilarious ! Alas, VS doesn&amp;rsquo;t understand the gesture :(&lt;/p&gt;
&lt;p&gt;As I work on a variety of projects I do need several virtual machines. At least one for every flavor of database server. This drove me to Server 2008 64 bits with Hyper V. Also in Windows 7 virtualization is important. It&amp;rsquo;s not as far as Server 2008 yet but on the longer run it is going to go much further. Virtual XP mode is a good demonstration of that. All is very very beta, not all online documentation is complete. An overview of my experiments:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Install &lt;a href="http://www.microsoft.com/windows/virtual-pc/download.aspx"&gt;Virtual PC beta&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Reboot&lt;/li&gt;
&lt;li&gt;Install Virtual XP. This installs a complete configured virtual XP sp3&lt;/li&gt;
&lt;li&gt;Start Virtual XP, a complete XP desktop shows up. With shared USB drives and full network connectivity to the host, the LAN and the internet&lt;/li&gt;
&lt;li&gt;Install &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=943b6ac7-87f2-45df-a516-21321d559ac3&amp;amp;displaylang=en"&gt;RAIL&lt;/a&gt; in virtual XP&lt;/li&gt;
&lt;li&gt;Reboot Virtual XP&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The Virtual PC manager looks familiar&lt;/p&gt;
&lt;p&gt;&lt;a href="http://codebetter.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/peter.van.ooijen/VirtualPCsinWindows7_5F00_748F041A.png"&gt;&lt;img height="469" width="642" src="http://codebetter.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/peter.van.ooijen/VirtualPCsinWindows7_5F00_thumb_5F00_71999F67.png" alt="Virtual PC&amp;#39;s in Windows 7" border="0" title="Virtual PC&amp;#39;s in Windows 7" style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;As an experiment I tried hosting an existing Hyper-V hosted virtual machine. The vhd is accepted the machine did boot but the screen and all connections remained blank. No wonder, Hyper-V is based on a hypervisor which lives between the hardware and the OS itself. The integration services of the virtual machine are based on this hypervisor. Windows 7 does not have a (compatible) hypervisor yet. But Virtual PC for W7 does require a processor with enabled hardware virtualization support. And the future will bring more with names like MED-V, read &lt;a href="http://www.withinwindows.com/2009/04/25/windows-xp-mode-internals-part-1-overview/"&gt;more here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;One of the things W7 already does bring in the beta are virtual applications. The application itself will actually run in a virtual environment but presents itself as an application on the host OS. W7 has virtual XP applications. With RAIL installed shortcuts in the &lt;em&gt;all users&lt;/em&gt; folder of XP are published on the host OS. I tried this with the worst application I could find. It is my bookkeeping program, an old MS-DOS Clipper application. Clipper applications are horrible. They think they own the whole machine and they are throwing endless streams of BIOS based IO requests. As a result a lot of keystrokes are not recognized. As the application is polling just one executable can drive the CPU load of &lt;strong&gt;any &lt;/strong&gt;processor to 100%. The only good about them is that they do are not multi threaded, you will lose only one core running them. These monsters do work under XP, they don&amp;rsquo;t under Vista.&lt;/p&gt;
&lt;p&gt;I set up a shortcut to the XP command prompt and one to the Clipper app&lt;/p&gt;
&lt;p&gt;&lt;a href="http://codebetter.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/peter.van.ooijen/Allusers_5F00_6718CB47.png"&gt;&lt;img height="327" width="511" src="http://codebetter.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/peter.van.ooijen/Allusers_5F00_thumb_5F00_7AC5B4DB.png" alt="Allusers" border="0" title="Allusers" style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;Both appear on the W7 start menu&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://codebetter.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/peter.van.ooijen/VirtualXPapps_5F00_58217660.png"&gt;&lt;img height="320" width="516" src="http://codebetter.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/peter.van.ooijen/VirtualXPapps_5F00_thumb_5F00_16A6C407.png" alt="Virtual XP apps" border="0" title="Virtual XP apps" style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;And now I do have an XP application which (visually) run as a W7 app.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://codebetter.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/peter.van.ooijen/MsDOsinWIndows7_5F00_2521C02C.png"&gt;&lt;img height="525" width="620" src="http://codebetter.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/peter.van.ooijen/MsDOsinWIndows7_5F00_thumb_5F00_35D9450D.png" alt="MsDOs in WIndows 7" border="0" title="MsDOs in WIndows 7" style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;&amp;lt;Small slightly off-topic rant&amp;gt;&lt;/p&gt;
&lt;p&gt;The only thing I do not like in W7 (so far..) is the default desktop. As a biologist and aquarium keeper I recognize the fish as a male of &lt;a href="http://en.wikipedia.org/wiki/Siamese_fighting_fish"&gt;Betta splendens&lt;/a&gt;, the Siamese fighting fish. They are very aggressive, males will fight each other until one of them dies. Even when the loser gets the opportunity to escape they usually will not survive. A common sight in aquarium shops are specimens who are pale, wrinkled and hardly moving. Not a very good metaphor for an OS. &lt;/p&gt;
&lt;p&gt;Wikipedia has a nice quote why it could make sense: &amp;ldquo;The Siamese fighting fish has been used as the default background in the first official beta version of the &lt;span style="color:#0066cc;"&gt;Windows 7&lt;/span&gt; operating system, in an apparent reference to the name &amp;quot;betta&amp;quot;. This could also be in reference to the fish&amp;#39;s ability to survive in smaller, less advanced aquariums, much like Windows 7 is supposedly designed to work better on lower end computers.&amp;rdquo;&lt;/p&gt;
&lt;p&gt;Could be, but my favorite would be a &lt;a href="http://en.wikipedia.org/wiki/Hoplosternum_thoracatum_cayennae"&gt;kwikwi&lt;/a&gt; then. Which will survive anything, accepts everything as food, can walk over land in case the puddle falls dry, and is a very gentle and social creature. It is also considered a very tasty consumption fish in South America.&lt;/p&gt;
&lt;p&gt;&amp;lt;/Small slightly off-topic rant&amp;gt;&lt;/p&gt;
&lt;p&gt;When starting the Clipper app it does work functionally, all keystrokes are recognized and the app does not crash. But it&amp;rsquo;s not usable, there are long lags between a key press and a program response. (It does work smooth inside virtual XP). But the technique itself seems stable.&lt;/p&gt;
&lt;p&gt;The idea of virtual applications does work. Running normal XP apps, like IE 6 or MSWord 97 is smooth. But why is all of this important to us as software developers ?&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Get rid of legacy apps and legacy parts/ features of the OS. In case you need them, run it in Virtual XP. Give us a clean and rich environment.&lt;/li&gt;
&lt;li&gt;The end of the OS as we know it. A lot of old Windows apps talk to each other. Using OS based protocols like DDE and COM. Or one app which fires of another app. A virtual running app cannot rely on other apps or specific OS features being available. All communication has to be done using formalized channels like WCF or REST&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Well, so far I have scratched the surface. I hope it is enough to get you interested in upcoming virtualization features.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://codebetter.com/aggbug.aspx?PostID=231278" width="1" height="1"&gt;</content><author><name>pvanooijen</name><uri>http://codebetter.com/members/pvanooijen/default.aspx</uri></author></entry><entry><title>Keeping a long running Silverlight application alive under forms authentication</title><link rel="alternate" type="text/html" href="/blogs/peter.van.ooijen/archive/2009/04/16/keeping-a-long-running-silverlight-application-alive-under-forms-authentication.aspx" /><id>/blogs/peter.van.ooijen/archive/2009/04/16/keeping-a-long-running-silverlight-application-alive-under-forms-authentication.aspx</id><published>2009-04-16T20:27:00Z</published><updated>2009-04-16T20:27:00Z</updated><content type="html">&lt;p&gt;This is the scenario : we have a Silverlight application (SL app) which run is running unattended on a big screen in an office. It displays the actual positions of objects on a map. Once every 10 minutes the app queries the hosting web server for position information. The information is not public, it is using asp.net forms authentication to guard it against unauthorized eyes.&lt;/p&gt;
&lt;p&gt;To get this to work as intended required some special attention. In this post I will give an overview. The site is using ajax. Also Silverlight is doing a lot of async communication. The combination of async (partial) postback and forms authentication has some quircks on itself, I wrote &lt;a href="http://codebetter.com/blogs/peter.van.ooijen/archive/2008/12/18/ajax-and-forms-authentication.aspx"&gt;a little post&lt;/a&gt; on that short ago. But as said, there are more quircks.&lt;/p&gt;
&lt;h2&gt;&lt;/h2&gt;
&lt;h3&gt;The server&lt;/h3&gt;
&lt;p&gt;The user sessions are running a long long time. The risk is that within a session IIS will recycle the underlying web application. When that happens the session state will be lost because, by default, session state is stored inproc.&amp;nbsp; The first step is to store the sesssion state in sql server. This will keep the session information alive when the application is recycled. Setting up sql server is no big deal, &lt;a href="http://faqfront.com/document/sql-server-session-state"&gt;this is a good overview&lt;/a&gt;. The thing to watch is that now everything you store in the session has to be explicitly serializable. Which usually boils down to setting the serializable attribute and adding default constructors.&lt;/p&gt;
&lt;h3&gt;The service&lt;/h3&gt;
&lt;p&gt;A Silverlight application gets it&amp;rsquo;s data from a service. Our basic service queries a repository to get specific data.&lt;/p&gt;
&lt;div style="border-right:1px solid;border-top:1px solid;font-size:10pt;background:white;border-left:1px solid;color:black;border-bottom:1px solid;font-family:courier new;"&gt;
&lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;KaartData&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;{&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;static&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af;"&gt;Kaart&lt;/span&gt;&amp;gt; Kaarten(&lt;span style="color:#2b91af;"&gt;KaartSoort&lt;/span&gt; soort, &lt;span style="color:#2b91af;"&gt;KaartPositie&lt;/span&gt; topLeft, &lt;span style="color:#2b91af;"&gt;KaartPositie&lt;/span&gt; bottomRight)&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:#2b91af;"&gt;KaartRepository&lt;/span&gt; repository = &lt;span style="color:#2b91af;"&gt;RepositoryFactory&lt;/span&gt;.KaartRepository();&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:blue;"&gt;return&lt;/span&gt; repository.ListKaarten(soort, topLeft, bottomRight);&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;
&lt;p style="margin:0px;"&gt;}&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;This service is published in a WCF service. A SL app can easily communicate over WCF with a service which is hosted in the same web application as the SL-app itself is running in. It should be possible to host the service somewhere else but that will introduce a large amount of security settings you will have to solve.&lt;/p&gt;
&lt;p&gt;In VS there is a template for such a service. &lt;/p&gt;
&lt;p&gt;&lt;a href="http://codebetter.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/peter.van.ooijen/0904161_5F00_20F7EB1B.jpg"&gt;&lt;img border="0" width="618" src="http://codebetter.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/peter.van.ooijen/0904161_5F00_thumb_5F00_37D6BC97.jpg" alt="0904161" height="446" style="border-top-width:0px;display:inline;border-left-width:0px;border-bottom-width:0px;border-right-width:0px;" title="0904161" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;The result is pretty straightforward &lt;/p&gt;
&lt;div style="border-right:1px solid;border-top:1px solid;font-size:10pt;background:white;border-left:1px solid;color:black;border-bottom:1px solid;font-family:courier new;"&gt;
&lt;p style="margin:0px;"&gt;[&lt;span style="color:#2b91af;"&gt;ServiceContract&lt;/span&gt;(Namespace = &lt;span style="color:#a31515;"&gt;&amp;quot;Datema&amp;quot;&lt;/span&gt;)]&lt;/p&gt;
&lt;p style="margin:0px;"&gt;[&lt;span style="color:#2b91af;"&gt;AspNetCompatibilityRequirements&lt;/span&gt;(RequirementsMode = &lt;span style="color:#2b91af;"&gt;AspNetCompatibilityRequirementsMode&lt;/span&gt;.Allowed)]&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;KaartService&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;{&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; [&lt;span style="color:#2b91af;"&gt;OperationContract&lt;/span&gt;]&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af;"&gt;Kaart&lt;/span&gt;&amp;gt; Kaarten(&lt;span style="color:#2b91af;"&gt;KaartSoort&lt;/span&gt; soort, &lt;span style="color:#2b91af;"&gt;KaartPositie&lt;/span&gt; topLeft, &lt;span style="color:#2b91af;"&gt;KaartPositie&lt;/span&gt; bottomRight)&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:blue;"&gt;return&lt;/span&gt; Datema.DatemaDirect.KaartServices.&lt;span style="color:#2b91af;"&gt;KaartData&lt;/span&gt;.Kaarten(soort, topLeft, bottomRight);&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;
&lt;p style="margin:0px;"&gt;}&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;As the service is embedded in the website it is guarded by forms authentication. That&amp;rsquo;s as intended, we don&amp;rsquo;t want unauthorized people or software to consume our service. But that will hit back, as we will see later.&lt;/p&gt;
&lt;h3&gt;The Silverlight Application&lt;/h3&gt;
&lt;p&gt;The application itself is built around &lt;a href="http://www.codeplex.com/deepearth"&gt;Deep Earth&lt;/a&gt;. This is an open source project which combines the power of Silverlight with that of a geo image servers like virtual Earth, Yahoo maps, Open Street Maps and many others. &lt;/p&gt;
&lt;p&gt;The xaml markup wraps up a deepearth map&lt;/p&gt;
&lt;div style="border-right:1px solid;border-top:1px solid;font-size:10pt;background:white;border-left:1px solid;color:black;border-bottom:1px solid;font-family:courier new;"&gt;
&lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;UserControl&lt;/span&gt;&lt;span style="color:blue;"&gt; &lt;/span&gt;&lt;span style="color:red;"&gt;x:Class&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;ChartMap.Page&lt;/span&gt;&amp;quot;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:red;"&gt;xmlns&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;http://schemas.microsoft.com/winfx/2006/xaml/presentation&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt; &lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:red;"&gt;xmlns:x&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;http://schemas.microsoft.com/winfx/2006/xaml&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt; &lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:red;"&gt;xmlns:DeepEarth&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;clr-namespace:DeepEarth;assembly=DeepEarth&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt; &amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Grid&lt;/span&gt;&lt;span style="color:blue;"&gt; &lt;/span&gt;&lt;span style="color:red;"&gt;x:Name&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;LayoutRoot&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;DeepEarth:Map&lt;/span&gt;&lt;span style="color:blue;"&gt; &lt;/span&gt;&lt;span style="color:red;"&gt;x:Name&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;Map&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;DeepEarth:Map&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;StackPanel&lt;/span&gt;&lt;span style="color:blue;"&gt; &lt;/span&gt;&lt;span style="color:red;"&gt;HorizontalAlignment&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;Left&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt; &lt;/span&gt;&lt;span style="color:red;"&gt;VerticalAlignment&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;Top&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="color:red;"&gt;Margin&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;10&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt; &amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Slider&lt;/span&gt;&lt;span style="color:blue;"&gt; &lt;/span&gt;&lt;span style="color:red;"&gt;x:Name&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;SliderZoom&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt; &lt;/span&gt;&lt;span style="color:red;"&gt;Orientation&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;Vertical&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt; &lt;/span&gt;&lt;span style="color:red;"&gt;Value&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;1&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt; &lt;/span&gt;&lt;span style="color:red;"&gt;Height&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;200&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt; &lt;/span&gt;&lt;span style="color:red;"&gt;Minimum&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;1&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt; &lt;/span&gt;&lt;span style="color:red;"&gt;Maximum&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;20&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="color:red;"&gt;ValueChanged&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;Slider_ValueChanged&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Slider&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;StackPanel&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Grid&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;UserControl&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;A SL-app is living in the browser. The code behind does the registration. &lt;/p&gt;
&lt;div style="border-right:1px solid;border-top:1px solid;font-size:10pt;background:white;border-left:1px solid;color:black;border-bottom:1px solid;font-family:courier new;"&gt;
&lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;private&lt;/span&gt; &lt;span style="color:blue;"&gt;readonly&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;GeometryLayer&lt;/span&gt; mapLayer;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;public&lt;/span&gt; Page()&lt;/p&gt;
&lt;p style="margin:0px;"&gt;{&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; InitializeComponent();&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:blue;"&gt;if&lt;/span&gt; (Map.BaseLayer == &lt;span style="color:blue;"&gt;null&lt;/span&gt;)&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Map.BaseLayer = &lt;span style="color:blue;"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;TileLayer&lt;/span&gt;(&lt;span style="color:#2b91af;"&gt;MapMode&lt;/span&gt;.Aerial);&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Loaded += ((theMap, args) =&amp;gt; &lt;span style="color:#2b91af;"&gt;HtmlPage&lt;/span&gt;.RegisterScriptableObject(&lt;span style="color:#a31515;"&gt;&amp;quot;ChartMap&amp;quot;&lt;/span&gt;, &lt;span style="color:blue;"&gt;this&lt;/span&gt;));&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; mapLayer = &lt;span style="color:blue;"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;GeometryLayer&lt;/span&gt;(Map);&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;}&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;The constructor also initializes a basic geometrylayer. That&amp;rsquo;s an aerial view of the world, to our app it&amp;rsquo;s just a background. A background you can zoom into in great detail. Check the &lt;a href="http://www.codeplex.com/deepearth"&gt;deepearth&lt;/a&gt; site for more on that.&lt;/p&gt;
&lt;p&gt;The constructor registers the application (this) on the HtmlPage under the name &lt;em&gt;ChartMap&lt;/em&gt;. We&amp;rsquo;ll meet that later on in the javascript.&lt;/p&gt;
&lt;p&gt;The application exposes methods to JavaScript by setting the Scriptable attribute&lt;/p&gt;
&lt;div style="border-right:1px solid;border-top:1px solid;font-size:10pt;background:white;border-left:1px solid;color:black;border-bottom:1px solid;font-family:courier new;"&gt;
&lt;p style="margin:0px;"&gt;[&lt;span style="color:#2b91af;"&gt;ScriptableMember&lt;/span&gt;]&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;void&lt;/span&gt; ShowKaarten(&lt;span style="color:#2b91af;"&gt;KaartSoort&lt;/span&gt; vanSoort)&lt;/p&gt;
&lt;p style="margin:0px;"&gt;{&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:blue;"&gt;var&lt;/span&gt; tl = &lt;span style="color:blue;"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;KaartPositie&lt;/span&gt;();&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; tl.Hoogte = Map.GeoBounds.Bottom;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; tl.Lengte = Map.GeoBounds.Left;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:blue;"&gt;var&lt;/span&gt; br = &lt;span style="color:blue;"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;KaartPositie&lt;/span&gt;();&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; br.Hoogte = Map.GeoBounds.Top;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; br.Lengte = Map.GeoBounds.Right;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:blue;"&gt;var&lt;/span&gt; svcProxy = &lt;span style="color:blue;"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;KaartServiceProvider&lt;/span&gt;();&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; svcProxy.GetKaarten(vanSoort, tl, br, DrawKaarten);&lt;/p&gt;
&lt;p style="margin:0px;"&gt;}&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;This method needs the WCF service to get the data.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;h3&gt;Consuming the WCF service in Silverlight&lt;/h3&gt;
&lt;p&gt;The first step is to add a service reference. For this to work you have to disable the forms authentication, else VS cannot get to the service to generate a proxy.&amp;nbsp; The generated proxy, &lt;em&gt;KaartServiceClient&lt;/em&gt;, can only be invoked asynchronous.&lt;/p&gt;
&lt;p&gt;To encapsulate the specific initialization and async coding aspects of the the proxy I have created a helper class&lt;/p&gt;
&lt;div style="border-right:1px solid;border-top:1px solid;font-size:10pt;background:white;border-left:1px solid;color:black;border-bottom:1px solid;font-family:courier new;"&gt;
&lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;internal&lt;/span&gt; &lt;span style="color:blue;"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;KaartServiceProvider&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;{&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:blue;"&gt;private&lt;/span&gt; &lt;span style="color:blue;"&gt;readonly&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;KaartServiceClient&lt;/span&gt; svc;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:blue;"&gt;internal&lt;/span&gt; KaartServiceProvider()&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:blue;"&gt;var&lt;/span&gt; addres = &lt;span style="color:blue;"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;Uri&lt;/span&gt;(&lt;span style="color:#2b91af;"&gt;Application&lt;/span&gt;.Current.Host.Source, &lt;span style="color:#a31515;"&gt;&amp;quot;/Services/KaartService.svc&amp;quot;&lt;/span&gt;);&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; svc = &lt;span style="color:blue;"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;KaartServiceClient&lt;/span&gt;(&lt;span style="color:#a31515;"&gt;&amp;quot;BasicHttpBinding_KaartService&amp;quot;&lt;/span&gt;, &lt;span style="color:blue;"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;EndpointAddress&lt;/span&gt;(addres));&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:blue;"&gt;internal&lt;/span&gt; &lt;span style="color:blue;"&gt;void&lt;/span&gt; GetKaarten(&lt;span style="color:#2b91af;"&gt;KaartSoort&lt;/span&gt; soort, &lt;span style="color:#2b91af;"&gt;KaartPositie&lt;/span&gt; tl, &lt;span style="color:#2b91af;"&gt;KaartPositie&lt;/span&gt; br,&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:#2b91af;"&gt;Action&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af;"&gt;ObservableCollection&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af;"&gt;Kaart&lt;/span&gt;&amp;gt;&amp;gt; kaarten)&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; svc.OpenCompleted += ((sender, e) =&amp;gt; svc.KaartenAsync(soort, tl, br));&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; svc.KaartenCompleted += ((sender, e) =&amp;gt; kaarten(e.Result));&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; svc.OpenAsync();&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;
&lt;p style="margin:0px;"&gt;}&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;It wraps the proxy &lt;em&gt;svc&lt;/em&gt;. In the constructor the proper address of the service is assembled. As the service is hosted by the same application as the Silverlight app I can use &lt;em&gt;&lt;span style="color:#2b91af;"&gt;Application&lt;/span&gt;.Current.Host.Source&lt;/em&gt; to get the right uri. &lt;/p&gt;
&lt;p&gt;The &lt;em&gt;GetKaarten&lt;/em&gt; method is doing the work. It is passed the parameters to the service and also passes &lt;em&gt;kaarten&lt;/em&gt; a callback method to catch the result of the service invocation. The service is explicitly opened, also this has to be done async. &lt;em&gt;OpenCompleted&lt;/em&gt; will start the real work by firing &lt;em&gt;KaarternAsync. &lt;/em&gt;When that completes the callback method will update the map with the fresh data.&lt;/p&gt;
&lt;div style="border-right:1px solid;border-top:1px solid;font-size:10pt;background:white;border-left:1px solid;color:black;border-bottom:1px solid;font-family:courier new;"&gt;
&lt;p style="margin:0px;"&gt;[&lt;span style="color:#2b91af;"&gt;ScriptableMember&lt;/span&gt;]&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;void&lt;/span&gt; ShowKaarten(&lt;span style="color:#2b91af;"&gt;KaartSoort&lt;/span&gt; vanSoort)&lt;/p&gt;
&lt;p style="margin:0px;"&gt;{&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ....&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:blue;"&gt;var&lt;/span&gt; svcProxy = &lt;span style="color:blue;"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;KaartServiceProvider&lt;/span&gt;();&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; svcProxy.GetKaarten(vanSoort, tl, br, DrawKaarten);&lt;/p&gt;
&lt;p style="margin:0px;"&gt;}&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;private&lt;/span&gt; &lt;span style="color:blue;"&gt;void&lt;/span&gt; DrawKaarten(&lt;span style="color:#2b91af;"&gt;ObservableCollection&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af;"&gt;Kaart&lt;/span&gt;&amp;gt; kaarten)&lt;/p&gt;
&lt;p style="margin:0px;"&gt;{&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; mapLayer.Clear();&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:blue;"&gt;foreach&lt;/span&gt; (&lt;span style="color:blue;"&gt;var&lt;/span&gt; kaart &lt;span style="color:blue;"&gt;in&lt;/span&gt; kaarten)&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mapLayer.Add(&lt;span style="color:blue;"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;VisualKaart&lt;/span&gt;(kaart));&lt;/p&gt;
&lt;p style="margin:0px;"&gt;}&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;/div&gt;
&lt;h3&gt;The Silverlight app on a web page&lt;/h3&gt;
&lt;p&gt;The Silverlight app is running in the browser. So the way to program it is through JavaScript. It takes a little puzzling to find the object to talk to. Remember the silverlight app registered itself as &lt;em&gt;ChartMap&lt;/em&gt;. To fire the scriptable webmethod you need the &lt;em&gt;Content.ChartMap&lt;/em&gt; property of the SL-object.&lt;/p&gt;
&lt;p&gt;A silverlight application can be used in several styles of web apps. A classical asp.net works well, an MVC app works even better. The latter is easier because the views in MVC are really client side views, the same enviroment the SL-app is living in. Classical Asp.net is more focused on server side code. &lt;/p&gt;
&lt;p&gt;It will look like this in an MVC view. The SL- app is between the &amp;lt;object&amp;gt; tags and has id &lt;em&gt;Wereld&lt;/em&gt;. The button&amp;rsquo;s&amp;nbsp; onclick event fires the SL method.&lt;/p&gt;
&lt;div style="border-right:1px solid;border-top:1px solid;font-size:10pt;background:white;border-left:1px solid;color:black;border-bottom:1px solid;font-family:courier new;"&gt;
&lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;select&lt;/span&gt; &lt;span style="color:red;"&gt;id&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;kaartSoort&amp;quot;&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;option&lt;/span&gt; &lt;span style="color:red;"&gt;value&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;0&amp;quot;&amp;gt;&lt;/span&gt;ENC&lt;span style="color:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;option&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;option&lt;/span&gt; &lt;span style="color:red;"&gt;value&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;1&amp;quot;&amp;gt;&lt;/span&gt;ARCS&lt;span style="color:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;option&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;select&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;input&lt;/span&gt; &lt;span style="color:red;"&gt;type&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;button&amp;quot;&lt;/span&gt; &lt;span style="color:red;"&gt;value&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;Toon kaarten&amp;quot;&lt;/span&gt; &lt;span style="color:red;"&gt;onclick&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;Wereld.Content.ChartMap.ShowKaarten(kaartSoort.value)&amp;quot;&lt;/span&gt; &lt;span style="color:blue;"&gt;/&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;object&lt;/span&gt; &lt;span style="color:red;"&gt;data&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;data:application/x-silverlight-2,&amp;quot;&lt;/span&gt; &lt;span style="color:red;"&gt;type&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;application/x-silverlight-2&amp;quot;&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:red;"&gt;width&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;100%&amp;quot;&lt;/span&gt; &lt;span style="color:red;"&gt;height&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;100%&amp;quot;&lt;/span&gt; &lt;span style="color:red;"&gt;id&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;Wereld&amp;quot;&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;param&lt;/span&gt; &lt;span style="color:red;"&gt;name&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;source&amp;quot;&lt;/span&gt; &lt;span style="color:red;"&gt;value&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;/ClientBin/ChartMap.xap&amp;quot;&lt;/span&gt; &lt;span style="color:blue;"&gt;/&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;param&lt;/span&gt; &lt;span style="color:red;"&gt;name&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;onerror&amp;quot;&lt;/span&gt; &lt;span style="color:red;"&gt;value&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;onSilverlightError&amp;quot;&lt;/span&gt; &lt;span style="color:blue;"&gt;/&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;param&lt;/span&gt; &lt;span style="color:red;"&gt;name&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;background&amp;quot;&lt;/span&gt; &lt;span style="color:red;"&gt;value&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;white&amp;quot;&lt;/span&gt; &lt;span style="color:blue;"&gt;/&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;param&lt;/span&gt; &lt;span style="color:red;"&gt;name&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;minRuntimeVersion&amp;quot;&lt;/span&gt; &lt;span style="color:red;"&gt;value&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;2.0.31005.0&amp;quot;&lt;/span&gt; &lt;span style="color:blue;"&gt;/&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;param&lt;/span&gt; &lt;span style="color:red;"&gt;name&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;autoUpgrade&amp;quot;&lt;/span&gt; &lt;span style="color:red;"&gt;value&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;true&amp;quot;&lt;/span&gt; &lt;span style="color:blue;"&gt;/&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;a&lt;/span&gt; &lt;span style="color:red;"&gt;href&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;http://go.microsoft.com/fwlink/?LinkID=124807&amp;quot;&lt;/span&gt; &lt;span style="color:red;"&gt;style&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;&lt;/span&gt;&lt;span style="color:red;"&gt;text-decoration&lt;/span&gt;: &lt;span style="color:blue;"&gt;none&lt;/span&gt;;&lt;span style="color:blue;"&gt;&amp;quot;&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;img&lt;/span&gt; &lt;span style="color:red;"&gt;src&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;http://go.microsoft.com/fwlink/?LinkId=108181&amp;quot;&lt;/span&gt; &lt;span style="color:red;"&gt;alt&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;Get Microsoft Silverlight&amp;quot;&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:red;"&gt;style&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;&lt;/span&gt;&lt;span style="color:red;"&gt;border-style&lt;/span&gt;: &lt;span style="color:blue;"&gt;none&amp;quot;&lt;/span&gt; &lt;span style="color:blue;"&gt;/&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;a&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;object&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;To keep the map up to date the method has to be fired over and over again, controlled by some kind of timer. Javascript has no real timers but using the setTimeOut method you can (recursively) call a method after an interval. In this example the function showMap updates the map and calls itself after 600 seconds.&lt;/p&gt;
&lt;div style="border-right:1px solid;border-top:1px solid;font-size:10pt;background:white;border-left:1px solid;color:black;border-bottom:1px solid;font-family:courier new;"&gt;
&lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;var&lt;/span&gt; fleetId = 0;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;var&lt;/span&gt; logoDisplayed = &lt;span style="color:blue;"&gt;false&lt;/span&gt;;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;var&lt;/span&gt; map;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;function&lt;/span&gt; showMap() {&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; map = document.getElementById(&lt;span style="color:#a31515;"&gt;&amp;#39;ctl00_ContentPlaceHolder1_TrackingMap&amp;#39;&lt;/span&gt;).Content.TrackingMap;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; map.ShowFleetTrack(fleetId);&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:green;"&gt;// Refresh map every 10 minutes&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; setTimeout(&lt;span style="color:#a31515;"&gt;&amp;quot;showMap()&amp;quot;&lt;/span&gt;, 600000);&lt;/p&gt;
&lt;p style="margin:0px;"&gt;}&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;This script is living on a classical asp.net page. Notice the ugly long id you need to get to the SL-app. I have moved all var&amp;rsquo;s out of the method to the page. Over time this code will build quite a call stack, not need for &amp;ldquo;invocation specific instance data&amp;rdquo;.&lt;/p&gt;
&lt;h3&gt;What&amp;rsquo;s wrong with this code ?&lt;/h3&gt;
&lt;p&gt;At first sight this code looks alright. But nevertheless it will hit an exception after a certain amount of time. Usually a quite cryptic Silverlight error. It took some puzzling to find out what went wrong.&lt;/p&gt;
&lt;p&gt;The application stays on one and the same page. The script on the page hits the embedded service once every 10 minutes. The service is protected by forms authentication. On every roundtrip the authentication cookie is checked. But what does &lt;strong&gt;not &lt;/strong&gt;happen is updating the timeout of forms authentication. When the user hits code behind a web page the session timeout of forms-authentication is reset. When the user&amp;rsquo;s page hits the embedded service this time-out is not reset. I&amp;rsquo;m not sure whether this is a bug or a feature but it is by no means the behavior you would expect.&lt;/p&gt;
&lt;p&gt;To prevent the service from timing out the script has to hit some server side code behind the page. As a target I add a dummy webmethod to the page&lt;/p&gt;
&lt;div style="border-right:1px solid;border-top:1px solid;font-size:10pt;background:white;border-left:1px solid;color:black;border-bottom:1px solid;font-family:courier new;"&gt;
&lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;partial&lt;/span&gt; &lt;span style="color:blue;"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;FleetMap&lt;/span&gt; : System.Web.UI.&lt;span style="color:#2b91af;"&gt;Page&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;{&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; [&lt;span style="color:#2b91af;"&gt;WebMethod&lt;/span&gt;]&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;static&lt;/span&gt; &lt;span style="color:blue;"&gt;void&lt;/span&gt; HartBeat()&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:green;"&gt;// No need to do anything, this is just a hartbeat from JavaScript to tell the page is still alive&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:green;"&gt;// This hartbeat prevents a time out of the authentication cookie&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;A webmethod, part of ASP.net ajax, can be called directly from script. &lt;/p&gt;
&lt;div style="border-right:1px solid;border-top:1px solid;font-size:10pt;background:white;border-left:1px solid;color:black;border-bottom:1px solid;font-family:courier new;"&gt;
&lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;function&lt;/span&gt; showMap() {&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; PageMethods.HartBeat();&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; map = document.getElementById(&lt;span style="color:#a31515;"&gt;&amp;#39;ctl00_ContentPlaceHolder1_TrackingMap&amp;#39;&lt;/span&gt;).Content.TrackingMap;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; map.ShowFleetTrack(fleetId);&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:green;"&gt;// Refresh map every 10 minutes&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; setTimeout(&lt;span style="color:#a31515;"&gt;&amp;quot;showMap()&amp;quot;&lt;/span&gt;, 600000);&lt;/p&gt;
&lt;p style="margin:0px;"&gt;}&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;In the loop the hartbeat tickles the server to notify the page is still alive. After which the SL-app can start firing its WCF requests.&lt;/p&gt;
&lt;p&gt;I am not checking on exceptions here. In case the session has timed out issuing a &lt;em&gt;HartBeat &lt;/em&gt;will redirect the user to the login page. As intended.&lt;/p&gt;
&lt;h3&gt;&lt;/h3&gt;
&lt;h3&gt;To conclude?&lt;/h3&gt;
&lt;p&gt;And now the app works as intended. Looking back it was a great experience combining all these new api&amp;rsquo;s. Communication between them works pretty good. Once you know how :) The bad guy was imho forms authentication. Which dates from a time when there was no such thing as partial or async postback. In a previous post I talked about the problems it has with ajax. Silverlight, another async poster, apparently has its own problems. &lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://codebetter.com/aggbug.aspx?PostID=195455" width="1" height="1"&gt;</content><author><name>pvanooijen</name><uri>http://codebetter.com/members/pvanooijen/default.aspx</uri></author></entry><entry><title>Every picture tells a story</title><link rel="alternate" type="text/html" href="/blogs/peter.van.ooijen/archive/2009/04/07/every-picture-tells-a-story.aspx" /><id>/blogs/peter.van.ooijen/archive/2009/04/07/every-picture-tells-a-story.aspx</id><published>2009-04-07T12:24:00Z</published><updated>2009-04-07T12:24:00Z</updated><content type="html">&lt;p&gt;As you may have noticed we have some trouble with the images on the codebetter site. Despite all good care the majority got lost when upgrading to a new server. Too bad. Imho a picture tells more than a thousand words. At this moment my blog looks a little like a scrapbook where the pictures have been torn out. Right now I’m digging through all my private backups to dig up what I can find. And will restore whatever I can. But no more lamenting. This post is to celebrate the joy of pictures.&lt;/p&gt;  &lt;p&gt;Many a post is an announcement of some speaking engagement. Complete with a description of the material covered. This post is looking back on just a presentation. I will not cover any depth of content, I’ll just try to show watching and participating in&amp;#160; a presentation is fun.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blog.sanderhoogendoorn.org/"&gt;Sander Hoogendoorn&lt;/a&gt; spoke for the Dutch user group &lt;a href="http://www.sdn.nl/"&gt;SDN&lt;/a&gt;. He’s always pleasantly opinioned on matters. You don’t have to agree on everything but it does tickle your thought. The presentation was titled “Surviving the hypes”. Let’s get started&lt;/p&gt;  &lt;p&gt;&lt;a href="http://codebetter.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/peter.van.ooijen/2009033001_5F00_589DF261.jpg"&gt;&lt;img title="20090330 01" style="border-right:0px;border-top:0px;display:inline;border-left:0px;border-bottom:0px;" height="462" alt="20090330 01" src="http://codebetter.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/peter.van.ooijen/2009033001_5F00_thumb_5F00_5680F398.jpg" width="604" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Ok, everybody is awake now. All the favorite hobby horses, including nHibernate and mvc,&amp;#160; pass the revue. Like a DJ he’s navigating through the slides and talk&lt;/p&gt; &lt;a href="http://codebetter.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/peter.van.ooijen/2009033002_5F00_5463F4CF.jpg"&gt;&lt;img title="20090330 02" style="border-right:0px;border-top:0px;display:inline;border-left:0px;border-bottom:0px;" height="436" alt="20090330 02" src="http://codebetter.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/peter.van.ooijen/2009033002_5F00_thumb_5F00_4474B00B.jpg" width="604" border="0" /&gt;&lt;/a&gt;   &lt;p&gt;But it’s not just opinions on what’s wrong with frameworks, included is a lesson how to isolate your app from the framework using design patterns and techniques like the layer supertype, facade and DI.&lt;/p&gt;  &lt;p&gt;And if everything else fails there’s the new magic of extension methods.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://codebetter.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/peter.van.ooijen/2009033003_5F00_177F4D30.jpg"&gt;&lt;img title="20090330 03" style="border-right:0px;border-top:0px;display:inline;border-left:0px;border-bottom:0px;" height="382" alt="20090330 03" src="http://codebetter.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/peter.van.ooijen/2009033003_5F00_thumb_5F00_4EE55E5E.jpg" width="604" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Great show. In case you got interested in the talk itself, &lt;a href="http://sanderhoogendoorn.org/blog/?p=131"&gt;here’s some more&lt;/a&gt; But better visit your user group and be part of a live show. I hope to have given you some inspiration. &lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://codebetter.com/aggbug.aspx?PostID=191242" width="1" height="1"&gt;</content><author><name>pvanooijen</name><uri>http://codebetter.com/members/pvanooijen/default.aspx</uri></author></entry><entry><title>DDD and repositories. Without nHibernate but with lazy loading</title><link rel="alternate" type="text/html" href="/blogs/peter.van.ooijen/archive/2009/03/17/ddd-and-repositories-without-nhibernate-but-with-lazy-loading.aspx" /><id>/blogs/peter.van.ooijen/archive/2009/03/17/ddd-and-repositories-without-nhibernate-but-with-lazy-loading.aspx</id><published>2009-03-17T12:00:13Z</published><updated>2009-03-17T12:00:13Z</updated><content type="html">&lt;p&gt;Domain driven design has become a very prominent way to develop software. A central domain model is used by all participants. To the end user it is a representation of the real&amp;#160; world. To the coder the model is a class model, working with the real domain world boils down to instantiating objects from these classes. In meetings we find ourselves often discussing a Visual Studio class diagram. Nothing fancy, but it works quite well. The domain user recognizes her entities, their data and behavior, the developer recognizes his classes, properties and methods.&lt;/p&gt;  &lt;p&gt;&lt;img src="http://codebetter.com/photos/peter.van.ooijen/images/189384/original.aspx" alt="" /&gt;&lt;/p&gt;  &lt;p&gt;In DDD these domain objects interact with the database through repositories. The methods of a repository return (sets of) domain objects as read from the database or accept domain objects which will be persisted to the database. nHibernate is a wonderful tool to build these repositories. All you have to do is define a mapping between domain classes and databases tables and nHibernate will take care of the tedious sql stuff. As a bonus you get a nice API for querying.&lt;/p&gt;  &lt;p&gt;But there are reasons not to use nHibernate. &lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Learning curve. In some teams the jump from sql scattered between the tags of a web page, stored procedures and wherever else to an O/R mapper is to big. Getting all database access together in one assembly is a big step forward on itself. &lt;/li&gt;    &lt;li&gt;Database server specific functionality. In a current project we are using SQL 2008 because we need the specific geographical functionality. At the time we started the project SQL 2008 was not feature stable yet, the nHibernate support was not quite there&amp;#160; either and the specific geographical queries would require a lot of sql passthrough. Combined with point 1 it was obvious we were going to do the sql ourselves. &lt;/li&gt;    &lt;li&gt;Restricted permissions on the application hoster. To do its magic nHibernate uses a lot of reflection. Reflection requires more priviliges than the partial trust many a shared hoster does offer. I &lt;a href="http://petersgekko.codebetter.com/blogs/peter.van.ooijen/archive/2008/05/09/nhibernate-and-medium-trust.aspx"&gt;tried to get nHibernate to work under partial trust&lt;/a&gt; but did not succeed. Perhaps it is possible with nHibernate 2.0 &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;But not using nHibernate does not mean you cannot work in DDD style. Using the repository pattern is still the way to go. In the remainder of this post I will briefly demonstrate that and will focus on lazy loading. This is a programming aspect of domain objects which makes life for you as a coder so much easier and your code such a lot clearer and easier to maintain. Given the domain model of last figure, it is clear to code like this&lt;/p&gt;  &lt;div style="border-right:1px solid;border-top:1px solid;font-size:10pt;background:white;border-left:1px solid;color:black;border-bottom:1px solid;font-family:courier new;"&gt;   &lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;foreach&lt;/span&gt; (&lt;span style="color:blue;"&gt;var&lt;/span&gt; orderLine &lt;span style="color:blue;"&gt;in&lt;/span&gt; myOrder.Lines)&lt;/p&gt;    &lt;p style="margin:0px;"&gt;{&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160; myTotal += orderLine.Article.Price;&lt;/p&gt;    &lt;p style="margin:0px;"&gt;}&lt;/p&gt; &lt;/div&gt;   &lt;p&gt; When you need to think about the database stuff behind this things get complicated. The order has to be read from an orders table. The orderdetails are read from another table and for every orderline a row has to be read from the articles table. The only way to get this working is by implementing lazy loading. That is read the data from the database when it is requested, not any earlier than that. With nHibernate you get lazy loading for free. We had to do it ourselves. The solution presented here works well for us. But don’t take it for granted, we have to jump through some hoops. Feel free to comment. Anything to simplify the matter will improve our code.&lt;/p&gt;  &lt;p&gt;The domain layer itself should suffer from persitance ignorance. That is it should be completely unknown to the domain object itself how and where it it persisted. The concession I have to make is that the domain object cannot ignore the fact that it is persited in some way and that it does have a certain price to retrieve data. To express this I define delegates with the domain classes , that is the signature of methods which will actually retrieve a domain object.&lt;/p&gt;  &lt;p&gt;Take the article class&lt;/p&gt;  &lt;div style="border-right:1px solid;border-top:1px solid;font-size:10pt;background:white;border-left:1px solid;color:black;border-bottom:1px solid;font-family:courier new;"&gt;   &lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;Article&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin:0px;"&gt;{&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;int&lt;/span&gt; Id { &lt;span style="color:blue;"&gt;get&lt;/span&gt;; &lt;span style="color:blue;"&gt;private&lt;/span&gt; &lt;span style="color:blue;"&gt;set&lt;/span&gt;; }&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;string&lt;/span&gt; Name { &lt;span style="color:blue;"&gt;get&lt;/span&gt;; &lt;span style="color:blue;"&gt;private&lt;/span&gt; &lt;span style="color:blue;"&gt;set&lt;/span&gt;; }&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;decimal&lt;/span&gt; Price { &lt;span style="color:blue;"&gt;get&lt;/span&gt;; &lt;span style="color:blue;"&gt;private&lt;/span&gt; &lt;span style="color:blue;"&gt;set&lt;/span&gt;; }&lt;/p&gt;    &lt;p style="margin:0px;"&gt;}&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;delegate&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;Article&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;OnRequestArticle&lt;/span&gt;(&lt;span style="color:blue;"&gt;int&lt;/span&gt; id);&lt;/p&gt; &lt;/div&gt;   &lt;p&gt;This delegate is used by the order line class to lazyload an article&lt;/p&gt;  &lt;div style="border-right:1px solid;border-top:1px solid;font-size:10pt;background:white;border-left:1px solid;color:black;border-bottom:1px solid;font-family:courier new;"&gt;   &lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;OrderLine&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin:0px;"&gt;{&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;public&lt;/span&gt; OrderLine(&lt;span style="color:blue;"&gt;int&lt;/span&gt; articleId, &lt;span style="color:blue;"&gt;int&lt;/span&gt; numberOrdered)&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160; {&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;this&lt;/span&gt;.articleId = articleId;&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; NumberOrdered = numberOrdered;&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160; }&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;int&lt;/span&gt; NumberOrdered { &lt;span style="color:blue;"&gt;get&lt;/span&gt;; &lt;span style="color:blue;"&gt;set&lt;/span&gt;; }&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;static&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;OnRequestArticle&lt;/span&gt; RequestArticle { &lt;span style="color:blue;"&gt;get&lt;/span&gt;; &lt;span style="color:blue;"&gt;set&lt;/span&gt;; }&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;private&lt;/span&gt; &lt;span style="color:blue;"&gt;int&lt;/span&gt; articleId;&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;private&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;Article&lt;/span&gt; article;&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;Article&lt;/span&gt; Article&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160; {&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;get&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;if&lt;/span&gt; (article == &lt;span style="color:blue;"&gt;null&lt;/span&gt;)&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;if&lt;/span&gt; (RequestArticle != &lt;span style="color:blue;"&gt;null&lt;/span&gt;)&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; article = RequestArticle(articleId);&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;return&lt;/span&gt; article;&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160; }&lt;/p&gt;    &lt;p style="margin:0px;"&gt;}&lt;/p&gt; &lt;/div&gt;   &lt;p&gt;The article of the orderline is instantiated as a null object. The first time the article is requested the static delegate property is fired to actually retrieve the article. To do that I need the article id. Which is passed in the constructor but not exposed by the domain object. In case you need it it is requested as orderLine.Article.ID&lt;/p&gt;  &lt;p&gt;Likewise the orderlines define a delegate, this one expresses that orderlines come in a set, all belonging to the same order.&lt;/p&gt;  &lt;div style="border-right:1px solid;border-top:1px solid;font-size:10pt;background:white;border-left:1px solid;color:black;border-bottom:1px solid;font-family:courier new;"&gt;   &lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;delegate&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af;"&gt;OrderLine&lt;/span&gt;&amp;gt; &lt;span style="color:#2b91af;"&gt;OnRequestOrderLines&lt;/span&gt;(&lt;span style="color:#2b91af;"&gt;Order&lt;/span&gt; forOrder);&lt;/p&gt; &lt;/div&gt;  &lt;p&gt;This delegate is used in the Order domain class&lt;/p&gt;  &lt;div style="border-right:1px solid;border-top:1px solid;font-size:10pt;background:white;border-left:1px solid;color:black;border-bottom:1px solid;font-family:courier new;"&gt;   &lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;static&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;OnRequestOrderLines&lt;/span&gt; RequestOrderLines { &lt;span style="color:blue;"&gt;get&lt;/span&gt;; &lt;span style="color:blue;"&gt;set&lt;/span&gt;; }&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;private&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af;"&gt;OrderLine&lt;/span&gt;&amp;gt; lines;&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af;"&gt;OrderLine&lt;/span&gt;&amp;gt; Lines&lt;/p&gt;    &lt;p style="margin:0px;"&gt;{&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;get&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160; {&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;if&lt;/span&gt; (lines == &lt;span style="color:blue;"&gt;null&lt;/span&gt;)&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;if&lt;/span&gt; (RequestOrderLines != &lt;span style="color:blue;"&gt;null&lt;/span&gt;)&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; lines = RequestOrderLines(&lt;span style="color:blue;"&gt;this&lt;/span&gt;);&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;return&lt;/span&gt; lines;&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160; }&lt;/p&gt;    &lt;p style="margin:0px;"&gt;}&lt;/p&gt; &lt;/div&gt;  &lt;p&gt;Using these static delegates we can have lazy loading. For the delegates to work they have to be wired up. Before doing that we have to take a look at implementing the repositories.&lt;/p&gt;  &lt;p&gt;This demo project has three repositories: Orders, Articles and Customers. I will not dive into the details of the implementation, you can find those &lt;a href="http://petersgekko.codebetter.com/blogs/peter.van.ooijen/archive/2007/12/03/back-to-basics-from-the-db-to-a-simple-domain-object.aspx"&gt;in a previous post&lt;/a&gt;. What is important for now are the signatures of the repository methods. This is the OrderRepository.&lt;/p&gt;  &lt;div style="border-right:1px solid;border-top:1px solid;font-size:10pt;background:white;border-left:1px solid;color:black;border-bottom:1px solid;font-family:courier new;"&gt;   &lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;OrderRepository&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin:0px;"&gt;{&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;Order&lt;/span&gt; GetOrder(&lt;span style="color:blue;"&gt;int&lt;/span&gt; orderId)&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160; {}&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af;"&gt;Order&lt;/span&gt;&amp;gt; ListOrders()&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160; {}&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af;"&gt;OrderLine&lt;/span&gt;&amp;gt; GetOrderLines(&lt;span style="color:#2b91af;"&gt;Order&lt;/span&gt; forOrder)&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160; {}&lt;/p&gt;    &lt;p style="margin:0px;"&gt;}&lt;/p&gt; &lt;/div&gt;   &lt;p&gt;The last method is quite interesting as it’s signature matches the OnRequestOrderLines delegate. It is the one which has to be wired to the Order’s&amp;#160; RequestOrderLines property.&lt;/p&gt;  &lt;p&gt;The repository has a helper class Lazyloaders which exposes all lazy loading methods as static methods. &lt;/p&gt;  &lt;div style="border-right:1px solid;border-top:1px solid;font-size:10pt;background:white;border-left:1px solid;color:black;border-bottom:1px solid;font-family:courier new;"&gt;   &lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;LazyLoaders&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin:0px;"&gt;{&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;static&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af;"&gt;OrderLine&lt;/span&gt;&amp;gt; RequestOderLines(&lt;span style="color:#2b91af;"&gt;Order&lt;/span&gt; order)&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160; {&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;var&lt;/span&gt; orderRepository = &lt;span style="color:blue;"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;OrderRepository&lt;/span&gt;();&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;return&lt;/span&gt; orderRepository.GetOrderLines(order);&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160; }&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;static&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;Article&lt;/span&gt; RequestArticle(&lt;span style="color:blue;"&gt;int&lt;/span&gt; articleId)&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160; {&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;var&lt;/span&gt; articleRepository = &lt;span style="color:blue;"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;ArticleRepository&lt;/span&gt;();&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;return&lt;/span&gt; articleRepository.GetArticle(articleId);&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160; }&lt;/p&gt;    &lt;p style="margin:0px;"&gt;}&lt;/p&gt; &lt;/div&gt;   &lt;p&gt;A repository object has very real instance members such as the connection to the database. It is not desired to have such a connection as a static member of the repository class. So it’s not possible to declare these static lazyloader members as members of the repository. That’s the main reason for the helper class.&lt;/p&gt;  &lt;p&gt;The lazyloaders have to be static as they are wired to a static property of the domain objects. This wiring up is done in the static constructor of the repository. A static constructor is fired only once, at the moment in your code the class is actually used the first time.&lt;/p&gt;  &lt;div style="border-right:1px solid;border-top:1px solid;font-size:10pt;background:white;border-left:1px solid;color:black;border-bottom:1px solid;font-family:courier new;"&gt;   &lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;OrderRepository&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin:0px;"&gt;{&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;static&lt;/span&gt; OrderRepository()&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160; {&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:#2b91af;"&gt;Order&lt;/span&gt;.RequestOrderLines = &lt;span style="color:#2b91af;"&gt;LazyLoaders&lt;/span&gt;.RequestOrderLines;&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:#2b91af;"&gt;OrderLine&lt;/span&gt;.RequestArticle = &lt;span style="color:#2b91af;"&gt;LazyLoaders&lt;/span&gt;.RequestArticle;&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160; }&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;Order&lt;/span&gt; GetOrder(&lt;span style="color:blue;"&gt;int&lt;/span&gt; orderId)&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160; {}&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af;"&gt;Order&lt;/span&gt;&amp;gt; ListOrders()&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160; {}&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af;"&gt;OrderLine&lt;/span&gt;&amp;gt; GetOrderLines(&lt;span style="color:#2b91af;"&gt;Order&lt;/span&gt; forOrder)&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160; {}&lt;/p&gt;    &lt;p style="margin:0px;"&gt;}&lt;/p&gt; &lt;/div&gt;   &lt;p&gt;In the static constructor of the repository the domain class is given an implementation of the lazyloaders. And now I am there and do have lazy loading for my orders and orderlines. &lt;/p&gt;  &lt;p&gt;It works. There are some things I don’t quite like&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;The domain objects have to expose public delegate properties. These are needed by the repositories but for anything else they can be confusing.&lt;/li&gt;    &lt;li&gt;The orderrepository has to expose the GetOrderLines method. This method makes no sense to any code outside the repositories. There are no orderlines without an order. The only way to access orderlines should be through their order. The lazy loading will return the orderlines. Lazy loading does need this method. Nobody else does. Any suggestion to hide this method is appreciated.&lt;/li&gt;    &lt;li&gt;I have to keep the article ID in the orderline. It is hidden and only required for the lazy loading. But I don’t like having an article Id and an Article in my orderline object.&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;But as a whole this solution is quite satisfying for us. You might wonder whether it performs well. When the&amp;#160; simple loop we started with executes a lot is happening behind the scenes. &lt;/p&gt;  &lt;div style="border-right:1px solid;border-top:1px solid;font-size:10pt;background:white;border-left:1px solid;color:black;border-bottom:1px solid;font-family:courier new;"&gt;   &lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;foreach&lt;/span&gt; (&lt;span style="color:blue;"&gt;var&lt;/span&gt; orderLine &lt;span style="color:blue;"&gt;in&lt;/span&gt; myOrder.Lines)&lt;/p&gt;    &lt;p style="margin:0px;"&gt;{&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160; myTotal += orderLine.Article.Price;&lt;/p&gt;    &lt;p style="margin:0px;"&gt;}&lt;/p&gt; &lt;/div&gt;   &lt;p&gt;For every iteration in the loop an article repository is created and a database query is performed.&amp;#160; When it comes to the actual performance the only thing which really counts is database access. Don’t worry about instantiating POCO’s, do worry about complex sql. That’ s where the real bottleneck is. In this case I’m firing a series of short and simple sql statements. The ado.net connection pooling will ensure the multiple subsequent connections to the DB will be fast. And in real life the code presented here works fast and smooth.&lt;/p&gt;  &lt;p&gt;The real plus lies in the real part of the application, where the code does things all kind of things with the domain objects. And never, ever has to worry when or how the data is read into the domain object. &lt;/p&gt;  &lt;p&gt;I still do miss nHibernate. Writing all the sql, and especially maintaining it, is tedious and can be pretty boring. Except for the geographical stuff. But to all other parts of the application it is transparent whether the repositories are hand work or implemented by an O-R mapper. &lt;/p&gt;  &lt;p&gt;I do hope to have made clear that you main goal should be coding against a domain model, and not using an O-R mapper. And I do hope you have suggestions to make my life even easier.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://codebetter.com/aggbug.aspx?PostID=189386" width="1" height="1"&gt;</content><author><name>pvanooijen</name><uri>http://codebetter.com/members/pvanooijen/default.aspx</uri></author><category term="Coding" scheme="http://codebetter.com/blogs/peter.van.ooijen/archive/tags/Coding/default.aspx" /><category term="Data" scheme="http://codebetter.com/blogs/peter.van.ooijen/archive/tags/Data/default.aspx" /></entry><entry><title>The return of CopySourceAsHtml</title><link rel="alternate" type="text/html" href="/blogs/peter.van.ooijen/archive/2009/02/26/the-return-of-copysourceashtml.aspx" /><id>/blogs/peter.van.ooijen/archive/2009/02/26/the-return-of-copysourceashtml.aspx</id><published>2009-02-26T09:55:09Z</published><updated>2009-02-26T09:55:09Z</updated><content type="html">&lt;p&gt;In a &lt;a href="http://codebetter.com/blogs/peter.van.ooijen/archive/2009/02/24/formatting-source-code-in-a-blog-post-revisited.aspx"&gt;recent post&lt;/a&gt; I did a walk through of using the &lt;a href="http://code.google.com/p/syntaxhighlighter/wiki/Usage"&gt;Google syntax highlighter&lt;/a&gt;. In the end I got it to work. As also the comments pointed out there are two major drawbacks.&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;The syntax highligher requires some scripts. These are installed on the codebetter site but a post read from an RSS feed will not be able to reach the scripts. The code will be an unreadable jumble. &lt;/li&gt;    &lt;li&gt;To work with html, xml or anything else with angle brackets requires using textarea tags. Many a blog post editor (but not all) will&amp;#160; encode the contents of the text enclosed. (&amp;gt; is translated into &amp;amp;gt;). The result will be that the code is also jumbled, even when the scripts are reachable. &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;The comments also pointed to an old friend, &lt;a href="http://www.jtleigh.com/people/colin/software/CopySourceAsHtml/"&gt;CopySourceAsHtml&lt;/a&gt;. I had lost it when moving to VS 2008. The comments&amp;#160; pointed to a recipe to get it working in VS 2008. But that’s no longer needed, &lt;a href="http://www.jtleigh.com/people/colin/software/CopySourceAsHtml/CopySourceAsHtml%203.0.msi"&gt;a VS 2008 version&lt;/a&gt; is now available.&lt;/p&gt;  &lt;p&gt;The good thing with CopySourceAsHtml is that it works with any code file in VS, the Copy As Html item is always in the main edit menu.&lt;/p&gt;  &lt;p&gt;For plain code&lt;/p&gt;  &lt;div style="font-size:12pt;background:white;color:black;font-family:courier new;"&gt;&lt;span style="color:blue;"&gt;     &lt;div style="font-size:10pt;background:white;color:black;font-family:courier new;"&gt;       &lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;namespace&lt;/span&gt; Datema.ENCtracking.Repositories.Helpers&lt;/p&gt;        &lt;p style="margin:0px;"&gt;{&lt;/p&gt;        &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;RepositoryBase&lt;/span&gt;&lt;/p&gt;        &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160; {&lt;/p&gt;        &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;public&lt;/span&gt; RepositoryBase(&lt;span style="color:blue;"&gt;string&lt;/span&gt; connectionString)&lt;/p&gt;        &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {&lt;/p&gt;        &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; connection.ConnectionString = connectionString;&lt;/p&gt;        &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }&lt;/p&gt;        &lt;p style="margin:0px;"&gt;&amp;#160;&lt;/p&gt;     &lt;/div&gt;      &lt;p style="margin:0px;"&gt;&lt;/p&gt; For Html&lt;/span&gt;&lt;/div&gt;  &lt;div style="font-size:12pt;background:white;color:black;font-family:courier new;"&gt;&lt;span style="color:blue;"&gt;     &lt;div style="font-size:10pt;background:white;color:black;font-family:courier new;"&gt;       &lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;asp&lt;/span&gt;&lt;span style="color:blue;"&gt;:&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Content&lt;/span&gt; &lt;span style="color:red;"&gt;ID&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;Content2&amp;quot;&lt;/span&gt; &lt;span style="color:red;"&gt;ContentPlaceHolderID&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;ContentPlaceHolder1&amp;quot;&lt;/span&gt; &lt;span style="color:red;"&gt;runat&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;server&amp;quot;&amp;gt;&lt;/span&gt;&lt;/p&gt;        &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;style&lt;/span&gt; &lt;span style="color:red;"&gt;type&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;text/css&amp;quot;&amp;gt;&lt;/span&gt;&lt;/p&gt;        &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; html,body, form&lt;/p&gt;        &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {&lt;/p&gt;        &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; height: 100%;&lt;/p&gt;        &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }&lt;/p&gt;        &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;style&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;        &lt;p style="margin:0px;"&gt;&amp;#160;&lt;/p&gt;        &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;script&lt;/span&gt; &lt;span style="color:red;"&gt;type&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;/span&gt;&lt;/p&gt;        &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;function&lt;/span&gt; pageLoad() {&lt;/p&gt;        &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; window.onerror = tellerror;&lt;/p&gt;        &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }&lt;/p&gt;        &lt;p style="margin:0px;"&gt;&amp;#160;&lt;/p&gt;        &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;function&lt;/span&gt; tellerror(msg, url, linenumber) {&lt;/p&gt;        &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;if&lt;/span&gt; (msg.toString().indexOf(&lt;span style="color:#a31515;"&gt;&amp;quot;Image&amp;quot;&lt;/span&gt;) &amp;gt;= 0 &amp;amp;&amp;amp; msg.toString().indexOf(&lt;span style="color:#a31515;"&gt;&amp;quot;4001&amp;quot;&lt;/span&gt;) &amp;gt;= 0) {&lt;/p&gt;        &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;return&lt;/span&gt; &lt;span style="color:blue;"&gt;true&lt;/span&gt;;&lt;/p&gt;        &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }&lt;/p&gt;        &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;else&lt;/span&gt; {&lt;/p&gt;        &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; alert(&lt;span style="color:#a31515;"&gt;&amp;#39;Error message= &amp;#39;&lt;/span&gt; + msg + &lt;span style="color:#a31515;"&gt;&amp;#39;\nURL= &amp;#39;&lt;/span&gt; + url + &lt;span style="color:#a31515;"&gt;&amp;#39;\nLineNumber= &amp;#39;&lt;/span&gt; + linenumber)&lt;/p&gt;        &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;return&lt;/span&gt; &lt;span style="color:blue;"&gt;true&lt;/span&gt;;&lt;/p&gt;        &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }&lt;/p&gt;        &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }&lt;/p&gt;     &lt;/div&gt; &lt;/span&gt;&lt;/div&gt;  &lt;p&gt;For Xaml&lt;/p&gt;  &lt;div style="font-size:12pt;background:white;color:black;font-family:courier new;"&gt;&lt;span style="color:blue;"&gt;     &lt;div style="font-size:10pt;background:white;color:black;font-family:courier new;"&gt;       &lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Grid&lt;/span&gt;&lt;span style="color:red;"&gt; x&lt;/span&gt;&lt;span style="color:blue;"&gt;:&lt;/span&gt;&lt;span style="color:red;"&gt;Name&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;LayoutRoot&amp;quot;&lt;/span&gt;&lt;span style="color:red;"&gt; Background&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;White&amp;quot;&amp;gt;&lt;/span&gt;&lt;/p&gt;        &lt;p style="margin:0px;"&gt;&lt;span style="color:#a31515;"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;DeepEarth&lt;/span&gt;&lt;span style="color:blue;"&gt;:&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Map&lt;/span&gt;&lt;span style="color:red;"&gt; x&lt;/span&gt;&lt;span style="color:blue;"&gt;:&lt;/span&gt;&lt;span style="color:red;"&gt;Name&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;map&amp;quot;&lt;/span&gt;&lt;span style="color:red;"&gt; Margin&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;0,0,0,0&amp;quot;&lt;/span&gt;&lt;span style="color:red;"&gt; BorderThickness&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;10&amp;quot;&amp;gt;&lt;/span&gt;&lt;/p&gt;        &lt;p style="margin:0px;"&gt;&lt;span style="color:#a31515;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;DeepControls&lt;/span&gt;&lt;span style="color:blue;"&gt;:&lt;/span&gt;&lt;span style="color:#a31515;"&gt;CoordControl&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;DeepControls&lt;/span&gt;&lt;span style="color:blue;"&gt;:&lt;/span&gt;&lt;span style="color:#a31515;"&gt;CoordControl&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;        &lt;p style="margin:0px;"&gt;&lt;span style="color:#a31515;"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;DeepEarth&lt;/span&gt;&lt;span style="color:blue;"&gt;:&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Map&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;        &lt;p style="margin:0px;"&gt;&lt;span style="color:#a31515;"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;StackPanel&lt;/span&gt;&lt;span style="color:red;"&gt; HorizontalAlignment&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;Left&amp;quot;&lt;/span&gt;&lt;span style="color:red;"&gt; VerticalAlignment&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;Top&amp;quot;&lt;/span&gt; &lt;span style="color:red;"&gt;Margin&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;10&amp;quot; &amp;gt;&lt;/span&gt;&lt;/p&gt;        &lt;p style="margin:0px;"&gt;&lt;span style="color:#a31515;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Button&lt;/span&gt;&lt;span style="color:red;"&gt; x&lt;/span&gt;&lt;span style="color:blue;"&gt;:&lt;/span&gt;&lt;span style="color:red;"&gt;Name&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;ButtonPortLabels&amp;quot;&lt;/span&gt;&lt;span style="color:red;"&gt; Content&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;Ports&amp;quot;&lt;/span&gt;&lt;span style="color:red;"&gt; Click&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;ButtonPortLabels_Click&amp;quot;&lt;/span&gt;&lt;span style="color:red;"&gt; FontSize&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;7&amp;quot;&lt;/span&gt;&lt;span style="color:red;"&gt; Opacity&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;0.5&amp;quot;/&amp;gt;&lt;/span&gt;&lt;/p&gt;        &lt;p style="margin:0px;"&gt;&lt;span style="color:#a31515;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Slider&lt;/span&gt;&lt;span style="color:red;"&gt; x&lt;/span&gt;&lt;span style="color:blue;"&gt;:&lt;/span&gt;&lt;span style="color:red;"&gt;Name&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;SliderZoom&amp;quot;&lt;/span&gt;&lt;span style="color:red;"&gt; Orientation&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;Vertical&amp;quot;&lt;/span&gt;&lt;span style="color:red;"&gt; Value&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;1&amp;quot;&lt;/span&gt;&lt;span style="color:red;"&gt; Height&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;200&amp;quot;&lt;/span&gt;&lt;span style="color:red;"&gt; Minimum&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;1&amp;quot;&lt;/span&gt;&lt;span style="color:red;"&gt; Maximum&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;20&amp;quot;&lt;/span&gt; &lt;span style="color:red;"&gt;ValueChanged&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;Slider_ValueChanged&amp;quot;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Slider&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;        &lt;p style="margin:0px;"&gt;&lt;span style="color:#a31515;"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;StackPanel&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;     &lt;/div&gt; &lt;/span&gt;&lt;/div&gt;  &lt;p&gt;All of these snippets where a matter of select, copy, paste. A thing to watch is the font size. Bu default CSAH takes the size of your editor. In my case the result will look far to big. Selecting a different size is no problem:&lt;/p&gt;  &lt;p&gt;&lt;img src="http://codebetter.com/photos/peter.van.ooijen/images/188709/original.aspx" alt="" /&gt;&lt;/p&gt;  &lt;p&gt;CSAH will remember&amp;#160; this setting.&lt;/p&gt;  &lt;p&gt;No hassles and it looks good on the site and in a feedreader.&lt;/p&gt;  &lt;p&gt;Welcome back !&lt;/p&gt; &lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://codebetter.com/aggbug.aspx?PostID=188708" width="1" height="1"&gt;</content><author><name>pvanooijen</name><uri>http://codebetter.com/members/pvanooijen/default.aspx</uri></author></entry><entry><title>Paging in a sql result set</title><link rel="alternate" type="text/html" href="/blogs/peter.van.ooijen/archive/2009/02/26/paging-in-a-sql-result-set.aspx" /><id>/blogs/peter.van.ooijen/archive/2009/02/26/paging-in-a-sql-result-set.aspx</id><published>2009-02-26T09:28:32Z</published><updated>2009-02-26T09:28:32Z</updated><content type="html">&lt;p&gt;This post is based on &lt;a href="http://davidhayden.com/blog/dave/archive/2005/12/30/2652.aspx"&gt;a post by fellow CB blogger Dave Hayden&lt;/a&gt;.&amp;#160; It deals with paging through a set of sql server data. Dave has a very clear and elegant solution but it did take some puzzling to find out why things have to be done that way. Dave’s solution steered towards a sproc. Trying to stay away from that I want to present a dynamic sql version of the same idea.&lt;/p&gt;  &lt;p&gt;Since the 2005 version of MS SQL server has the &lt;a href="http://msdn.microsoft.com/en-us/library/ms186734.aspx"&gt;ROW_NUMBER&lt;/a&gt; function. This function returns the sequence number of the result set rows. Like this select statement.&lt;/p&gt;  &lt;div style="font-size:12pt;background:white;color:black;font-family:courier new;"&gt;   &lt;p style="margin:0px;"&gt;SELECT Id, Name, ROW_NUMBER() OVER (ORDER BY Name) AS Row FROM Fleet&lt;/p&gt; &lt;/div&gt;  &lt;p&gt;The OVER part determines the sort order of the result set.&lt;/p&gt;  &lt;p&gt; This row number is an ideal base for retrieving data in pages. With a page size of 20 the first page will contain row numbers 1 to 21, the second 21 to 40, etc. Alas you cannot use the function result directly in the where clause. To retrieve the first page this sql will not work. &lt;/p&gt;  &lt;div style="font-size:12pt;background:white;color:black;font-family:courier new;"&gt;   &lt;p style="margin:0px;"&gt;SELECT Id, Name, ROW_NUMBER() OVER (ORDER BY Name) AS Row FROM Fleet WHERE ROW &amp;lt; 21 &lt;/p&gt; &lt;/div&gt;  &lt;p&gt;To get around this you need an outer select to wrap up. Like this:&lt;/p&gt;  &lt;div style="font-size:12pt;background:white;color:black;font-family:courier new;"&gt;   &lt;p style="margin:0px;"&gt;SELECT Id, Name FROM &lt;/p&gt;    &lt;p style="margin:0px;"&gt;(SELECT Id, Name, ROW_NUMBER() OVER (ORDER BY Name) AS Row FROM Fleet) AS tmp &lt;/p&gt;    &lt;p style="margin:0px;"&gt;WHERE ROW &amp;lt; 21 &lt;/p&gt; &lt;/div&gt;  &lt;p&gt;There is a pattern in this&lt;/p&gt;  &lt;div style="font-size:12pt;background:white;color:black;font-family:courier new;"&gt;   &lt;p style="margin:0px;"&gt;SELECT&amp;#160; &lt;strong&gt;MyCols&lt;/strong&gt; FROM&lt;/p&gt;    &lt;p style="margin:0px;"&gt;(SELECT &lt;strong&gt;MyCols&lt;/strong&gt;, ROW_NUMBER() OVER (ORDER BY &lt;strong&gt;MyOrder&lt;/strong&gt;) AS Row FROM &lt;strong&gt;MyView&lt;/strong&gt;) AS tmp&lt;/p&gt;    &lt;p style="margin:0px;"&gt;WHERE ROW &amp;lt; &lt;strong&gt;MaxRow&lt;/strong&gt;&lt;/p&gt; &lt;/div&gt;  &lt;p&gt;   &lt;br /&gt;&lt;/font&gt;&lt;/font&gt;The values for the example query I started with&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;MyCols=”Id, Name”&lt;/p&gt;  &lt;p&gt;MyView=”Fleet”&lt;/p&gt;  &lt;p&gt;MyOrder=”Name”&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;In a more complex scenario the data will be a view on several tables resulting in one result set. Here the list of columns for the result set will not match the list of columns in the view.&lt;/p&gt;  &lt;p&gt;Take this query.&lt;/p&gt; &lt;font size="2"&gt;&lt;font color="#000000"&gt;     &lt;div style="font-size:12pt;background:white;color:black;font-family:courier new;"&gt;       &lt;p style="margin:0px;"&gt;SELECT&amp;#160; Name,Id, City FROM &lt;/p&gt;        &lt;p style="margin:0px;"&gt;(SELECT Person.Name,Person.Id, City.City , ROW_NUMBER() OVER (ORDER BY Name) AS Row FROM Persons INNER JOIN City On Person.CityId=City.ID) AS tmp&amp;#160; &lt;/p&gt;        &lt;p style="margin:0px;"&gt;WHERE ROW &amp;lt; 21&lt;/p&gt;     &lt;/div&gt;      &lt;p&gt;&lt;/p&gt;      &lt;p&gt;&lt;/p&gt; The pattern now evolves to&lt;/font&gt;&lt;font size="2"&gt;&lt;font color="#000000"&gt;&lt;/font&gt;      &lt;div style="font-size:12pt;background:white;color:black;font-family:courier new;"&gt;       &lt;p style="margin:0px;"&gt;SELECT&amp;#160; &lt;strong&gt;MyCols&lt;/strong&gt; FROM &lt;/p&gt;        &lt;p style="margin:0px;"&gt;(SELECT &lt;strong&gt;MyViewCols&lt;/strong&gt;, ROW_NUMBER() OVER (ORDER BY &lt;strong&gt;MyOrder&lt;/strong&gt;) AS Row FROM &lt;strong&gt;MyView&lt;/strong&gt;) AS tmp&amp;#160; &lt;/p&gt;        &lt;p style="margin:0px;"&gt;WHERE ROW &amp;lt; MaxRow&lt;/p&gt;     &lt;/div&gt;      &lt;p&gt;&lt;/p&gt;   &lt;/font&gt;The values for the last query &lt;/font&gt;  &lt;p&gt;MyCols=”Name, Id, City”&lt;/p&gt;  &lt;p&gt;MyViewCols=”&lt;font size="3"&gt;Person.Name,Person.Id, City.City &lt;/font&gt;”&lt;/p&gt;  &lt;p&gt;MyView=”&lt;font size="3"&gt;Persons INNER JOIN City On Person.CityId=City.ID&lt;/font&gt;”&lt;/p&gt;  &lt;p&gt;MyOrder=”Name”&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;To complete the pattern I have to fully parameterize the row numbers. Here I also limit the inner query with a SELECT TOP, no need to retrieve more rows than maxrow.&lt;/p&gt;  &lt;div style="font-size:12pt;background:white;color:black;font-family:courier new;"&gt;   &lt;p style="margin:0px;"&gt;SELECT &lt;strong&gt;MyCols&lt;/strong&gt; FROM &lt;/p&gt;    &lt;p style="margin:0px;"&gt;(SELECT TOP &lt;strong&gt;MaxRow &lt;/strong&gt;ROW_NUMBER OVER (ORDER BY&amp;#160; &lt;strong&gt;MyOrder &lt;/strong&gt;) AS Row, &lt;strong&gt;MyViewCols&lt;/strong&gt; FROM &lt;strong&gt;MyView&lt;/strong&gt;)&amp;#160; AS Tmp &lt;/p&gt;    &lt;p style="margin:0px;"&gt;WHERE Row &amp;gt; @MinRow AND Row &amp;lt;= @MaxRow&lt;/p&gt; &lt;/div&gt;  &lt;p&gt; It is cumbersome to assemble this query over and over again.&amp;#160; Having to do all sql myself (more on that in a later post) I have built a small C# function which will assemble the paging query from the fragments passed in. It uses the pattern described,&amp;#160; builds a sqlCommand and is used like this. &lt;/p&gt;  &lt;div style="font-size:12pt;background:white;color:black;font-family:courier new;"&gt;   &lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;const&lt;/span&gt; &lt;span style="color:blue;"&gt;string&lt;/span&gt; columns = &lt;span style="color:#a31515;"&gt;&amp;quot;Code, ExpireDate, Description&amp;quot;&lt;/span&gt;;&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;const&lt;/span&gt; &lt;span style="color:blue;"&gt;string&lt;/span&gt; view = &lt;span style="color:#a31515;"&gt;&amp;quot;Permit INNER JOIN ProductCell ON Permit.Code = ProductCell.Code WHERE Permit.LicenceId=@LicenceId&amp;quot;&lt;/span&gt;;&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;const&lt;/span&gt; &lt;span style="color:blue;"&gt;string&lt;/span&gt; orderBy = &lt;span style="color:#a31515;"&gt;&amp;quot;Permit.Code&amp;quot;&lt;/span&gt;;&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;const&lt;/span&gt; &lt;span style="color:blue;"&gt;string&lt;/span&gt; viewColumns = &lt;span style="color:#a31515;"&gt;&amp;quot;Permit.Code, ExpireDate, Description&amp;quot;&lt;/span&gt;;&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;var&lt;/span&gt; cmd = BuildPagedSelectCommand(pageNo, columns, view, orderBy, viewColumns, pageSize);&lt;/p&gt;    &lt;p style="margin:0px;"&gt;cmd.Parameters.AddWithValue(&lt;span style="color:#a31515;"&gt;&amp;quot;@LicenceId&amp;quot;&lt;/span&gt;, licenceId);&lt;/p&gt; &lt;/div&gt;   &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;font size="4"&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;The function itself is pretty straightforward&lt;/p&gt;  &lt;div style="font-size:12pt;background:white;color:black;font-family:courier new;"&gt;&lt;span style="color:blue;"&gt;     &lt;div style="font-size:12pt;background:white;color:black;font-family:courier new;"&gt;       &lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;protected&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;SqlCommand&lt;/span&gt; BuildPagedSelectCommand(&lt;span style="color:blue;"&gt;int&lt;/span&gt; pageNumber, &lt;span style="color:blue;"&gt;string&lt;/span&gt; columnList, &lt;span style="color:blue;"&gt;string&lt;/span&gt; selectFrom, &lt;span style="color:blue;"&gt;string&lt;/span&gt; orderBy, &lt;span style="color:blue;"&gt;string&lt;/span&gt; columnsAs, &lt;span style="color:blue;"&gt;int&lt;/span&gt; pageSize)&lt;/p&gt;        &lt;p style="margin:0px;"&gt;{&lt;/p&gt;        &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;var&lt;/span&gt; minRow = (pageNumber - 1) * pageSize;&lt;/p&gt;        &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;var&lt;/span&gt; maxRow = minRow + pageSize;&lt;/p&gt;        &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;var&lt;/span&gt; cmd = &lt;span style="color:blue;"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;SqlCommand&lt;/span&gt;(&lt;span style="color:blue;"&gt;string&lt;/span&gt;.Format(&lt;span style="color:#a31515;"&gt;&amp;quot;SELECT {0} FROM (SELECT TOP {1} ROW_NUMBER() OVER (ORDER BY {2}) AS Row,{3} FROM {4}) AS tmp WHERE Row &amp;gt; @MinRow AND Row &amp;lt;= @MaxRow&amp;quot;&lt;/span&gt;,&lt;/p&gt;        &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; columnList, maxRow, orderBy, columnsAs, selectFrom), connection);&lt;/p&gt;        &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160; cmd.Parameters.AddWithValue(&lt;span style="color:#a31515;"&gt;&amp;quot;@MinRow&amp;quot;&lt;/span&gt;, minRow);&lt;/p&gt;        &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160; cmd.Parameters.AddWithValue(&lt;span style="color:#a31515;"&gt;&amp;quot;@MaxRow&amp;quot;&lt;/span&gt;, maxRow);&lt;/p&gt;        &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;return&lt;/span&gt; cmd;&lt;/p&gt;        &lt;p style="margin:0px;"&gt;}&lt;/p&gt;     &lt;/div&gt; &lt;/span&gt;&lt;/div&gt;  &lt;p&gt; All it does is calculate the rownumbers, assemble the sql statement and create the sql command to return. &lt;/p&gt;  &lt;p&gt;For the simpler cases where the result columns match the underlying view columns I have created an overload.&lt;/p&gt;  &lt;div style="font-size:12pt;background:white;color:black;font-family:courier new;"&gt;   &lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;protected&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;SqlCommand&lt;/span&gt; BuildPagedSelectCommand(&lt;span style="color:blue;"&gt;int&lt;/span&gt; pageNumber, &lt;span style="color:blue;"&gt;string&lt;/span&gt; columnList, &lt;span style="color:blue;"&gt;string&lt;/span&gt; selectFrom, &lt;span style="color:blue;"&gt;string&lt;/span&gt; orderBy, &lt;span style="color:blue;"&gt;int&lt;/span&gt; pageSize)&lt;/p&gt;    &lt;p style="margin:0px;"&gt;{&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;return&lt;/span&gt; BuildPagedSelectCommand(pageNumber, columnList, selectFrom, orderBy, columnList, pageSize);&lt;/p&gt;    &lt;p style="margin:0px;"&gt;}&lt;/p&gt; &lt;/div&gt;   &lt;p&gt;It uses the original overload using the columnlist twice.&lt;/p&gt;  &lt;p&gt;Paging data is not that complicated but the syntax of the query required is somewhat confusing. I hope this example helps in clarifying it.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://codebetter.com/aggbug.aspx?PostID=188707" width="1" height="1"&gt;</content><author><name>pvanooijen</name><uri>http://codebetter.com/members/pvanooijen/default.aspx</uri></author><category term="Data" scheme="http://codebetter.com/blogs/peter.van.ooijen/archive/tags/Data/default.aspx" /></entry><entry><title>Formatting source code in a blog post (revisited)</title><link rel="alternate" type="text/html" href="/blogs/peter.van.ooijen/archive/2009/02/24/formatting-source-code-in-a-blog-post-revisited.aspx" /><id>/blogs/peter.van.ooijen/archive/2009/02/24/formatting-source-code-in-a-blog-post-revisited.aspx</id><published>2009-02-24T08:16:00Z</published><updated>2009-02-24T08:16:00Z</updated><content type="html">&lt;p&gt;There are a couple of posts I have to write. But before doing that I need to &lt;a href="http://codebetter.com/blogs/peter.van.ooijen/archive/2007/03/02/Formatting-source-code-in-a-blog-post-.aspx"&gt;reinvestigate&lt;/a&gt; the way to format source code. The Codebetter site supports the &lt;a href="http://code.google.com/p/syntaxhighlighter/wiki/Usage"&gt;Google syntax highlighter&lt;/a&gt;. Which works great for C# code but up till now I havn’t had any luck with XML of HTML. This post was started as a public experiment to get that working. In the process I have posted it again and again to see what it looks like. Now things are straightened out and the cheat-sheet remains.&lt;/p&gt;
&lt;p&gt;To use Syntax highlighter you needs a blogging tool which supports direct editing of the underlying HTML. As a non native speaker I also need a good spelling checker. Both are combined in LiveWriter,&lt;/p&gt;
&lt;p&gt;Formatting some C#&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Select the source in Visual studio and copy it to the clipboard &lt;/li&gt;
&lt;li&gt;Paste the code into notepad. This will paste the raw text only and remove any formatting &lt;/li&gt;
&lt;li&gt;Copy the code from notepad to the clipboard &lt;/li&gt;
&lt;li&gt;Go to HTML view &lt;/li&gt;
&lt;li&gt;Paste the code &lt;/li&gt;
&lt;li&gt;Enclose it in a pair of &lt;em&gt;pre&lt;/em&gt; tags &lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;&amp;lt;pre class=&amp;quot;c-sharp&amp;quot; name=&amp;quot;code&amp;quot;&amp;gt; &lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;public Term GetOrAddTerm(string word, Language language) &lt;br /&gt;{ &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Term result = GetTerm(word, language); &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (result == null) &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; { &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; result = new Term(); &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; result.Word = word; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; result.Language = language; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Save(result); &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; } &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return result; &lt;br /&gt;}&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&amp;lt;/pre&amp;gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;And this will be the result.&lt;/p&gt;&lt;pre class="C-sharp" name="code"&gt;public Term GetOrAddTerm(string word, Language language)
{
    Term result = GetTerm(word, language);
    if (result == null)
    {
        result = new Term();
        result.Word = word;
        result.Language = language;
        Save(result);
    }
    return result;
}&lt;/pre&gt;
&lt;p&gt;That’ no big deal. But for HTML or XML it is harder. When pasting the code in HTML view the code itself will turn into markup of the page. Not the intention. To solve this &lt;em&gt;use the &lt;strong&gt;textarea&lt;/strong&gt; tag instead of the pre tag&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;The html markup of the post will look like this.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&amp;lt;textarea class=”html” name=”code”&amp;gt;&lt;/strong&gt;&lt;/p&gt;&lt;br /&gt;&amp;lt;table&amp;gt; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;% &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; foreach (var crumb in Model.BreadCrumbs) &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {%&amp;gt; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;tr&amp;gt; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;td&amp;gt; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;%= Html.ActionLink(crumb.Naam, crumb.ID.ToString())%&amp;gt; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/td&amp;gt; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/tr&amp;gt; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;%&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; } %&amp;gt; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;tr&amp;gt; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;td&amp;gt; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;%= Model.ArtikelGroep.Naam&amp;nbsp; %&amp;gt; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/td&amp;gt; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/tr&amp;gt; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;tr&amp;gt; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;td&amp;gt; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/td&amp;gt; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/tr&amp;gt; &lt;br /&gt;&amp;lt;/table&amp;gt; &lt;br /&gt;&lt;strong&gt;&amp;lt;/textarea&amp;gt;&lt;/strong&gt; 
&lt;p&gt;This is pretty weird. Looks like&amp;nbsp; markup, but it is no markup as it is enclosed between the &amp;lt;textarea&amp;gt; tags. Some pieces of software will trip over this. Like the post editor, which might change the html into escaped html (&amp;amp;lt). But on the CB site the result looks just great.&lt;/p&gt;&lt;textarea class="html" name="code"&gt;&amp;lt;table&amp;gt;
    &amp;lt;%
        foreach (var crumb in Model.BreadCrumbs)
        {%&amp;gt;
    &amp;lt;tr&amp;gt;
        &amp;lt;td&amp;gt;
            &amp;lt;%= Html.ActionLink(crumb.Naam, crumb.ID.ToString())%&amp;gt;
        &amp;lt;/td&amp;gt;
    &amp;lt;/tr&amp;gt;
    &amp;lt;%    
        } %&amp;gt;
    &amp;lt;tr&amp;gt;
        &amp;lt;td&amp;gt;
            &amp;lt;%= Model.ArtikelGroep.Naam  %&amp;gt;
        &amp;lt;/td&amp;gt;
    &amp;lt;/tr&amp;gt;
    &amp;lt;tr&amp;gt;
        &amp;lt;td&amp;gt;
        &amp;lt;/td&amp;gt;
    &amp;lt;/tr&amp;gt;
&amp;lt;/table&amp;gt;
&lt;/textarea&gt; 
&lt;p&gt;In the end it’s quite simple. Having this settled I can start working on the real posts. Stay tuned.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://codebetter.com/aggbug.aspx?PostID=188640" width="1" height="1"&gt;</content><author><name>pvanooijen</name><uri>http://codebetter.com/members/pvanooijen/default.aspx</uri></author></entry><entry><title>Firefox and the 100% DIV revisited</title><link rel="alternate" type="text/html" href="/blogs/peter.van.ooijen/archive/2009/01/27/firefox-and-the-100-div-revisited.aspx" /><id>/blogs/peter.van.ooijen/archive/2009/01/27/firefox-and-the-100-div-revisited.aspx</id><published>2009-01-27T13:13:00Z</published><updated>2009-01-27T13:13:00Z</updated><content type="html">&lt;p&gt;One of the best thing about blogging is that it is a two way thing. Responses help me to find directions to solve the post&amp;#39;s problem. In my &lt;a href="http://codebetter.com/blogs/peter.van.ooijen/archive/2008/12/18/silverlight-firefox-and-100.aspx"&gt;last post&lt;/a&gt; I discussed a workaround for a problem we had with Firefox. The many constructive comments gave me more insight, leading to a far better solution. &lt;/p&gt;
&lt;p&gt;The problem was a page which is supposed to display a Silverlight control which fills a browser window&lt;/p&gt;&lt;font color="#000000"&gt;
&lt;p&gt;&amp;lt;html xmlns=&amp;quot;&lt;a href="http://www.w3.org/1999/xhtml"&gt;http://www.w3.org/1999/xhtml&lt;/a&gt;&amp;quot; &amp;gt; &lt;br /&gt;&amp;lt;head runat=&amp;quot;server&amp;quot;&amp;gt; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;title&amp;gt;&amp;lt;/title&amp;gt; &lt;br /&gt;&amp;lt;/head&amp;gt;&lt;/p&gt;
&lt;p&gt;&amp;lt;body &amp;gt; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;form id=&amp;quot;form1&amp;quot; runat=&amp;quot;server&amp;quot;&amp;gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;ajaxToolkit:ToolkitScriptManager runat=&amp;quot;Server&amp;quot; ID=&amp;quot;ScriptManager1&amp;quot; EnablePageMethods=&amp;quot;true&amp;quot; /&amp;gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;div style=&amp;#39;height:100%; width:100%&amp;#39; &amp;gt; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;asp:Silverlight ID=&amp;quot;TrackingMap&amp;quot; runat=&amp;quot;server&amp;quot; Source=&amp;quot;~/ClientBin/Map.xap&amp;quot; BackColor=&amp;quot;Transparent&amp;quot; Windowless=&amp;quot;true&amp;quot;&amp;nbsp; Height=&amp;quot;100%&amp;quot; Width=&amp;quot;100%&amp;quot; /&amp;gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/div&amp;gt; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/form&amp;gt; &lt;br /&gt;&amp;lt;/body&amp;gt; &lt;br /&gt;&amp;lt;/html&amp;gt; &lt;br /&gt;&lt;/p&gt;&lt;/font&gt;
&lt;p&gt;It looks great in IE but in Firefox the page is completely blank. This has to with the way IE and FIrefox calculate the available width. IE takes the browser windows&amp;#39; width. Which is, in this scenario, the intended value. Firefox considers the width not set so it is 0. As James says it &amp;quot;&lt;a href="http://codebetter.com/blogs/peter.van.ooijen/archive/2008/12/18/silverlight-firefox-and-100.aspx#187375"&gt;both implementations are idiotic&lt;/a&gt;&amp;quot;&lt;/p&gt;
&lt;p&gt;There are several work around&amp;#39;s. A post by &lt;a href="http://www.nablasoft.com/guardian/index.php/about/"&gt;Giorgetti Alessandro&lt;/a&gt;&amp;nbsp; &lt;a href="http://www.nablasoft.com/guardian/index.php/2008/11/06/silverlight-plugin-height-percentage-problem-firefox/"&gt;summarizes all of them&lt;/a&gt;. I did some further investigations and found limitations and gotcha&amp;#39;s on all three of them.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Use an absolute size&amp;nbsp; instead of a percentage. I discussed that in my&amp;nbsp; &lt;a href="http://codebetter.com/blogs/peter.van.ooijen/archive/2008/12/18/silverlight-firefox-and-100.aspx"&gt;previous post&lt;/a&gt; already. &lt;/li&gt;
&lt;li&gt;Add a &lt;strong&gt;position:fixed&lt;/strong&gt; attribute to the style of the containing div. This does have a lot of drawbacks. Googling around you will find a lot of them. Besides upsetting a couple of browsers it also has a very bad influence on the content of the div. Our Silverlight control has the &lt;em&gt;BackColor&lt;/em&gt; and &lt;em&gt;Windowless&lt;/em&gt; attributes set. With these values the control works well with ajax popups like the calendar Extender. Setting the &lt;em&gt;position:fixed&lt;/em&gt; attribute hides all of the popups. So that option is a no go. &lt;/li&gt;
&lt;li&gt;Set the height of all main containers on the page to 100%. This is a suggestion which does work; but only when applied thoroughly. &lt;/li&gt;&lt;/ol&gt;
&lt;p&gt;To display the page correctly requires the following addition to the markup.&lt;/p&gt;&lt;font color="#0000ff"&gt;
&lt;p&gt;&lt;font color="#000000"&gt;&amp;lt;html xmlns=&amp;quot;&lt;a href="http://www.w3.org/1999/xhtml"&gt;http://www.w3.org/1999/xhtml&lt;/a&gt;&amp;quot; &amp;gt; &lt;br /&gt;&amp;lt;head runat=&amp;quot;server&amp;quot;&amp;gt; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;title&amp;gt;&amp;lt;/title&amp;gt; &lt;br /&gt;&lt;strong&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;style type=&amp;quot;text/css&amp;quot;&amp;gt; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; html,body, form &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; { &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; height: 100%; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; } &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/style&amp;gt; &lt;br /&gt;&lt;/strong&gt;&amp;lt;/head&amp;gt;&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font color="#000000"&gt;&amp;lt;body &amp;gt; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;form id=&amp;quot;form1&amp;quot; runat=&amp;quot;server&amp;quot;&amp;gt;&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font color="#000000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;ajaxToolkit:ToolkitScriptManager runat=&amp;quot;Server&amp;quot; ID=&amp;quot;ScriptManager1&amp;quot; EnablePageMethods=&amp;quot;true&amp;quot; /&amp;gt;&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font color="#000000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;div style=&amp;#39;height:100%; width:100%&amp;#39; &amp;gt; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;asp:Silverlight ID=&amp;quot;TrackingMap&amp;quot; runat=&amp;quot;server&amp;quot; Source=&amp;quot;~/ClientBin/Map.xap&amp;quot; BackColor=&amp;quot;Transparent&amp;quot; Windowless=&amp;quot;true&amp;quot;&amp;nbsp; Height=&amp;quot;100%&amp;quot; Width=&amp;quot;100%&amp;quot; /&amp;gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/div&amp;gt; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/form&amp;gt; &lt;br /&gt;&amp;lt;/body&amp;gt; &lt;br /&gt;&amp;lt;/html&amp;gt; &lt;br /&gt;&lt;/font&gt;&lt;/p&gt;&lt;/font&gt;
&lt;p&gt;Adding the style to the page does the trick. Now the page displays well in IE and in Firefox.&lt;/p&gt;
&lt;p&gt;But when you are using a masterpage or have nested containers things get more elaborate. Googling on &lt;em&gt;Firefox Masterpage 100%&lt;/em&gt;&amp;nbsp; will results in loads and load of similar frustrations. For the trick to work it is not enough to just add the style to the masterpage. You have to set the width and height of &lt;strong&gt;all&lt;/strong&gt; containers around the control. Forget one and the control will still not show.&lt;/p&gt;
&lt;p&gt;Thanks everybody for helping.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://codebetter.com/aggbug.aspx?PostID=187818" width="1" height="1"&gt;</content><author><name>pvanooijen</name><uri>http://codebetter.com/members/pvanooijen/default.aspx</uri></author></entry><entry><title>Silverlight, FireFox and 100%</title><link rel="alternate" type="text/html" href="/blogs/peter.van.ooijen/archive/2008/12/18/silverlight-firefox-and-100.aspx" /><id>/blogs/peter.van.ooijen/archive/2008/12/18/silverlight-firefox-and-100.aspx</id><published>2008-12-18T14:07:59Z</published><updated>2008-12-18T14:07:59Z</updated><content type="html">&lt;p&gt;In my &lt;a href="http://codebetter.com/blogs/peter.van.ooijen/archive/2008/12/18/ajax-and-forms-authentication.aspx"&gt;last post&lt;/a&gt; I mentioned something nice about FireFox. In this post I&amp;#39;ll talk something not that nice about FireFox and the way we, more or less, worked around it.&lt;/p&gt;  &lt;p&gt;A lot of people complain about Silverlight not working in Firefox. Including myself. Our &lt;a href="http://www.codeplex.com/deepearth"&gt;DeepEarth&lt;/a&gt; page looks great in IE or Safari but in Firefox there is nothing to be seen at all. Not even an error message. There is quite a discussion on Silverlight and Firefox &lt;a href="http://silverlight.net/forums/t/6156.aspx"&gt;over here&lt;/a&gt; which branches in many directions. Thanks to Willem who spotted the one comment by &lt;a href="http://silverlight.net/members/makkros.aspx"&gt;Makkros&lt;/a&gt; which was the key to the solution.&lt;/p&gt;  &lt;p&gt;The problem with Silverlight in Firefox has all to do with sizing. Take this snippet of the webpage&lt;/p&gt;  &lt;p&gt;&lt;font color="#0000ff"&gt;&amp;lt;&lt;/font&gt;&lt;font color="#a31515"&gt;div&lt;/font&gt; &lt;font color="#ff0000"&gt;class&lt;/font&gt;&lt;font color="#0000ff"&gt;=&amp;quot;mapStyle&amp;quot;&amp;gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#0000ff"&gt;&amp;#160;&amp;#160; &amp;lt;&lt;/font&gt;&lt;font color="#a31515"&gt;asp&lt;/font&gt;&lt;font color="#0000ff"&gt;:&lt;/font&gt;&lt;font color="#a31515"&gt;Silverlight&lt;/font&gt; &lt;font color="#ff0000"&gt;ID&lt;/font&gt;&lt;font color="#0000ff"&gt;=&amp;quot;TrackingMap&amp;quot;&lt;/font&gt; &lt;font color="#ff0000"&gt;runat&lt;/font&gt;&lt;font color="#0000ff"&gt;=&amp;quot;server&amp;quot;&lt;/font&gt; &lt;font color="#ff0000"&gt;Source&lt;/font&gt;&lt;font color="#0000ff"&gt;=&amp;quot;~/ClientBin/TrackingMap.xap&amp;quot;&lt;/font&gt;&amp;#160; &lt;font color="#0000ff"&gt;/&amp;gt;&lt;/font&gt; &lt;/p&gt;  &lt;p&gt;&lt;font color="#0000ff"&gt;&amp;lt;/&lt;/font&gt;&lt;font color="#a31515"&gt;div&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;It&amp;#39;s a silverlight control enclosed in a div. As the control displays a map the best thing would be to claim as much space as available&lt;/p&gt;  &lt;p&gt;&lt;font color="#0000ff"&gt;&amp;lt;&lt;/font&gt;&lt;font color="#a31515"&gt;div&lt;/font&gt; &lt;font color="#ff0000"&gt;class&lt;/font&gt;&lt;font color="#0000ff"&gt;=&amp;quot;mapStyle&amp;quot;&amp;gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#0000ff"&gt;&amp;#160;&amp;#160; &amp;lt;&lt;/font&gt;&lt;font color="#a31515"&gt;asp&lt;/font&gt;&lt;font color="#0000ff"&gt;:&lt;/font&gt;&lt;font color="#a31515"&gt;Silverlight&lt;/font&gt; &lt;font color="#ff0000"&gt;ID&lt;/font&gt;&lt;font color="#0000ff"&gt;=&amp;quot;TrackingMap&amp;quot;&lt;/font&gt; &lt;font color="#ff0000"&gt;runat&lt;/font&gt;&lt;font color="#0000ff"&gt;=&amp;quot;server&amp;quot;&lt;/font&gt; &lt;strong&gt;&lt;font color="#ff0000"&gt;Width&lt;/font&gt;&lt;font color="#0000ff"&gt;=&amp;quot;100%&amp;quot;&lt;/font&gt; &lt;font color="#ff0000"&gt;Height&lt;/font&gt;&lt;font color="#0000ff"&gt;=&amp;quot;90%&amp;quot;&lt;/font&gt; &lt;/strong&gt;&lt;font color="#ff0000"&gt;Source&lt;/font&gt;&lt;font color="#0000ff"&gt;=&amp;quot;~/ClientBin/TrackingMap.xap&amp;quot;&lt;/font&gt; &lt;font color="#0000ff"&gt;/&amp;gt;&lt;/font&gt; &lt;/p&gt;  &lt;p&gt;&lt;font color="#0000ff"&gt;&amp;lt;/&lt;/font&gt;&lt;font color="#a31515"&gt;div&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;This works in IE and Safari (and maybe more). When the browser window is resized the control takes up all space available with the div wrapping around. &lt;/p&gt;  &lt;p&gt;Alas things work different in Firefox. Googling on&lt;em&gt; Firefox DIV 100%&lt;/em&gt; results in many many hits. Firefox first sizes the DIV and then it&amp;#39;s up to the content to use it. Resulting in content sized 0 by 0. Which comes pretty close to invisible.&lt;/p&gt;  &lt;p&gt;So you have to set the size of the control in absolute measures to see it. And resize it later on from script. &lt;/p&gt;  &lt;p&gt;&lt;font color="#0000ff"&gt;&amp;lt;&lt;/font&gt;&lt;font color="#a31515"&gt;div&lt;/font&gt; &lt;font color="#ff0000"&gt;class&lt;/font&gt;&lt;font color="#0000ff"&gt;=&amp;quot;mapStyle&amp;quot;&amp;gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#0000ff"&gt;&amp;#160;&amp;#160; &amp;lt;&lt;/font&gt;&lt;font color="#a31515"&gt;asp&lt;/font&gt;&lt;font color="#0000ff"&gt;:&lt;/font&gt;&lt;font color="#a31515"&gt;Silverlight&lt;/font&gt; &lt;font color="#ff0000"&gt;ID&lt;/font&gt;&lt;font color="#0000ff"&gt;=&amp;quot;TrackingMap&amp;quot;&lt;/font&gt; &lt;font color="#ff0000"&gt;runat&lt;/font&gt;&lt;font color="#0000ff"&gt;=&amp;quot;server&amp;quot;&lt;/font&gt; &lt;strong&gt;&lt;font color="#ff0000"&gt;Width&lt;/font&gt;&lt;font color="#0000ff"&gt;=&amp;quot;500px&amp;quot;&lt;/font&gt; &lt;font color="#ff0000"&gt;Height&lt;/font&gt;&lt;font color="#0000ff"&gt;=&amp;quot;300px&amp;quot;&lt;/font&gt;&lt;/strong&gt; &lt;font color="#ff0000"&gt;Source&lt;/font&gt;&lt;font color="#0000ff"&gt;=&amp;quot;~/ClientBin/TrackingMap.xap&amp;quot;&lt;/font&gt; &lt;font color="#0000ff"&gt;/&amp;gt;&lt;/font&gt; &lt;/p&gt;  &lt;p&gt;&lt;font color="#0000ff"&gt;&amp;lt;/&lt;/font&gt;&lt;font color="#a31515"&gt;div&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;Alas this does not solve things at all. The initial size is OK, but resizing the control will not resize the wrapping DIV. Sizing the control over it&amp;#39;s initial size will crop a part, sizing it under it&amp;#39;s original size will result in an undesired border. It requires a full page refresh to get things into proportion again.&lt;/p&gt;  &lt;p&gt;In the end I came up with this solution. Not that elegant, but it works. Any suggestions for something better are more than welcome. &lt;/p&gt;  &lt;p&gt;In the page load of the code behind the control is given it&amp;#39;s initial size. A number of pixels for FF, a percentage for the rest.&lt;/p&gt;  &lt;pre class="c-sharp" name="code"&gt;protected void Page_Load(object sender, EventArgs e)
{

    if (! IsPostBack)
    {      

        if (Request.Browser.Browser.ToLower() == &amp;quot;firefox&amp;quot;)
        {
            TrackingMap.Width = new Unit(mapWidth, UnitType.Pixel);
            TrackingMap.Height = new Unit(mapHeight, UnitType.Pixel);
            FireFoxWidth.Text = mapWidth.ToString();
            FireFoxHeight.Text = mapHeight.ToString();
            FireFoxSupport.Visible = true;
        }
        else
        {
            TrackingMap.Width = new Unit(100, UnitType.Percentage);
            TrackingMap.Height = new Unit(88, UnitType.Percentage);
        }
        
    }

}&lt;/pre&gt;

&lt;p&gt;The number of pixels for the initial size is hard to guess. The browsercapabilties always suggest a 640*480 screen. Not that useful; I have to take arbitrary values. To house it I created two properties which store the values in the session &lt;/p&gt;

&lt;pre class="c-sharp" name="code"&gt;private const string ffMapWidth = &amp;quot;FFmapWidth&amp;quot;;
private int mapWidth
{
    get
    {
        var o = Context.Session[ffMapWidth];
        if (o == null)
            return 1024;
        return int.Parse(o.ToString());
    }
    set
    {
        Context.Session[ffMapWidth] = value;
    }
}

private const string ffMapHeight = &amp;quot;FFmapHeight&amp;quot;;
private int mapHeight
{
    get
    {
        var o = Context.Session[ffMapHeight];
        if (o == null)
            return 768;
        return int.Parse(o.ToString());
    }
    set
    {
        Context.Session[ffMapHeight] = value;
    }
}&lt;/pre&gt;

&lt;p&gt;It&amp;#39;s up to the user to pick a new size for the control, that&amp;#39;s what the FireFoxSupport control is for. That has two textboxes to enter the size and a button to perform the actual resize.&lt;/p&gt;

&lt;pre class="c-sharp" name="code"&gt;protected void resizeMap(object sender, EventArgs e)
{
    try
    {
        mapWidth = int.Parse(FireFoxWidth.Text);
        mapHeight = int.Parse(FireFoxHeight.Text);
        Response.Redirect(Request.Url.ToString(), true);
    }
    catch
    {
        FireFoxWidth.Text = mapWidth.ToString();
        FireFoxHeight.Text = mapHeight.ToString();
    }
}&lt;/pre&gt;

&lt;p&gt;The new desired size is read from the textboxes and stored in the session using the properties. A complete rebuild of the page is enforced, the page load will now set the map to the desired size. And the div will wrap right because it&amp;#39;s a brand new page.&lt;/p&gt;

&lt;p&gt;I don&amp;#39;t like this very much, but at least it does work. The only other working scenario I could imagine to circumvent the user taking care of the size is forcing a page refresh after a browser resize. Which stinks even more and will still leave the problem of finding out the available room. Which is a matter of chicken and egg.&lt;/p&gt;

&lt;p&gt;I don&amp;#39;t want to get involved in any holy war on browsers or w3c but I really do believe Firefox does this completely wrong. Silverlight is not the only content suffering. &lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://codebetter.com/aggbug.aspx?PostID=186288" width="1" height="1"&gt;</content><author><name>pvanooijen</name><uri>http://codebetter.com/members/pvanooijen/default.aspx</uri></author></entry><entry><title>Ajax and forms authentication</title><link rel="alternate" type="text/html" href="/blogs/peter.van.ooijen/archive/2008/12/18/ajax-and-forms-authentication.aspx" /><id>/blogs/peter.van.ooijen/archive/2008/12/18/ajax-and-forms-authentication.aspx</id><published>2008-12-18T08:46:32Z</published><updated>2008-12-18T08:46:32Z</updated><content type="html">&lt;p&gt;Forms authentication is nice way to protect your asp.net web pages from unauthorized views. The good thing is that it shields all request for pages in your site and will redirect the request to a login page. You can set the time out of a session, after a preset period of inactivity the user has to be re-authenticated.&lt;/p&gt;  &lt;p&gt;Al done in the web.config&lt;/p&gt; &lt;font color="#0000ff"&gt;   &lt;p&gt;&amp;lt;&lt;font color="#a31515"&gt;authentication&lt;/font&gt;&lt;font color="#0000ff"&gt; &lt;/font&gt;&lt;font color="#ff0000"&gt;mode&lt;/font&gt;&lt;font color="#0000ff"&gt;=&lt;/font&gt;&amp;quot;&lt;font color="#0000ff"&gt;Forms&lt;/font&gt;&amp;quot;&lt;font color="#0000ff"&gt;&amp;gt;&lt;/font&gt; &lt;/p&gt;    &lt;p&gt;&amp;#160;&amp;#160; &amp;lt;&lt;font color="#a31515"&gt;forms&lt;/font&gt;&lt;font color="#0000ff"&gt; &lt;/font&gt;&lt;font color="#ff0000"&gt;loginUrl&lt;/font&gt;&lt;font color="#0000ff"&gt;=&lt;/font&gt;&amp;quot;&lt;font color="#0000ff"&gt;~/login.aspx&lt;/font&gt;&amp;quot;&lt;font color="#0000ff"&gt; &lt;/font&gt;&lt;font color="#ff0000"&gt;timeout&lt;/font&gt;&lt;font color="#0000ff"&gt;=&lt;/font&gt;&amp;quot;&lt;font color="#0000ff"&gt;2&lt;/font&gt;&amp;quot;&lt;font color="#0000ff"&gt;&amp;gt;&lt;/font&gt; &lt;/p&gt;    &lt;p&gt;&amp;lt;/&lt;font color="#a31515"&gt;forms&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;gt;&lt;/font&gt; &lt;/p&gt;    &lt;p&gt;&amp;lt;/&lt;font color="#a31515"&gt;authentication&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;gt;&lt;/font&gt; &lt;/p&gt;    &lt;p&gt;&amp;lt;&lt;font color="#a31515"&gt;authorization&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;gt;&lt;/font&gt; &lt;/p&gt;    &lt;p&gt;&amp;#160;&amp;#160; &amp;lt;&lt;font color="#a31515"&gt;deny&lt;/font&gt;&lt;font color="#0000ff"&gt; &lt;/font&gt;&lt;font color="#ff0000"&gt;users&lt;/font&gt;&lt;font color="#0000ff"&gt;=&lt;/font&gt;&amp;quot;&lt;font color="#0000ff"&gt;?&lt;/font&gt;&amp;quot;&lt;font color="#0000ff"&gt;/&amp;gt;&lt;/font&gt; &lt;/p&gt;    &lt;p&gt;&amp;lt;/&lt;font color="#a31515"&gt;authorization&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;gt;&lt;/font&gt;&lt;/p&gt; &lt;/font&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;The bad thing is that forms authentication does not work that well with an AJAX site. When a partial postback hits the server and the session has timed out the server will redirect the request to the login page. This is a response the AJAX request cannot handle well. The result will be an endless loop of requests and the page just hangs. Damit Dobric has a &lt;a href="http://live.mscommunity.net/blogs/damirdobric/archive/2008/08/18/ajax-callbacks-and-forms-authentication.aspx"&gt;very informative post&lt;/a&gt; on this. The good thing about Firefox is that it does detect the redirect loop and will stop. IE just keeps on trying.&lt;/p&gt;  &lt;p&gt;Damir presents a solution for the problem which does requires quite some fiddling. Here I would like to present a simpler solution.&lt;/p&gt;  &lt;p&gt;The page load of the masterpage checks if the request is the first one in the current session by inspecting the &lt;strong&gt;Session.IsNewSession &lt;/strong&gt;property. In a page shielded with forms authentication this will never be the case; posting back the login form was the first request. But when the request was issued by a partial postback in a timed out session the IsNewSession property will read true and the situation can be handled. &lt;/p&gt;  &lt;pre class="c-sharp" name="code"&gt;protected void Page_Load(object sender, EventArgs e)
{
    // Ajax postback, session timed out. Redirect 
    if (Session.IsNewSession)
    {
        FormsAuthentication.SignOut();
        Response.Redirect(&amp;quot;~/Default.aspx&amp;quot;, true);
    }
}&lt;/pre&gt;

&lt;p&gt;It explicitly signs out of FormAuthentication and redirects the user to the main page. No more loops, no more hangups.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://codebetter.com/aggbug.aspx?PostID=186280" width="1" height="1"&gt;</content><author><name>pvanooijen</name><uri>http://codebetter.com/members/pvanooijen/default.aspx</uri></author></entry><entry><title>WPF = Code + Markup (Custom pushpins for DeepEarth)</title><link rel="alternate" type="text/html" href="/blogs/peter.van.ooijen/archive/2008/12/11/wpf-code-markup-custom-pushpins-for-deepearth.aspx" /><id>/blogs/peter.van.ooijen/archive/2008/12/11/wpf-code-markup-custom-pushpins-for-deepearth.aspx</id><published>2008-12-11T12:21:22Z</published><updated>2008-12-11T12:21:22Z</updated><content type="html">&lt;p&gt;Windows Presentation Foundation has been around for a relative short while. Silverlight brings WPF to the browser, with that the amount of writings on WPF is growing fast. At the moment I&amp;#39;m working on a project which uses &lt;a href="http://www.codeplex.com/deepearth"&gt;Deep Earth&lt;/a&gt;, a very cool Silverlight based viewer on Virtual Earth (or any other map provider). Deep Earth is an open source project. Having seen the curly path of this project I want to take a closer look at separation of presentation and logic behind, being one of the fundamentals of WPF. &lt;/p&gt;  &lt;p&gt;WPF presentation is written out in markup, which is just another XML document. Logic is written out in C# (or any other .net language).&amp;#160; There are several kinds of logic like business logic and presentation logic. Business logic should be kept as far from WPF as possible but when it comes to presentation logic there are many, many ways to handle that. In markup but also In C#. And sometimes you have to cross the border, C# code manipulating markup or markup providing a hook for your C# code. I will discuss both here.&lt;/p&gt;  &lt;p&gt;As a demo I have a simple Silverligth user control. The xaml editor in VS is in it&amp;#39;s current state not that useful. My image is drawn with Expression Blend. After that I copied the markup into VS. (VS and Expression Blend can be integrated, that&amp;#39;s another story). The result looks like this.&lt;/p&gt;  &lt;p&gt;&lt;img src="http://codebetter.com/photos/peter.van.ooijen/images/185976/original.aspx" alt="" /&gt;&lt;/p&gt;  &lt;p&gt;Just an ellipse with two lines (the path elements)&lt;/p&gt;  &lt;p&gt;I want to be able to set a visual property like the line thickness from code. There are many many ways to do that. According to most sources the way to do it is using databinding in the markup. But that is quite a hassle; not only the markup required also the timing. What if I want to update the property over and over again ? The most informative story I have found was &lt;a href="http://www.west-wind.com/WebLog/posts/75854.aspx"&gt;this post by Rick Strahl&lt;/a&gt; on his frustrations. &lt;/p&gt;  &lt;p&gt;What made me see the light was laying the web aside and browsing Petzolds book &lt;a href="http://www.charlespetzold.com/wpf/index.html"&gt;Applications = code + markup&lt;/a&gt; (this post&amp;#39;s title is a tribute). That book has been critiqued by some as being not the right approach to WPF. For me it works just fine as it perfectly describes the two aspects, code and markup, and how they can communicate. I&amp;#39;m a code guy, at first sight Blend frightens me as a the tool of graphical artist. Anyway, Petzold&amp;#39;s treatment presented a simple solution.&lt;/p&gt;  &lt;p&gt;All visual elements have an optional &lt;em&gt;name&lt;/em&gt; attribute. By default Expression Blend omits it. Elements with a name do show up in the code behind; elements without one don&amp;#39;t. So after updating the XAML to&lt;/p&gt;  &lt;p&gt;&lt;font color="#0000ff"&gt;&amp;lt;&lt;/font&gt;&lt;font color="#a31515"&gt;Path&lt;/font&gt;&lt;font color="#ff0000"&gt; &lt;strong&gt;x&lt;/strong&gt;&lt;/font&gt;&lt;strong&gt;&lt;font color="#0000ff"&gt;:&lt;/font&gt;&lt;font color="#ff0000"&gt;Name&lt;/font&gt;&lt;font color="#0000ff"&gt;=&amp;quot;Line1&amp;quot;&lt;/font&gt;&lt;/strong&gt;&lt;font color="#ff0000"&gt; HorizontalAlignment&lt;/font&gt;&lt;font color="#0000ff"&gt;=&amp;quot;Left&amp;quot;&lt;/font&gt;&lt;font color="#ff0000"&gt; Margin&lt;/font&gt;&lt;font color="#0000ff"&gt;=&amp;quot;163.401&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#0000ff"&gt;&amp;lt;&lt;/font&gt;&lt;font color="#a31515"&gt;Path&lt;/font&gt;&lt;font color="#ff0000"&gt; x&lt;/font&gt;&lt;strong&gt;&lt;font color="#0000ff"&gt;:&lt;/font&gt;&lt;font color="#ff0000"&gt;Name&lt;/font&gt;&lt;font color="#0000ff"&gt;=&amp;quot;Line2&amp;quot;&lt;/font&gt;&lt;/strong&gt;&lt;font color="#ff0000"&gt; HorizontalAlignment&lt;/font&gt;&lt;font color="#0000ff"&gt;=&amp;quot;Left&amp;quot;&lt;/font&gt;&lt;font color="#ff0000"&gt; Margin&lt;/font&gt;&lt;font color="#0000ff"&gt;=&amp;quot;158.222&lt;/font&gt;&lt;font color="#0000ff"&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;I can access the lines from code behind.&lt;/p&gt;  &lt;pre class="c-sharp" name="code"&gt;public partial class MyFancySilverlightControl : UserControl
{
    public MyFancySilverlightControl()
    {
        InitializeComponent();
    }

    public void ChangeLine(Color color, double thickness)
    {
        Line1.Stroke = new SolidColorBrush(color);
        Line1.StrokeThickness = thickness;
    }
}&lt;/pre&gt;

&lt;p&gt;The next thing I want to do is use my usercontrols in DeepEarth. DeepEarth does have a nice collection of shape controls to place on a map. Things like polygons to outline a region and pushpins to mark a position. Here the vector graphics used by WPF really shine. For example you can zoom in on a map and outline a city boundary in every detail using a Polygon shape. Zoom out and the boundaries melt into a small dot. Zoom in again and every detail is still there. Imagine doing that with bitmaps..&lt;/p&gt;

&lt;p&gt;In the newest version the content of the different shapes is defined in markup templates. The basic markup of a shape is straightforward&lt;/p&gt;

&lt;p&gt;&lt;font color="#0000ff"&gt;&amp;lt;&lt;/font&gt;&lt;font color="#a31515"&gt;Style&lt;/font&gt;&lt;font color="#ff0000"&gt; TargetType&lt;/font&gt;&lt;font color="#0000ff"&gt;=&amp;quot;DeepShapes:GeometryBase&amp;quot;&amp;gt;&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;&lt;font color="#0000ff"&gt;&amp;lt;&lt;/font&gt;&lt;font color="#a31515"&gt;Setter&lt;/font&gt;&lt;font color="#ff0000"&gt; Property&lt;/font&gt;&lt;font color="#0000ff"&gt;=&amp;quot;Template&amp;quot;&amp;gt;&lt;/font&gt;&lt;/p&gt;
&lt;font color="#a31515"&gt;
  &lt;p&gt;&lt;/p&gt;
  &lt;font color="#0000ff"&gt;&amp;lt;&lt;/font&gt;&lt;font color="#a31515"&gt;Setter.Value&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;gt;&lt;/font&gt; &lt;/font&gt;&lt;font color="#a31515"&gt;
  &lt;p&gt;&lt;/p&gt;
  &lt;font color="#0000ff"&gt;&amp;lt;&lt;/font&gt;&lt;font color="#a31515"&gt;ControlTemplate&lt;/font&gt;&lt;font color="#ff0000"&gt; TargetType&lt;/font&gt;&lt;font color="#0000ff"&gt;=&amp;quot;DeepShapes:GeometryBase&amp;quot;&amp;gt;&lt;/font&gt; &lt;/font&gt;&lt;font color="#a31515"&gt;
  &lt;p&gt;&lt;/p&gt;
  &lt;font color="#0000ff"&gt;&amp;lt;&lt;/font&gt;&lt;font color="#a31515"&gt;Canvas&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;gt;&lt;/font&gt; &lt;/font&gt;&lt;font color="#a31515"&gt;
  &lt;p&gt;&lt;/p&gt;
  &lt;font color="#0000ff"&gt;&amp;lt;&lt;/font&gt;&lt;font color="#a31515"&gt;Path&lt;/font&gt;&lt;font color="#ff0000"&gt; x&lt;/font&gt;&lt;font color="#0000ff"&gt;:&lt;/font&gt;&lt;font color="#ff0000"&gt;Name&lt;/font&gt;&lt;font color="#0000ff"&gt;=&amp;quot;path&amp;quot;/&amp;gt;&lt;/font&gt; &lt;/font&gt;&lt;font color="#a31515"&gt;
  &lt;p&gt;&lt;/p&gt;
  &lt;font color="#0000ff"&gt;&amp;lt;/&lt;/font&gt;&lt;font color="#a31515"&gt;Canvas&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;gt;&lt;/font&gt; &lt;/font&gt;&lt;font color="#a31515"&gt;
  &lt;p&gt;&lt;/p&gt;
  &lt;font color="#0000ff"&gt;&amp;lt;/&lt;/font&gt;&lt;font color="#a31515"&gt;ControlTemplate&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;gt;&lt;/font&gt; &lt;/font&gt;&lt;font color="#a31515"&gt;
  &lt;p&gt;&lt;/p&gt;
  &lt;font color="#0000ff"&gt;&amp;lt;/&lt;/font&gt;&lt;font color="#a31515"&gt;Setter.Value&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;gt;&lt;/font&gt; &lt;/font&gt;&lt;font color="#a31515"&gt;
  &lt;p&gt;&lt;/p&gt;
  &lt;font color="#0000ff"&gt;&amp;lt;/&lt;/font&gt;&lt;font color="#a31515"&gt;Setter&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;gt;&lt;/font&gt; &lt;/font&gt;&lt;font color="#a31515"&gt;
  &lt;p&gt;&lt;/p&gt;
  &lt;font color="#0000ff"&gt;&amp;lt;/&lt;/font&gt;&lt;font color="#a31515"&gt;Style&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;gt;&lt;/font&gt;&lt;/font&gt; 

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;A shape basically contains a single path (line). The template for a pushpin also contains a lot of fancy markup building the image of the pin. The WPF method OnApplyTemplate instantiates the shape. In overrides of this method the DeepEarth classes take further care of the correct size and position of the control on the map. &lt;/p&gt;

&lt;p&gt;On a map usercontrols are like pushpins, an image of some kind placed on a certain location. A first shot would be to subclass the DeepEarth Pushpin class and add the markup of my pushpins to the templates of DeepEarth. But that would not be very flexible; in such a scenario every new control requires fiddling with the DeepEarth core assemblies. Besides that it would be hard again to set control properties from code.&lt;/p&gt;

&lt;p&gt;Again, working from code provides a solution. And here the markup in the template provides a base for the code. I have added one new class to the DeepEarth shapes, a UserControlHost. This is it&amp;#39;s markup&lt;/p&gt;
&lt;font color="#a31515"&gt;
  &lt;p&gt;&lt;/p&gt;
  &lt;font color="#0000ff"&gt;&amp;lt;&lt;/font&gt;&lt;font color="#a31515"&gt;Style&lt;/font&gt;&lt;font color="#ff0000"&gt; TargetType&lt;/font&gt;&lt;font color="#0000ff"&gt;=&amp;quot;DeepShapes:UserControlHost&amp;quot;&amp;gt;&lt;/font&gt;&lt;/font&gt;&lt;font color="#a31515"&gt; 
  &lt;p&gt;&lt;/p&gt;
  &lt;font color="#0000ff"&gt;&amp;lt;&lt;/font&gt;&lt;font color="#a31515"&gt;Setter&lt;/font&gt;&lt;font color="#ff0000"&gt; Property&lt;/font&gt;&lt;font color="#0000ff"&gt;=&amp;quot;RenderTransformOrigin&amp;quot;&lt;/font&gt;&lt;font color="#ff0000"&gt; Value&lt;/font&gt;&lt;font color="#0000ff"&gt;=&amp;quot;0.5,0.5&amp;quot; /&amp;gt;&lt;/font&gt; &lt;/font&gt;&lt;font color="#a31515"&gt;
  &lt;p&gt;&lt;/p&gt;
  &lt;font color="#0000ff"&gt;&amp;lt;&lt;/font&gt;&lt;font color="#a31515"&gt;Setter&lt;/font&gt;&lt;font color="#ff0000"&gt; Property&lt;/font&gt;&lt;font color="#0000ff"&gt;=&amp;quot;AnchorPoint&amp;quot;&lt;/font&gt;&lt;font color="#ff0000"&gt; Value&lt;/font&gt;&lt;font color="#0000ff"&gt;=&amp;quot;0.5,0.5&amp;quot; /&amp;gt;&lt;/font&gt; &lt;/font&gt;&lt;font color="#a31515"&gt;
  &lt;p&gt;&lt;/p&gt;
  &lt;font color="#0000ff"&gt;&amp;lt;&lt;/font&gt;&lt;font color="#a31515"&gt;Setter&lt;/font&gt;&lt;font color="#ff0000"&gt; Property&lt;/font&gt;&lt;font color="#0000ff"&gt;=&amp;quot;Template&amp;quot;&amp;gt;&lt;/font&gt; &lt;/font&gt;&lt;font color="#a31515"&gt;
  &lt;p&gt;&lt;/p&gt;
  &lt;font color="#0000ff"&gt;&amp;lt;&lt;/font&gt;&lt;font color="#a31515"&gt;Setter.Value&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;gt;&lt;/font&gt; &lt;/font&gt;&lt;font color="#a31515"&gt;
  &lt;p&gt;&lt;/p&gt;
  &lt;font color="#0000ff"&gt;&amp;lt;&lt;/font&gt;&lt;font color="#a31515"&gt;ControlTemplate&lt;/font&gt;&lt;font color="#ff0000"&gt; TargetType&lt;/font&gt;&lt;font color="#0000ff"&gt;=&amp;quot;DeepShapes:UserControlHost&amp;quot;&amp;gt;&lt;/font&gt; &lt;/font&gt;&lt;font color="#a31515"&gt;
  &lt;p&gt;&lt;/p&gt;
  &lt;font color="#0000ff"&gt;&amp;lt;&lt;/font&gt;&lt;font color="#a31515"&gt;Grid&lt;/font&gt;&lt;font color="#ff0000"&gt; x&lt;/font&gt;&lt;font color="#0000ff"&gt;:&lt;/font&gt;&lt;font color="#ff0000"&gt;Name&lt;/font&gt;&lt;font color="#0000ff"&gt;=&amp;quot;LayoutRoot&amp;quot;&lt;/font&gt;&lt;font color="#ff0000"&gt; OpacityMask&lt;/font&gt;&lt;font color="#0000ff"&gt;=&amp;quot;#FF000000&amp;quot;&lt;/font&gt;&lt;font color="#ff0000"&gt; Background&lt;/font&gt;&lt;font color="#0000ff"&gt;=&amp;quot;#00000000&amp;quot;&amp;gt;&lt;/font&gt; &lt;/font&gt;&lt;font color="#a31515"&gt;
  &lt;p&gt;&lt;/p&gt;
  &lt;font color="#0000ff"&gt;&amp;lt;/&lt;/font&gt;&lt;font color="#a31515"&gt;Grid&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;gt;&lt;/font&gt; &lt;/font&gt;&lt;font color="#a31515"&gt;
  &lt;p&gt;&lt;/p&gt;
  &lt;font color="#0000ff"&gt;&amp;lt;/&lt;/font&gt;&lt;font color="#a31515"&gt;ControlTemplate&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;gt;&lt;/font&gt; &lt;/font&gt;&lt;font color="#a31515"&gt;
  &lt;p&gt;&lt;/p&gt;
  &lt;font color="#0000ff"&gt;&amp;lt;/&lt;/font&gt;&lt;font color="#a31515"&gt;Setter.Value&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;gt;&lt;/font&gt; &lt;/font&gt;&lt;font color="#a31515"&gt;
  &lt;p&gt;&lt;/p&gt;
  &lt;font color="#0000ff"&gt;&amp;lt;/&lt;/font&gt;&lt;font color="#a31515"&gt;Setter&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;gt;&lt;/font&gt; &lt;/font&gt;&lt;font color="#a31515"&gt;
  &lt;p&gt;&lt;/p&gt;
  &lt;font color="#0000ff"&gt;&amp;lt;/&lt;/font&gt;&lt;font color="#a31515"&gt;Style&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;gt;&lt;/font&gt;&lt;/font&gt; 

&lt;p&gt;Instead of a path the template declares a named grid. The nice thing about a grid control is that other controls can be added to its &lt;em&gt;Children&lt;/em&gt;. And that&amp;#39;s just what I do when applying the template&lt;/p&gt;

&lt;pre class="c-sharp" name="code"&gt;namespace DeepEarth.Shapes
{
    public class UserControlHost : Pushpin
    {

        private readonly UserControl hostedControl;

        public UserControlHost(UserControl hostedControl)
        {
            DefaultStyleKey = typeof(UserControlHost);
            this.hostedControl = hostedControl;
        }


        public override void OnApplyTemplate()
        {
            ((Grid) GetTemplateChild(&amp;quot;LayoutRoot&amp;quot;)).Children.Add(hostedControl);
            base.OnApplyTemplate();
        }

    }
}&lt;/pre&gt;

&lt;p&gt;The usercontrol is passed in the constructor.&amp;#160; In the overriden &lt;em&gt;OnApplyTemplate&lt;/em&gt; the grid is grabbed using the &lt;em&gt;GetTemplateChild&lt;/em&gt; method and the usercontrol is added to its &lt;em&gt;Children&lt;/em&gt;. After that &lt;em&gt;OnApplyTemplate&lt;/em&gt; of the &lt;em&gt;PushPin&lt;/em&gt; base class is fired. It takes care of all the sizing and positioning work. To that method there is no difference between xaml from the original template or xaml from injected usercontrol.&lt;/p&gt;

&lt;p&gt;The UserControlHost class is just another shape like a polyline, polygon or the default pushpin. And you can do all the same things with it, like adding it to layers. This way you can host any UserControl in DeepEarth. This snippet will look familiar to anybody working with DeepEarth&lt;/p&gt;

&lt;pre class="c-sharp" name="code"&gt;UserControl visual;
if (isCurrentPosition)
    visual = new ShipVisual(shipColor, (double) clusteredWp.Course);
else
    visual = new PushpinVisual();

var pin = new UserControlHost(visual);

pin.Point = new Point(clusteredWp.Longitude, clusteredWp.Latitude);
wayPointLayer.Shapes.Add(pin);&lt;/pre&gt;

&lt;p&gt;That&amp;#39;s it. I hope to have demonstrated that in WPF the border between markup and code is somewhat flexible. Both aspects are very powerful and they can really help each other. Separate well and rule (the deep earth).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://codebetter.com/aggbug.aspx?PostID=185979" width="1" height="1"&gt;</content><author><name>pvanooijen</name><uri>http://codebetter.com/members/pvanooijen/default.aspx</uri></author><category term="Coding" scheme="http://codebetter.com/blogs/peter.van.ooijen/archive/tags/Coding/default.aspx" /></entry><entry><title>Ubiquitous language, not only in your customer's domains</title><link rel="alternate" type="text/html" href="/blogs/peter.van.ooijen/archive/2008/11/25/ubiquitous-language-not-only-in-your-customer-s-domains.aspx" /><id>/blogs/peter.van.ooijen/archive/2008/11/25/ubiquitous-language-not-only-in-your-customer-s-domains.aspx</id><published>2008-11-25T20:52:40Z</published><updated>2008-11-25T20:52:40Z</updated><content type="html">&lt;p&gt;In the hart of domain driven design is ubiquitous language. Everyone involved, from developer to domain expert, speaks the same language. This should not be just a matter of using the same labels for &amp;quot;things&amp;quot;. Many a discussion starts with the question how to name something and leads to a shared analysis of what that thing really is. In the end (of that discussion) the resulting name is well chosen and has a deeper meaning.&lt;/p&gt;  &lt;p&gt;But when it comes to naming things in the domain of software development I often see a not so ubiquitous language. To name just two of today&amp;#39;s hobby horses: both the &lt;em&gt;IoC/DI&lt;/em&gt; label and the &lt;em&gt;TDD/BDD&lt;/em&gt; label are used for a diversity of &amp;quot;things&amp;quot;. &lt;a href="http://www.martinfowler.com/articles/injection.html"&gt;IoC and DI&lt;/a&gt; are not quite the same thing. But when it comes to naming techniques, designs, architectures or frameworks all to often the full label IoC/DI is applied. This almost reads as IoC aka DI, suggesting two different names for one and the same &amp;quot;thing&amp;quot;. Whatever that thing is. It could be a framework implementing an IoC container or a design decision to use the DI pattern. Good articles on the subject describe the similarities and the differences between DI and IoC. Only the best take it a step further and use one name for one thing and suggest clear names rich in meaning for all other things. &lt;/p&gt;  &lt;p&gt;The same story more or less applies to TDD/BDD. On the bright side &lt;a href="http://codebetter.com/blogs/matthew.podwysocki/default.aspx"&gt;Matthew Podwysocki&lt;/a&gt; just published a &lt;a href="http://codebetter.com/blogs/matthew.podwysocki/archive/2008/11/25/code-contracts-dbc-in-a-tdd-world.aspx"&gt;very good post&lt;/a&gt; on defining BDD as compared to TDD. So next time you read the label TDD/BDD just read that post again. And don&amp;#39;t get me started on naming products. Microsoft almost makes a habit of names like &amp;quot;WCF formerly known as Indigo&amp;quot;. I&amp;#39;ve been &lt;a href="http://petersgekko.codebetter.com/blogs/peter.van.ooijen/archive/2006/06/14/146403.aspx"&gt;ranting on that&lt;/a&gt; before. &lt;/p&gt;  &lt;p&gt;The domain of building software is one of the most complex domains you can imagine. Imho it would be beneficial to everybody to be as clear as possible in naming things here. What works for our customers will work for ourselves as well.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://codebetter.com/aggbug.aspx?PostID=185307" width="1" height="1"&gt;</content><author><name>pvanooijen</name><uri>http://codebetter.com/members/pvanooijen/default.aspx</uri></author></entry><entry><title>Interoperability with a Java (Axis) web service</title><link rel="alternate" type="text/html" href="/blogs/peter.van.ooijen/archive/2008/11/13/interoperability-with-a-java-axis-web-service.aspx" /><id>/blogs/peter.van.ooijen/archive/2008/11/13/interoperability-with-a-java-axis-web-service.aspx</id><published>2008-11-13T07:53:09Z</published><updated>2008-11-13T07:53:09Z</updated><content type="html">&lt;p&gt;In my current project we are communicating with an external web service which is implemented in Java using Axis. This service returns arrays containing &amp;quot;nillable&amp;quot; integers. When generating the proxies in WCF or asp.net webservices these translate to nullable ints. So far so good.&lt;/p&gt;  &lt;p&gt;The problem was that every nullable int in an array &lt;em&gt;always&lt;/em&gt; returned null. A nullable element in the root of a return message did contain a value. Things got more confusing when my collegue, who uses Borland C++ builder to&amp;#160; consume the service, could read values. Even more so because C++ does not have any nullable types.&lt;/p&gt;  &lt;p&gt;Googling around revealed that this is a problem more people have with web services implemented with Axis. Using all kinds of tools to consume such a service. What I want to share is this gem in the search results. In a &lt;a href="http://www.tomergabel.com/GettingWCFAndApacheAxisToBeFriendly.aspx"&gt;small and very clear post&lt;/a&gt; Tomer Gabel explains what is going on and also presents a very simple solution. Read the article and be amazed. The solution is flipping one flag in the Axis server config. Our service provider did that and now everything is working fine. Though C++ still doesn&amp;#39;t have any nullable types :)&lt;/p&gt;  &lt;p&gt;I&amp;#39;m no Java expert at all but it works on our machine :)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://codebetter.com/aggbug.aspx?PostID=184972" width="1" height="1"&gt;</content><author><name>pvanooijen</name><uri>http://codebetter.com/members/pvanooijen/default.aspx</uri></author></entry></feed>