sharing about .NET and technology RSS 2.0
 Thursday, January 25, 2007

In some enterprise applications you need to show geographical data such as countries and postcodes. Most of the time you need it for a registration page, where the user need to fill in the country and postcode/area.

Geonames is a free geographical database that contains over 8 million geographical names and it can be accessed through a number of webservices. For example the url http://ws.geonames.org/countryInfo? gives an xml with all countries, whereas the following request http://ws.geonames.org/postalCodeSearch?placename=be gives us all postcodes for a particular country (e.g. Belgium).

Most likely you need two dropdown lists, one for countries and one for postcodes, where the postcode dropdown is dependent from the country dropdown list. This is a very good example to introduce AJAX by using the CascadingDropdown that is included in ASP.NET AJAX.

To implement this functionality we need to implement two methods on a webservice, namely GetCountries and GetPostalCodesByCountry. The GetCountries simply returns all countries sorted by name and looks like this:

GeonamesService.asmx.cs - Copy Code
[WebMethod] public CascadingDropDownNameValue[] GetCountries() { List<CascadingDropDownNameValue> list = new List<CascadingDropDownNameValue>(); CountryItemCollection countries = IStaySharp.Geonames.GeonamesService.GetAllCountries(); for (int i = 0; i < countries.Countries.Length; i++) { list.Add(new CascadingDropDownNameValue( countries.Countries[i].CountryName, countries.Countries[i].CountryCode)); } list.Sort(CompareCascadingDropDownNameValueByName); return list.ToArray(); }

Note that the list need to be converted to an array of CascadingDropDownNameValue objects. Note that we also sort the list by implementing a delegate named CompareCascadingDropDownNameValueByName.

GeonamesService.asmx.cs - Copy Code
private static int CompareCascadingDropDownNameValueByName(CascadingDropDownNameValue x, CascadingDropDownNameValue y) { if (x == null && y == null) return 0; else if (x == null && y != null) return -1; else if (x != null && y == null) return 1; else return x.name.CompareTo(y.name); }

The other webservice method, called GetPostalCodesByCountry, need to retrieve all postcodes for a particular country. The signature of the method is very strict. The parameter names must be named 'knownCategoryValues' and 'category', otherwise it will fail!

GeonamesService.asmx.cs - Copy Code
[WebMethod] public CascadingDropDownNameValue[] GetPostalCodesByCountry(string knownCategoryValues, string category) { List<CascadingDropDownNameValue> list = new List<CascadingDropDownNameValue>(); StringDictionary kv = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues); if (kv.ContainsKey("Country")) { string countryName = kv["Country"]; PostalCodeItemCollection postalCodes = IStaySharp.Geonames.GeonamesService.GetPostalCodes(countryName); for (int i = 0; i < postalCodes.PostalCodes.Length; i++) { list.Add(new CascadingDropDownNameValue( string.Format("{0} ({1})", postalCodes.PostalCodes[i].PostalCode, postalCodes.PostalCodes[i].Name), postalCodes.PostalCodes[i].PostalCode)); } } list.Sort(CompareCascadingDropDownNameValueByName); return list.ToArray(); }

In order to complete the webservice, the attribute ScriptService (line 3) need to be included so that a client javascript proxy can be generated. You can test this by calling your webservice like this http://localhost:9999/GeonamesService.asmx/js.

GeonamesService.asmx.cs - Copy Code
1 [WebService(Namespace = "http://tempuri.org/")] 2 [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] 3 [System.Web.Script.Services.ScriptService()] 4 public class GeonamesService : System.Web.Services.WebService 5 { 6 ... 7 }

Finally we only need to add two CascadingDropDown controls on our aspx page with the following settings:

Default.aspx - Copy Code
<asp:ScriptManager ID="scriptManager" runat="server" /> <asp:DropDownList ID="countriesDropDown" runat="server"/> <ajaxToolkit:CascadingDropDown ID="countriesCascadingDropDown" TargetControlID="countriesDropDown" Category="Country" PromptText="Please select a country" LoadingText="[Loading countries...]" ServicePath="/GeonamesService.asmx" ServiceMethod="GetCountries" runat="server"/> <br/><br/> <asp:DropDownList ID="postalCodesDropDown" runat="server"/> <ajaxToolkit:CascadingDropDown ID="postalCodesCascadingDropDown" TargetControlID="postalCodesDropDown" Category="PostalCode" PromptText="Please select postalcode" LoadingText="[Loading postalcodes...]" ServicePath="GeonamesService.asmx" ServiceMethod="GetPostalCodesByCountry" ParentControlID="countriesDropDown" runat="server"/>

The source code can be downloaded here: IStaySharp.AJAXSample.rar (332,56 KB)

Thursday, January 25, 2007 2:13:28 AM (Romance Standard Time, UTC+01:00)  #    Comments [1] -
 | 
 Friday, August 18, 2006

Windows Live Writer is a desktop application that makes it easier to compose compelling blog posts using Windows Live Spaces or your current blog service. For Windows Live Writer I created a plugin called SyntaxColor4Writer that enables you to embed syntax highlighting in your blog posts. More details about SyntaxColor4Writer can be found here. This is how the plugin looks:

This is an example of a xml fragment generated by SyntaxColor4Writer:

<system.web> <compilation defaultLanguage="VB" debug="true" /> <customErrors mode="RemoteOnly" /> </system.web>

 

Friday, August 18, 2006 2:17:50 AM (Romance Standard Time, UTC+01:00)  #    Comments [0] -
 |  | 
 Thursday, April 06, 2006

I am planning to install MediaWiki for my site www.istaysharp.net. This way I can easily add/update content, because currently the site is static, and that's thre reason why it's not updated frequently.

It was planned for this evening to update www.istaysharp.net, but a new version has been released of MediaWiki, version 1.6.1. I hope the upgrade will go smooth and that my code will still work :)

One other interesting point, is that apparently there is an experimental support for connecting to an Oracle database (read release notes). Are there any plans for supporting MS SQL Server 2000? If so, please let me know!!!

Thursday, April 06, 2006 7:51:19 PM (Romance Standard Time, UTC+01:00)  #    Comments [0] -
 | 
 Thursday, March 09, 2006

Modern GPUs are increasing in programmability and these chips can do more than just graphical computations. They can now be used as a coprocessor, and they can be integrated for a set of tasks. GPGPU (General-Purpose compuation on GPUs) is such an initiative that contains a catalog where the GPU can be used for general-purpose computation.

The big challenge, is to translate the everyday applications to two-dimensional graphic functions, like texture mapping. In other words: Pretend that everything is a game (source). 

As an example in this article and results, a quicksort algorithm of 18 million records in Visual C++ took 21 seconds, while the GPU took 2 seconds! What are the results for a Quad SLI setup? ;-)

Microsoft research is apparently working on a system that simplifies the programming of GPU to general-purpose tasks, it's called Accelerator (simplified programming of graphics processing units for general-purpose uses via data-parallelism).

Thursday, March 09, 2006 12:41:25 AM (Romance Standard Time, UTC+01:00)  #    Comments [0] -
 |  | 
 Friday, March 03, 2006

Wikipedia is the biggest and most famous online encyclopedia available. They have now more than 1 million articles, and it's still growing! This page gives you an idea about the architecture and the specification of the servers. The master database, called Samuel, contains all articles and has about a capacity of 400GB. Here you can monitor the wiki servers.

Friday, March 03, 2006 1:47:37 AM (Romance Standard Time, UTC+01:00)  #    Comments [0] -
 | 
 Wednesday, February 01, 2006

Internet Explorer 7 Beta 2 has been released to the public, and can be downloaded here. I installed IE7 on a clean WinXP SP2 without any problems through VPC. My blog site and IStaySharp.NET rendered correctly with IE7.

The coolest feature I found, is the integrated rss reader...

Wednesday, February 01, 2006 2:04:57 AM (Romance Standard Time, UTC+01:00)  #    Comments [2] -
 | 
 Wednesday, October 26, 2005

LAME is a very popular LGPL MP3 encoder. For a long time LAME version 3.90.X was recommended, now version 3.97b has been released. This version uses the -V setting, with a value from 0 (highest) till 9 (lowest) quality in VBR. More details about these settings can be found here.

Instead of lossy compressions like MP3, there are also losless codecs like FLAC (Free Losless Audio Coded). No quality is lost, but the file size is much bigger. Here are some results in applying the above settings on a regular audio cd:

Setting File size Remark
WAV 721 MB losless, uncompressed
FLAC 405 MB losless, level 9 (highest)
LAME -b 320 163 MB lossy, CBR 320, highest possible quality
LAME -V 0 105 MB lossy, VBR
LAME -V 0 --vbr-new 102 MB lossy, VBR but another algorithm (better quality and smaller)


You can assume that with the settings used here you cannot distinguish the mp3 from the original cd. A very good resource about audio, codecs and tests is Hydrogenaudio . This graph gives a nice relationship between the file size and audio quality for the LAME encoder.  Between V0 and CBR320 setting, you see the file size increases by 50%, whereas the quality does not increase as much as that.

Wednesday, October 26, 2005 12:30:15 AM (Romance Standard Time, UTC+01:00)  #    Comments [0] -
 | 
 Thursday, September 08, 2005

The RealDN site, a blog site where employees of Real Software share their knowledge about technology, has been updated.

 

Thursday, September 08, 2005 12:59:39 AM (Romance Standard Time, UTC+01:00)  #    Comments [0] -
 | 
 Friday, May 06, 2005

It' s a pub located in Clearfield and it has a website.
Some more pictures can be found here.

Does such a pub exists near Belgium? Please let me know :-)

Friday, May 06, 2005 10:31:12 PM (Romance Standard Time, UTC+01:00)  #    Comments [0] -

 Tuesday, October 26, 2004

Apple announced today that iTunes is now available in Austria, Belgium, Finland, Greece, Italy, Luxembourg, Netherlands, Portugal and Spain for €0.99 per song from a database of 700,000 songs.

Tuesday, October 26, 2004 10:53:34 PM (Romance Standard Time, UTC+01:00)  #    Comments [0] -

 Tuesday, July 27, 2004

This was a nice surprise, KITT from the famous TV series Knight Rider is for sale on eBay! 
The item on eBay can be found here, it starts from $40,000.00 :-)

Apparently there is also a Knight Con 2004 in August 20th till August 22nd in the Theme Park Warner Bros. Movieworld in Bottrop–Kirchhellen (Germany).

Tuesday, July 27, 2004 10:08:32 PM (Romance Standard Time, UTC+01:00)  #    Comments [0] -

Archive
<September 2008>
SunMonTueWedThuFriSat
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2008
Christoph De Baene
Sign In
Statistics
Total Posts: 141
This Year: 12
This Month: 0
This Week: 0
Comments: 134
All Content © 2008, Christoph De Baene
DasBlog theme 'Business' created by Christoph De Baene (delarou)