Monday, February 28, 2005

Future of .NET Remoting

Is .NET Remoting a dying technology? or Evolving to a unified distributed computing technology?

I heard that Ingo Rammer quoted "i have wasted two years of my life on .net remoting" in a conference in Frankfurt last year. Whether this is from a credible source or not, it looks like remoting is slated to go into second class technology, with flashy n sexy Indigo entering the scene.

[Ingo, offcially confirmed that *wasted* is not quoted by him]

In MSDN article "Introducing Longhorn for Developers" & Introducing Indigo: An Early Look,

Indigo is a set of .NET technologies for building and running connected systems, best of ASMX + Remoting. Indigo service applications support two main communications types: a stateless model (Indigo Web Services), in which messages are received with few if any guarantees, and a stateful model (Indigo RemoteObject Services), which creates a communication session between two service objects. The stateless model is equivalent to current-day Web services and is useful when broadcasting noncritical information. The stateful model, on the other hand, uses session state to enable Web services to provide functionality across the Internet, including callback methods, events, widely distributed transactions, and reliability and durability guarantees that enterprise applications require.

Indigo RemoteObject applications are built using the Indigo SOAP messaging infrastructure; therefore, they support end-to-end security features, including authentication and encryption, widely distributed and long-running transactions, automatic activation, and a robust management infrastructure, in addition to providing the ability to perform interface-based remoting and use asynchronous server methods.

I'm still not sure if Indigo RemoteObject will work behind a firewall, if you know pls let me know. Happen to view the msdn channel 9 video of Richard Turner {Indigo Program Manager} looks like, stage is all set for Indigo and we know about that so called *support* he is talking about and as a matter of fact Indigo will NOT support Windows 2000 either.

With all the performance the remoting framework suppose to deliver, it looks like somebody throwed the baby out with the bathwater. Looking at MSDNtv, Matt Tavis was demonstrating some of the feature enhancements to remoting infrastructure in Whidbey, my guess nothing will be added in Orcas version of .NET.

IpcChannel - for inter process communication in same box, avoids the overhead of network stack
Secure TcpChannel - built-in support for encryption, signing and authentication
Version Tolerant Serialization - more a serialization feature but this allows for versioning of types without worrying about failing to de/serialize when communicating with older versions on the client/server
some more that i didn't understand

Finally a word from Ingo about this
"The role of Remoting after Indigo? Hmm ... it will be the same role as the one of ASP.NET Web services, WSE 2.0, MSMQ, and Enterprise Services/COM+: Existing apps will continue to work (you can even run Indigo and any of these previous technologies in the same application and AppDomain). New apps (or parts thereof) will however quite likely be developed directly based on Indigo. (If running on Windows XP, Windows Server 2003 or - future - Longhorn as these are the only platforms which will be supported). "Normal" apps with the previous technologies (Remoting, ASP.NET, ...) will be quite easy to migrate. Custom transport channels and custom sinks will be harder to move ... i.e. they will have to be rewritten using the new extensibility models. Oh btw: Remoting will also continue to exist for areas which are not addressed by Indigo like cross-AppDomain communication. After all: Indigo is based on Remoting's __TransparentProxy architecture anyway ;-) "

No, there is no need to push the panic button and stop using remoting in new projects, a Prescriptive Guidance for Today's Technologies by Richard Turner's Tech-Ed session.

Saturday, February 26, 2005

p&p Updater Application Block - Analysis and Review

Prior to including this application block as part of your enterprise architecture, do check out the architectural alternative of push technology, using Systems Management Server or group policy of active directory. Apart from server cost this may turn out to be information overload, but provides lot of benefits with simplified application deployment and administration, like ability to rollout to specific group, incremental updates greatly reducing network traffic and reduces the operational costs of developing software for deployment.

We can also look at another technical alternative that is shipped with .NET 1.0, HREF-EXE AKA Zero-touch deployment {sounds very similar to JAVA Web Start ;-)}. It might turn to be simplest of all deployment models, you deploy the application in any web server and user clicks on the link to the application .NET downloads the application and executes it. The update mechanism is like updating web applications, simply have to replace the file on the Web server and from that point on everyone launching your application will get the newest version.

But HREF-EXE come with an inherent limitations like, No offline support (always connected to web server), No desktop integration (user has to manually create an shortcut to exe), Runs in a sandbox with restricted semi-trust security (will not be able to call a web service in different machine from where exe is downloaded) and network delay (fat smart client apps will be more impacted).


Some of these limitations are overcome in next generation of this technology, ClickOnce shipping with .NET 2.0, with features like offline support, rolling back to previous versions of an application, and listing an application in the Windows Start menu & Add/Remove Programs catalog, HTTP compression support, simpler deployment packaging with help of "Whidbey". But if you are looking at capabilities like install to GAC, manage ODBC or COM+, registry write, setting up permissions (File/Folder/Registry) or any custom actions at install/uninstall, Install On Demand
Transactional Installation and Source Resiliency, only option is MSI.

The Updater Application Block helps to detect, validate, and download application updates deployed in a central location, using a "pull" model, with minimal coding and ability to configure externally and extend it for any special reqt.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnbda/html/updater.asp

1. All applications will have a boot strap application (AppStart.exe) which will use its configuration file to identify the latest and greatest version of the application and launch it.

2. The Updater Application Block requires a controller application to start/stop the update process and handle the various events that occur when application update tasks are performed. There are three distinct types of controller, each with their own considerations: Computer-Wide Controllers, Application Launcher Controllers and Self-Updating Applications. This controller app will get the server manifest for the application, connecting to the web server and check if there is any updated version available.

3. If new version is found, it will download the latest version using an downloader (Background intelligent transfer service (BITS) downloader comes out-of-the-box)

4. Uses and validates binaries (basically an crypto hash check with RSA algorithm) to ensure authenticity of the binaries

5. Updates the boot strap application configuration to the new version and runs the post-installation tasks if specified in manifest.

6. Depending on the type of controller, the new version is launched, if its a self updating controller, all the update happens in background and application gets notified of the successful completion of updating, which can take action like popping up a form to confirm with user on launching updated version.

As with other application blocks everything is customizable and out-of-the-box ships with a standard binaries that can be used for 90% of cases. Its one of the simpler and easy to use blocks of what i have seen. There is no sample provided for Application Launcher Controllers, although it should be easier to modify application launcher to make the asynchronous update process as a synchronous one, i got a very good sample for this one from Chris L. Kinsman http://www.vergentsoftware.com/downloads/uabsamples.zip.

Some of the features that i wish/expect to be in next release,

- Make mandatory updates, in most of cases you might want to make the update mandatory instead of user opting for an update

- Incremental update, i would prefer to publish only modified binaries and application block should be able to take the other files from the previous version of application

- Manage staged rollouts, to be able to control which clients update and when. Found a simple and good solution in net, modify the manifest retrieval code so that it can call an ASP.NET page, which returns different manifests based on the user's credentials (so you can have a group of users who are given one version, and everyone else gets the last major release or a one department can be given one version that is different from another department)

- Compression on the wire, this will help reduce a lot of network traffic

- Rollback update, only way to do that out-of-the-box is to release a new version with older binaries, works perfect but may be we can do that better

- Cleanup old versions, which should be simpler with some code in post processor

- May be i'm more user friendly, i would like to have a "what's new" or more accurately "what's the fix" information for the updated version to be available in manifest

The soon be released Updater Application Block 2.0, focuses on simplification of use, adherence to the Enterprise Library specification, and alignment with .NET 2.0 ClickOnce.

Thursday, February 24, 2005

int division in SQLServer T-SQL

Today, I'm trying to use T-SQL to do a calculation something like this


Declare @a intDeclare @b int
select @a=1, @b=2
select (@a/@b)*100

No the result was not 50, it was 0.Thats 'coz SQL Server performs an implicit data-type conversion and converts the resulting value of 1/2 as integer. Fix is to cast the operands to decimal

select ( cast(@a as decimal)/ cast(@b as decimal) )*100

Tuesday, February 22, 2005

sizeof (.net object) ?

Some time back, I was asked a way to find memory footprint of a dataset and my first thought was, a simple method call that .NET might provide, (No, sizeof operator only works with value types and not reference types) but life is not that eazy, there isn't any magic object that will let me do this.

After some googling found the following piece of code

long bytecount = System.GC.GetTotalMemory(true);
DataSet1 ds = new DataSet1();
ds.EnforceConstraints = false;
ds.Order_Details.BeginLoadData();
ds.Orders.BeginLoadData();
ds.ReadXml("c:\\test.xml");
bytecount = System.GC.GetTotalMemory(true) - bytecount;
MessageBox.Show("Loaded - Waiting. Total K = " + (bytecount/1024).ToString());
long bytecount = System.GC.GetTotalMemory(true);
System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();
xmlDoc.Load("c:\\test.xml");
bytecount = System.GC.GetTotalMemory(true) - bytecount;
MessageBox.Show("Loaded - Waiting. Total K = " + (bytecount/1024).ToString());

Thanks Barry Gervin, http://objectsharp.com/Blogs/barry/archive/2004/02/24/284.aspx

Thank god, Java developers too, doesn't have a simpler option for this and a solution i found thats used in Java world is much like Barry's code.

Not being skeptical here, but we tried using a memory analysis tool (Compuware's DevPartner) and also used the windows perfmon to cross check the value. Oops, none of the value match, no not some minor differences, it differed by a huge numbers. We had to take a expert guess, one which closely matched the memory size calculated from database columns being fetched, no i am not going to disclose which method was close, as i'm myself not sure which one is.

If you can think of something of perfect way to get the memory foot print of a .NET object, pls let me know with your comments here. I appreciate your help.

Saturday, February 19, 2005

.NET app - another running instance check and DTC exception

This error and its fix is weird and i am posting this to a miserable developer, who is still trying to crack this error in this scenario. It was a requirement is to allow only one instance of the batch app to run, hence the following code was copied from internet to check if another instance of application is running, and abort the current instance

Process [] aoRunningInstance = Process.GetProcessesByName(Constant.APPLICATION_NAME);
if (aoRunningInstance.Length > 1)
{
throw new ApplicationException("Another instance of app is running. Aborting current instance.");
}
aoRunningInstance = null;

Everything went fine; it found another instance and aborted, but weirdly in a scenario

//Create a new Transaction
//Open SQL connection inside the Transaction
//Open DB2 connection inside the Transaction

Line where i try to open DB2 connection, an exception is thrown >>>>> [IBM][CLI Driver] CLI0126E Operation invalid at this time. SQLSTATE=HY011

It was found that if we comment out another instance check code, the error is not happening. #@$@#$@!#. Wait, fix to this error is even weirder, we open and close the DB2 connection before this another instance check code and click the error vanishes in thin air.

I found a another way of to check another running instance of the app from Updater Application Block,

private Mutex _appStartMutex;
private readonly Guid _mutexGuid = new Guid( new byte[] { 0x5F, 0x4D, 0x69, 0x63, 0x68, 0x61, 0x65, 0x6C, 0x20, 0x53, 0x74, 0x75, 0x61, 0x72, 0x74, 0x5F });
bool isOwned = false;
_appStartMutex = new Mutex( true, System.Reflection.Assembly.GetExecutingAssembly().FullName + _mutexGuid.ToString(), out isOwned );
if ( !isOwned ){
throw new ApplicationException("Another instance of app is running. Aborting current instance.");
}

This will not alow the application to run even if its run with different executable name or from a different location. But has overhead of Mutex, not sure if this will fix this the above error.

It indeed fixes the above issue and after some thought i think it will be performance effective to have Mutex instead of pulling every process name that is running machine, i always see a 100% spike if i do this using task manager.

Tuesday, February 15, 2005

ASP.NET Datagrid to Excel clipboard copy/paste: an ugly javascript solution

As usual this one is a crazy reqt to provide a feature to copy/paste a fixed size datagrid to/from excel. To me * should understand the architectural difference between a web form and winform There are some inherent features that comes with winform; and one should not expect, all the features to be provided in webform. "He who gives me salt, he shall get the solution", i found excel reads/writes data in clipbooard with tab delimited for columns and new line delimited for rows,

function GetExcelData(){
var content = clipboardData.getData("Text");
if (content!=null) {
     var t = content.replace(/\n/g," \n");
     t = t.replace(/\t/g," \t");
     var myArray = t.split(/\n/);
     var y = "<table align='center' border='1'>";
     for (var i = 0; i < myArray.length; i++) {
          y = y + "<tr>";
          var myArray2 = myArray[i].split(/\t/);
          for (var j = 0; j < myArray2.length; j++) {
               y = y + "<td> " + myArray2[j] + "</td>";
          }
          y = y + "</tr>";
     }
     y = y + "</table>";
     window.spnMsg.innerHTML = y;
}
else {
     window.spnMsg.innerHTML = "No text found in clipboard.";
}
}

function PutExcelData(){ //... build a string in delimited format and put it in clipboard

Proposed solution is to provide a button "Copy", to copy the data from datagrid to clipboard and a "Paste" button to copy the data data from clipboard to datagrid.

Warning: Not sure if it is supported in all IE versions and other GOOD browsers like Firefox.

I found a workaround also, use a textarea form field that holds the text to be copied, select it by form.textarea.select() method and copy it to the clipboard using the execCommand like below, Unfortunately the select() method works with visible form objects only, that can be easily overcomed but putting that control in a div tag and making the div tag invisible.

document.myForm.invisibleTextArea.select();
document.execCommand('Copy');

It struck me after coding the solution, how easy it will be to exploit this and steal a sensitive information from clipboard (i know many copy/paste passwords, credit card nbrs!). I expect IE to atleast prompt user, before allowing this script to access clipboard.