Galin Iliev's blog

Software Architecture & Development

IIS7 Administration and Customization talk

My talk yesterday went well and I think people found it interesting so I've decided to post slides and demo as well as some useful links

From presentation:

  • Slides - PowerPoint 2007 - (2.4 MB)
  • Demo - VS 2008 project (961 KB)

Some resources:

IIS7 talk @ SofiaDev UG

I am giving a talk this Thursday in front of SofiaDev .NET User group at local Microsoft office at 18:30 local time.

In the presentation I will show:

  1. New tools in IIS7 as well as new administration options
  2. New tracing and diagnostics options
  3. New integration pipeline
  4. Deep example that:
    • use custom IIS module written in C#
    • extend IIS configuration schema
    • extend IIS Manager by adding UI component

If this sounds interesting to you and you want to attend write to branimir _ at _ sofiadev dot org

See you there!

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.

Silverlight 1.0 released and support for Linix announced

On September 4th, 2007 9 PM PST Microsoft released to web (RTW) Silverlight 1.0 and announced that they will work together with Novell Inc. to enable silverliht applications on Linux.

ScottGu posted what's in silverlight 1.0 release:

  • Built-in codec support for playing VC-1 and WMV video, and MP3 and WMA audio within a browser.  The VC-1 codec is a big step forward for incorporating media within a web experience - since it supports very efficiently playing high-quality, high definition video in the browser.  It is a standards-based media format that is implemented in all HD-DVD and Blueray DVD players, and is supported by hundreds of millions of mobile devices, XBOX 360s, PlayStation 3s, and Windows Media Centers (enabling you to encode content once and run it on all of these devices + Silverlight unmodified).  It enables you to use a huge library of existing video content and provides access to the broad ecosystem of existing Windows Media tools, components, vendors and hardware. 
  • Silverlight supports the ability to progressively download and play media content from any web-server.  You can point Silverlight at any URL containing video/audio media content, and it will download it and enable you to play it within the browser.  No special server software is required, and Silverlight can work with any web-server (including Apache on Linux).  We'll also be releasing an IIS 7.0 media pack that enables rich bandwidth throttling features that you can enable on your web-server for free.
  • Silverlight also optionally supports built-in media streaming.  This enables you to use a streaming server like Windows Media Server on the backend to efficiently stream video/audio (note: Windows Media Server is a free product that runs on Windows Server).  Streaming brings some significant benefits in that: 1) it can improve the end-user's experience when they seek around in a large video stream, and 2) it can dramatically lower your bandwidth costs. 

  • Silverlight enables you to create rich UI and animations, and blend vector graphics with HTML to create compelling content experiences.  It supports a Javascript programming model to develop these.  One benefit of this is that it makes it really easy to integrate these experiences within AJAX web-pages (since you can write Javascript code to update both the HTML and XAML elements together). 

  • Silverlight makes it easy to build rich video player interactive experiences.  You can blend together its media capabilities with the vector graphic support to create any type of media playing experience you want.  Silverlight includes the ability to "go full screen" to create a completely immersive experience, as well as to overlay menus/content/controls/text directly on top of running video content (allowing you to enable DVD like experiences).  Silverlight also provides the ability to resize running video on the fly without requiring the video stream to be stopped or restarted.

There is another RTW Expression Encoder 1.0 release on the web.  Expression Encoder is part of the Microsoft Expression suite of products, and enables designers and content professionals to enhance, encode and publish media content for Silverlight.  You can use it to import media files from a variety of formats (QuickTime, WMV, AVI and more), add leaders and trailers to videos for advertising or roll credits, easily watermark video with corporate logos or brands, and then tune the encoding settings to create optimal web-friendly Silverlight experiences.

Silverlight is used on several MS sites - MSN Podium '08, Halo 3 HD Preview...

Here are some screenshots: