Galin Iliev's blog

Software Architecture & Development

MIXUK 07 Sessions

MIXUK 07 recorded sessions are made public - you can see them at 

Note: At Day 2 there are two sessions of ScottG that cannot be missed if you want to catch up with all fancy stuff that coming in VS 2008

And of course the videos are streamed through Sivlerlight video player... Did you expected somethig else :) And very conviniently you can download them in .zip format for offline view

Open Source @ Microsoft

On the latest MSDN newsletter was announced new Open Source site. Although BillG and Microsoft are notorious by demanding software to be paid we see dramatic changes in recent years. MS opened a number of sites to host open source projects like GotDotNet, CodePlex, and now this one.  

Having in mind the fact that .NET Framework source code will be open (together with debug symbols) MS is not that evil :), isn't it?

And some facts about business guys (and enterpreneuers ): I read a short news that says that for every $1 income for Microsoft there are $14 for partner ecosystem( here is full story in Bulgarian). Here are similar numbers in English. So from economic standpoint it is not bad to be part of this ecosystem.

So what you think?

How to enable IIS7 Integrated Pipeline mode

IIS7 has been made alive with Windows Vista (full server release will be with Windows Server 2008) and offers many new features. You can read about them at One of the most exciting features was option to extend IIS using ASP.NET and managed code or so called to "plug into integrated pipeline mode".

So far I was able to run ASP.NET sites using application Classic .NET App Pool. But so far I wasn't able to utilize Integrated pipeline mode.

By setting Managed pipeline mode to Integrated causes my app stop working with terrible error.

Although the message in event log I wasn't able to find a solution although good message:

A request mapped to aspnet_isapi.dll was made within an application pool running in Integrated .NET mode. Aspnet_isapi.dll can only be used when running in Classic .NET mode. Please either specify preCondition="ISAPImode" on the handler mapping to make it run only in application pools running in Classic .NET mode, or move the application to another application pool running in Classic .NET mode in order to use this handler mapping.

Well... the error is in aspnet_isapi.dll. So let's remove ISAPI related modules from modules section

After this operation I got Error 500

HTTP Error 500.0 - Internal Server Error
Description: Handler "AboMapperCustom-76525" has a bad module "IsapiModule" in its module list

So the next step is to remove all Handler Mappings that are mapped to IsapiFilter

And ... voila.. this was it...

Hope you'll find this helpful.

1st and 2nd chance exceptions

On last Sofia.NET UG meeting were discussed also first and second chance exceptions which was new to me. Here is what MS Knowledge Base says on the subject:

"When an exception is raised, the handler may correct or ignore the condition rather than allow a failure to propagate up through intervening layers. This is very useful in complex environments such as networks where partial failures are expected and it is not desirable to fail an entire operation just because one of several optional parts failed. In this case, the exception can be handled so that the application does not recognize that an exception has occurred.

However, if the application is being debugged, the debugger sees all exceptions before the program does. This is the distinction between the first and second chance exception: the debugger gets the first chance to see the exception (hence the name). If the debugger allows the program execution to continue and does not handle the exception, the program will see the exception as usual. If the program does not handle the exception, the debugger gets a second chance to see the exception. In this latter case, the program normally would crash if the debugger were not present."

Empty Database for Production

It is common to test data-driven applications with dummy data to test if everythign works fine. Once it is done the easiest way to start using in production is to recreate database. In case you have real lookup data in some of the tables (as predefined user, user groups, security rights and etc) you have to script them too.

There is another way though: just clear dummy data. As we know it can be done with T-SQL DELETE statement. Unfortunately this doesnt reset autonumber fields. So if you have Autonumber columns in your tables you have two choices:

  • run TRUNCATE TABLE statement - you can use this only if there are no contrains and foreign keys related with this table
  • or delete all data and reset autonumber field (back to 1) with the following statements:
       1:  DELETE FROM tblName
       2:  DBCC CHECKIDENT (tblName, RESEED, 0)

Hope this helps

How to insert record to DB using Javascript and Astoria Service

I wrote several posts regarding Astoria Services and in this one I will demonstrate how to insert reocord in database using AJAX calls.

Read my previous post - How to consume Astoria Service - in order to get deeper into solution environment.

I extended Javascript code so there is one more function that add new record to database. As it is for demostration purposes excuse hard-coded values, please.

So in order to add new record you need:

  • to create and instanciate variable with appropriate JSON format. Be careful here! All required fields from DB must present and have valid values.
  • set HTTP POST verb to the request.
  • set URL that point to root of entity type (Customer in our case)
  • set Request's headers "Accept" AND "Content-Type" to "application/json"
    wRequest.get_headers()["Accept"] = "application/json";
    wRequest.get_headers()["Content-Type"] = "application/json";
  • set request body's content with serialized variable content.

and finally call Invoke() method.

Here is full function:

   1:  function createNewCustomer(custID, contactName, companyName)
   2:  {
   3:      //create new item
   4:      var customer = {__metadata: {Type:"Customer" },
   5:          CustomerID:custID ,ContactName: contactName, CompanyName: companyName, ContactTitle:"", Address:"", City:""
   6:          , Region:"", PostalCode:"", Country:"", Phone:"", Fax:"" };
   8:      //save item to server using Astoria Service
   9:      var wRequest =  new Sys.Net.WebRequest();
  10:      wRequest.set_httpVerb("POST");
  11:      wRequest.set_url("http://galcho-pc:86/northwind.svc/Customers"); 
  13:      wRequest.get_headers()["Accept"] = "application/json";
  14:      wRequest.get_headers()["Content-Type"] = "application/json";
  15:      wRequest.add_completed(function (response, eventArgs){
  16:          var statusText = response.get_statusText();
  17:          alert(statusText);
  18:      });
  20:      wRequest.set_body(Sys.Serialization.JavaScriptSerializer.serialize(customer));
  21:      wRequest.invoke();
  22:  }

And the button that execute is defined with following HTML

<input type="button" value="New Customers" onclick="createNewCustomer('AAAA','Galin Iliev', 'Galcho.COM');" />

Hope you find it interesting.

UPDATE: Here is sample project: (191.09 KB)

In order to run sample project do following:

  • make sure you installed the packages stated here.
  • extract files and modify Connection string NorthingEntites in web.config to match your SQL server that run Northwind DB
  • when running the sample make sure the URL in browser's address bar contain same hostname as in astoriaUrl JS variable (Default.aspx line 29) otherwise you will get "Access Denied!" error from browser single origin restriction. 

How to consume Astoria Service

A week ago I wrote about setting-up Astoria Service. Now is time to expose real power of Astoria - consuming data from client script.

Once you have setup your Web Data Service you're ready to write ASP.NET AJAX script to consume it. Basically you need these things:

  • set Requiest's header "accept" value of "application/json" so the data can be used directly in JS
  • call appropriate URL
  • and, of course, process data

The rest is done form Astoria team :) Kudos for them

this is how the code looks like:

   1:  function loadCustomers(){
   2:      var webRequest = new Sys.Net.WebRequest();   
   4:      webRequest.set_url("http://galcho-pc:86/northwind.svc/Customers");   
   6:      webRequest.get_headers()["accept"] = "application/json";
   8:      webRequest.add_completed(function (result){
   9:          var cust = result.get_object();   
  10:          for (i = 0; i < cust.length; i++){   
  11:              addCustomer(cust[i].ContactName, cust[i].CompanyName);
  12:          }  
  13:      });   
  15:      webRequest.invoke(); 
  16:  }
  18:  function addCustomer(contactName, companyName){
  19:      $get("customers").innerHTML += "<div>" + contactName + "</div>" + companyName + "<br/>";
  20:  }

There main function is loadCustomers(). It does all I described above. And there is a helper function that fills a DIV's innerHTML property with approperiate content.

Here is the HTML:

   1:  <div id="customers">
   2:      <span style="font-size: large; font-weight: bold; border: solid 1px black; width: 100%;
   3:          display: block;">
   4:          <div>
   5:              Contact Name</div>
   6:          CompanyName</span>
   7:  </div>

And the result looks like:


You can download full ASPX file from here: (0.94 KB)

More sophisticated article for Astoria consumer app is coming. It is based on MIX AJAX classed that provide infrastructure for CRUD operations.

The Pmarca Guide to Career Planning

I've just came across interesting reading: The Pmarca Guide to Career Planning in three parts (by Marc Andreessen):

This is very interesting for young professionals who are setting their path and for experienced one as it is very good from motivation stand point.

And interesting quote:

Or, start your own company.

If your startup fails, try another one. If that one fails, get back into a high-growth company to reset your resume and get more skills and experiences. Then start another company. Repeat as necessary until you change the world.

 Nothing is easy!!! for sure! It is better to get used to it :)

Installing old OS on new machine

I had interesting experience last night: I had to install Windows XP on new laptop with Mobile Intel® GM965 Express chipset .

I know you would wonder why and the reason was: Because on this machine will live software that communicates with a hardware for vehicle diagnostic system. And the provider (or software ) required Windows XP.

Piece of cake, right?! Having an issue or two I was able to install it in.... 3.5 hours Arghhggggggggg (it had to be ready ASAP :( ).

Well let me share with you so you will know how to act if you have similar situation:

Problem 1:SATA HDD

Probably you know that if Windows XP installation package doesn't have SCSI or SATA drivers for your adapter you have to provide them in the early stages of instalation (by pressing F6) using.....  ta damm Floppy Disk! But who in the world is still using FDD? Even accountants I know use USB flash drive and digital signature. This was almost showstopper but I remembered the tool I read about for customizing Windows installations - free nLite. Beside removing components, incorporating serial keys, SPs, hotfixes and a bunch of tweaks there is a option to incorporate drivers. This is exactly what I needed. the rest is customizing WinXP ISO image

Problem 2: Chipset Drivers

This one was relatively easy - The Intel guys provided a nice little .exe that expant image on floppy disk. As I don't have one I decompressed the .exe several times until I get a nice 1.44 MB .IMA file. I had to download the shareware WinImage in order to extract files from .IMA image and then nLite did his job.

And bingo - it worked. The rest is borring software installation.

Hope this helps.