Thursday, September 28, 2006

New Design/New Name

For all you getting this via Atom/RSS (btw, thanks for subscribing), come on by and check out the new blog design. This time I went for a darker design giving a bit of a Vista-ish feel. Also, you will see I finally formally changed the name to NetFX Harmonics to agree with the INSANE decision to rename WinFX to .NET 3.0.



Finally, if you haven't done so already please start using the new feed at http://feeds.feedburner.com/FXHarmonics/ to replace to old one. I will soon be discontinuing the old feed.

JavaScript Graphics Development Updated

For all those interested in learning some introductory concepts some lesser known features of JavaScript, I just updated my e-chapter on JavaScript Graphics Development. This an introduction to using JavaScript and Ajax concepts to do manual graphics development. It also touches briefly on concepts involving interactive graphics and widget creation.



Anyhow, here's the link:

Exam Update

Well, I'm a month into the ACTUAL writing of the C# 2.0 exam and I'm finding it just as fun as I thought it would be. This exam is more advanced than most people are probably going to want it to be, but I just can't imagine WHY someone would want to take a sissy exam. That doesn't help anyone. On the other end of things, anyone who knows Richter's CLR via C# book by heart should do great on this exam.



The only previews I can give at this time are that this exam is really more of a C#/CLR 2.0 exam as I have a sections for reflection and AppDomain management. I also have sections for more controversial things like COM Interop and unsafe code (not too bad-- I'm not about to ask pointer arithmetic questions!). The other thing I can say is that this complements the 70-* certification exams in that this covers the more technical dimension of the CLR, C#, and the framework. It's more like computer science exams than the certification exams. That is, they are more algorithmic than scenario-based.



As I progress, I'm also setting aside questions for a possible CLR 2.0 exam (for my own exam; probably not Brainbench). I figure this exam could cover things like fusion, assembly loading mechanics, CLR internal memory management, identification of core DLLs ( i.e. mscorwks.dll) and other fun topics. I would really like to see "IT" people think MUCH more like CS people; internals and mechanics are VERY good things to know.

Update

Here's a quick update on a few things...



First off the primary feed for this site is now at the below link:





Please change all your references to point to the new link. I'll be removing the old one in a few months.



Secondly, since someone had an aneurysm and decided it would be a great idea to confuse the entire planet, WinFX is now called .NET 3.0. Ergo, I'm changing the name of this blog to NetFX Harmonics for the time being.



Thirdly, I'll probably be posting much more content in the near future. Recently I was at an MSDN event and I was amazed at how little everyone (including the presenter) knew about new technologies. There were people who actually asked what SOA event was. I assumed everyone in the Microsoft technical community would be at least somewhat up to date with WinFX (Uhhhh duhhh .NET 3.0) information. Clearly I was wrong. I guess I should start publishing again!

Breaking the Silence

Well, good news and bad news. I was offered the gig to write the new Brainbench C# 2.0 exam. I've been wanting that for a while, so obviously I took it. Of course three days later I get an offer from an editor for me to write a chapter or two for a soon to be released Ajax book. Ha! The bad news is that they had the exact same time frame (1 to 2 months). That, plus my intensive physical training and skydiving pursuits I found absolutely no time on my (Google) calendar to write a chapter! This is a major lesson in timing for me.



I'm really excited about the C# 2.0 exam though. If you know anything about how I write samples and questions you'll know that I'm BEYOND uptight about strictness to best practices and the official framework design guidelines (thank you Krzysztof Cwalina and Brad Abrams). So, my questions will obviously follow those VERY legalistically.



...and NO I won't have threading questions or web questions on the exam. This is NOT a framework exam! I hate it when test writers put that stuff on those exams. Strictly web people will miss every threading question and strictly Windows people will miss every web question. So, it will be fair... but, no, not easy!



By the way, I know I haven't posted any research in a VERY long time on either of my blogs (this one and my Ajax blog), but I've been rather swamped with non-technical activities for the past few months. I still have many more videos just sitting here that I need to post, but I just need to find the right time.

C# Fundamentals Exam Released!

Awesome! The Brainbench C# Fundamentals exam just went public! Why do I care? Well, because I was the technical editor for the exam! I'm rather excited because this was my first publicly shown work as a technical editor of anything.



I think exam takers will find the exam to be fair. It's not too terribly advanced, but it's not a beginners exam either. It should really test if you know what you're talking about. One thing that I will remind everyone of is that C# is a standardized language, not "some Microsoft language". So, this exam tests your knowledge of the official C# (ECMA-334) language, not your slang usages of it. Also, sadly, this exam is on the older C# 1.0, not 2.0, which is my favorite language.



Currently the exam is available for free at brainbench.com. The full link is below. Enjoy!



3D RSS XAML Demonstration

Here's a short application I wrote for a demo recently. This is a rather simple RSS application, but I created it in 3D in XAML using the February CTP of WinFX. Also, the code is self-sufficient. That is, you can use the below XAML declaration in XAMLPad.



The first thing to notice about this application is that the data is real. That is, the actually RSS information you are seeing on the screen is from a live RSS feed; this demonstrates XAML's XML data-binding capabilities. The next thing to notice is that the entire thing is on an angle. That's because this is all rendered in 3D. So, this also demonstrates using XAML in 3D. You should also notice the background. This is actually just a JPG on my website. There is no C#/VB.NET anywhere... it's all XAML. This demonstrates the power to skin objects. Finally, you should notice that the rendering has different font styles and sizes. This demonstrates how you can style controls... yes, controls. There's nothing fancy here. There isn't really a "3D TextBlock" or anything. A TextBlock is a TextBlock. I just so happen to be using it in 3D.



So, there are many things this demo demonstrates. I actually recorded a short video lesson on 3D XAML programming and I will be releasing it very soon. In the future I may have an entire series on 3D XAML programming.



<Page
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Viewport3D>
<Viewport3D.Resources>
<XmlDataProvider x:Key="xmlData" Source="http://fxfeeds.mozilla.com/rss20.xml">
</XmlDataProvider>
<Style x:Key="rssTitle" TargetType="{x:Type TextBlock}">
<Setter Property="FontSize" Value="24"/>
<Setter Property="TextBlock.Foreground">
<Setter.Value>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
<LinearGradientBrush.GradientStops>
<GradientStop Color="Blue" Offset="0"/>
<GradientStop Color="Green" Offset="1"/>
</LinearGradientBrush.GradientStops>
</LinearGradientBrush>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="rssText" TargetType="{x:Type TextBlock}">
<Setter Property="FontSize" Value="12"/>
<Setter Property="Foreground" Value="Gray"/>
</Style>
</Viewport3D.Resources>
<Viewport3D.Camera>
<PerspectiveCamera
Position="2.5,2.5,5"
LookDirection="-.5,-.5,-1"
FieldOfView="45"
UpDirection="1,0,0"
>
</PerspectiveCamera>
</Viewport3D.Camera>
<ModelVisual3D>
<ModelVisual3D.Content>
<Model3DGroup>
<AmbientLight Color="White"></AmbientLight>
<GeometryModel3D>
<GeometryModel3D.Geometry>
<MeshGeometry3D
Positions="-1, -1, 0 1, -1, 0 -1, 1, 0 1, 1, 0"
TriangleIndices="2 0 1 3 2 1"
TextureCoordinates="1 1 1 0 0 1 0 0"
Normals="0,0,1 0,0,1 0,0,1 0,0,1">
</MeshGeometry3D>
</GeometryModel3D.Geometry>
<GeometryModel3D.Material>
<DiffuseMaterial>
<DiffuseMaterial.Brush>
<VisualBrush>
<VisualBrush.Visual >
<StackPanel>
<ListBox ItemsSource="{Binding Source={StaticResource xmlData}, XPath=rss/channel/item}">
<ListBox.Background>
<ImageBrush ImageSource="http://davidbetz.net/kansas/xamlimage.jpg"></ImageBrush>
</ListBox.Background>
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding XPath=title}" Style="{StaticResource rssTitle}"></TextBlock>
<TextBlock Text="{Binding XPath=description}" Style="{StaticResource rssText}"></TextBlock>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</StackPanel>
</VisualBrush.Visual>
</VisualBrush>
</DiffuseMaterial.Brush>
</DiffuseMaterial>
</GeometryModel3D.Material>
</GeometryModel3D>
</Model3DGroup>
</ModelVisual3D.Content>
</ModelVisual3D>
</Viewport3D>
</Page>






Video 4 (FWD) - "Using the Web Developer Toolbar"

One of the most powerful and appreciated extensions for Firefox is the Web Developer toolbar. This is the extension that helped convert me from an independent IEvangelist to a Firefox promoter and standards advocate. This tool puts the keys to client-side web development into the hands of the developer.



With a quick click of the mouse, the developer can now see all elements of a certain type, can disable or enable various portions of development ( i.e. JavaScript), or can view otherwise hidden form information. It's such a powerful tool that you'll never be able to do client-side web development again without it.



I do apologize for being so slow in the posting of these videos. There will be a few more in the future. These videos are from September 2005 and are for Firefox 1.0.x, but are still appropriate for Firefox 1.5.x (and Firefox 2.0)



Shared Source Common Language Infrastructure 2.0

I've been waiting for this one! The public version of the .NET 2.0 source code has been released! Otherwise known as the SSCLI 2.0 (Shared Source Common Language Infrastructure 2.0), this is basically the .NET 2.0 framework source code (among other things). With Reflector you can view the framework code, but this is the original code before any compilation thus leaving the developer comments in tact. It's also a bit cleaner here.



Not only that, but you get a load of unmanaged code. I'm talking about real hardcore CLR stuff. It also includes the C# compiler source code as well as the code for ILASM, ILDASM, and a bunch of other utilities. It's going to be really awesome seeing how generics and anonymous delegates are implemented.



My favorite piece that came with SSCLI 1.X is still here: there C# code for the JScript compiler (yes, the JScript compiler is written in C#). I actually used the original source code for the basis for a brain bender quiz in my .NET class. I highly, highly recommend the use of this SSCLI for your educational endeavors. Either to help you learn more, or to help others out.



Here's the link to download the SSCLI 2.0:

LLBLGen Overview (Special Edition) Video

A friend of mine told me someone tasked him with creating an O/R mapping tool. My first reaction was...well, of course, your company likes to reinvent the wheel, loves useless legacy technology, and is very anti-productivity. He said that nothing is easy to use and everything has useless error messages. So I of course reminded him of the great gift to humanity known as LLBLGen, which is very easy to use and is very clearly designed. I've mentioned LLBLGen to him before, but this time was a real marketing opportunity. (Actually, I'm very annoying about promoting .NET 2.0, Firefox, Gmail, and LLBLGen -- absolute life savers).



Anyways... I told him I would create a quick overview video of LLBLGen as a marketing pitch to his company. Well, the "quick video" turned out to be almost a half hour long. Err, yeah... So, I've decided to share this video with the rest of the world. It's actually not like my usual videos, so I'm marking this version as "Special Edition". I'll probably release the "final" version in the future.



Below is the link to the LLBLGen Overview (Special Edition) video.





Disclaimer: I am in no way affiliated with Solution Design or any Solution Design/LLBLGen product. The above video is in no way endorsed by Solution design and is unofficial in every sense of the word.

Brainbench C# Fundamentals Technical Editor

What a week... I finally finished my gig as Brainbench technical editor (they called it an exam "cleaner") for the C# Fundamentals exam. Apparently they were extremely impressed with my work. Where others write a small comment line, I would write a page or so about the question and the answers citing the ECMA standard and anally explaining the improper wording of something.



I'm also rather kicking myself for turning down another gig they offered me. After I finished with this gig, I was offered the gig to write the VB.NET 2005 exam. My initial justification to myself for rejecting it was for the same reason I wouldn't write an Internet Explorer exam: it's no different than devil worship. Now I wish I took that gig, because even though the vbc.exe compiler packs a TON of useless garbage (you ever look at that stuff? A ton of odd Microsoft.VisualBasic references) in the assemblies, it's still IL! .NET is .NET! In any case, I did tell my rep there that I want to be on the list for any C# 2.0, CLR, or .NET 2.0 framework exams! We'll see!

WCF Relative Binding Speeds

My latest infrastructure design consists of a few services spread over various servers and with many clients in various locations. Some of the clients will be on the same machine as the service, others will be on the same NT-based network, others will be WSE3 services, and even others will be PHP based. I wanted to provide the best solution for each, ergo my love for the Go-live of WCF! With WCF I can have the services expose multiple endpoints to allow a diverse number of clients each with their own maximum efficiency. PHP clients for example will get a BasicHttpBinding endpoint, while clients on the same machine as the service will use the NetNamedPipeBinding.



What do the speeds look like for each of these bindings? I went ahead and wrote a quick test harness to see the relative speeds of each binding. These are very simple tests, but they do demonstrate how the speeds of the bindings compare with each other. Without a ton of needless talk, let's get right into what's going on...



Here is the service configuration file...



  <system.serviceModel>
<services>
<service type="WcfDemo.DemoService">
<endpoint
address="WsDualHttpBinding"
contract="WcfDemo.IDemoService"
binding="wsDualHttpBinding"
/>
<endpoint
address="WsHttpBinding"
contract="WcfDemo.IDemoService"
binding="wsHttpBinding"
/>
<endpoint
address="BasicHttpBinding"
contract="WcfDemo.IDemoService"
binding="basicHttpBinding"></endpoint>
<endpoint
address="NetTcpBinding"
contract="WcfDemo.IDemoService"
binding="netTcpBinding"
/>
<endpoint
address="NetNamedPipeBinding"
contract="WcfDemo.IDemoService"
binding="netNamedPipeBinding"></endpoint>
</service>
</services>
</system.serviceModel>


Here is the significant portion of the service code...



Uri netTcpAddress = new Uri("net.tcp://localhost:8080/");
Uri httpAddress = new Uri("http://localhost:8081/");
Uri netPipeAddress = new Uri("net.pipe://localhost/");
using (ServiceHost service = new ServiceHost(typeof(DemoService), new Uri[] { netTcpAddress, httpAddress, netPipeAddress })) {
service.Open( );

Console.WriteLine("Listening...");
Console.ReadLine( );
}


Notice the netPipeAddress is using "net.pipe" as the address scheme and doesn't have a port. This is actually for the netNamedPipeBinding binding which is for inner process communication on the same machine, so there wouldn't be a port for that. The netTcpBinding binding does however have a port as it would really be out on the network somewhere. Also keep in mind that you add a uri for each address scheme, not each address.



Here is the client configuration file...


<system.serviceModel>
<client>
<endpoint
address="http://localhost:8081/WsDualHttpBinding"
binding="wsDualHttpBinding"
name="WSDualHttpBinding"
contract="IDemoService" />
<endpoint
address="http://localhost:8081/WsHttpBinding"
binding="wsHttpBinding"
name="WSHttpBinding"
contract="IDemoService" />
<endpoint
address="http://localhost:8081/BasicHttpBinding"
binding="basicHttpBinding"
name="BasicHttpBinding"
contract="IDemoService" />
<endpoint
address="net.tcp://localhost:8080/NetTcpBinding"
binding="netTcpBinding"
name="NetTcpBinding"
contract="IDemoService" />
<endpoint
address="net.pipe://localhost/NetNamedPipeBinding"
binding="netNamedPipeBinding"
name="NetNamedPipeBinding"
contract="IDemoService" />
</client>
</system.serviceModel>


Again notice there is no port on the netNamedPipeBinding binding and there is a port on the netTcpBinding. Also notice that each of the addresses end in the name of the endpoint specified by the server; the endpoints also have a name attribute to be accessible by the client-side code as seen in the next code block.



Here is how I start my client code...


DemoServiceProxy wSDualHttpProxy = new DemoServiceProxy("WSDualHttpBinding");
DemoServiceProxy wSHttpProxy = new DemoServiceProxy("WSHttpBinding");
DemoServiceProxy basicHttpProxy = new DemoServiceProxy("BasicHttpBinding");
DemoServiceProxy netTcpProxy = new DemoServiceProxy("NetTcpBinding");
DemoServiceProxy netNamedPipeProxy = new DemoServiceProxy("NetNamedPipeBinding");


My actual benchmarking code consists of a simple timer that look like this...



Person person = new Person( );
DateTime a = DateTime.Now;
int i = 0;
while ((DateTime.Now - a).Seconds < 10) {
wSDualHttpProxy.RecordPerson(person);
i++;
}
Console.WriteLine("WSDualHttpBinding: Processed {0} calls in 10 seconds", i);


That basically just means I want to run as many tests as possible in 10 seconds.



I actually ordered the tests based on my predictions of their relative speeds and it turns out my predictions were correct. Take a look for yourself...



WSDualHttpBinding: Processed 1602 calls in 10 seconds
WSHttpBinding: Processed 2531 calls in 10 seconds
BasicHttpBinding: Processed 17913 calls in 10 seconds
NetTcpBinding: Processed 39957 calls in 10 seconds
NetNamedPipeBinding: Processed 48255 calls in 10 seconds


This isn't really that surprising. The more complex web services protocols are slower than the most basic ones, which are in turn slower than a direct TCP connection, which in turn is slower than the named-pipes binding connection for use on the same machine.



That was actually an out-of-the-box benchmark; that is, I didn't customize the bindings in any way. In another test I turned off security for the WsDualHttpBinding and WsHttpBinding bindings.



First, I added the following binding sections to both the service and the client configuration files.




<bindings>
<wsDualHttpBinding>
<binding name="noSecurity">
<security mode="None"></security>
</binding>
</wsDualHttpBinding>
<wsHttpBinding>
<binding name="noSecurity">
<security mode="None"></security>
</binding>
</wsHttpBinding>
</bindings>


Then I altered the endpoints to point to the appropriate binding. Here is the service configuration alteration.



<endpoint
address="WsDualHttpBinding"
bindingConfiguration="noSecurity"
contract="WcfDemo.IDemoService"
binding="wsDualHttpBinding"
/>
<endpoint
address="WsHttpBinding"
bindingConfiguration="noSecurity"
contract="WcfDemo.IDemoService"
binding="wsHttpBinding"
/>


here is the client configuration alteration.



<endpoint
address="http://localhost:8081/WsDualHttpBinding"
binding="wsDualHttpBinding"
name="WSDualHttpBinding"
bindingConfiguration="noSecurity"
contract="IDemoService" />
<endpoint
address="http://localhost:8081/WsHttpBinding"
binding="wsHttpBinding"
name="WSHttpBinding"
bindingConfiguration="noSecurity"
contract="IDemoService" />


The results for both WSDualHttpBinding and WSHttpBinding were much faster!



WSDualHttpBinding: Processed 5773 calls in 10 seconds
WSHttpBinding: Processed 17257 calls in 10 seconds
BasicHttpBinding: Processed 19528 calls in 10 seconds
NetTcpBinding: Processed 39756 calls in 10 seconds
NetNamedPipeBinding: Processed 47457 calls in 10 seconds


So as you can see you can get really different levels of performance based on the different binding you use. The ability to have these various endpoints provides a great mechanism for my services to reach all kinds of different clients with great interoperability and maximized speed for network and local communication. Best of all, it's all free...no extra coding! All I had to do to add the new binding was add the endpoint to the service configuration file. WCF takes care of all the magic for you...



Supplemental material - Sample Projects


Video 3 (FWD) - "Introduction to the Firefox Console"

Here's the next video in the Firefox Web Developer series: Using the Firefox Console. The Firefox Console is a tremendously underused tool built right into Firefox. It allows for safe and efficient JavaScript development that may otherwise be a complete nightmare. This tool is also an absolute must for remote scripting developers (yes, I still refuse to call it "Ajax"). You can think of this tool as being much like a service tracer. C# programmers will feel right at home with this guy.



I say it in the video as well, but let me emphasis it here: the Firefox console is not the JavaScript console. Firefox is a complete standalone Web Development Suite -- not just a web browser. These tools are not addons, plugins, or extensions, but rather are natively built-in tools in Firefox. In later videos I will discuss other tools also built right into Firefox.



OK, so here ya go...



Indigo Girl

OK, everyone interested in WCF needs to stop what they are doing and head on over to http://www.thatindigogirl.com/. Michele has posted chapters to her up amazing, soon-to-be-released WCF book up there. Not just that, but there are a few things that really impress me.



First off, she has to be my new technology role model (move over Brad Abrams and Andrew Trolsen) as she to be the highest ranking MVP in the world. Sheesh, just go look at her profile at http://www.idesign.net/.



Secondly, she's probably the best writer I've ever read. Picky doesn't even begin to describe me. If I don't consider the author absolutely outstanding, I don't bother flipping the pages. She is one of the very few people I can actually put up with. Her bypassing of the silly Hello World example for a more useful one was very respectable and it demonstrated to me that she wants to get right to the point (in turn this shows technical security; insecure writers have SO padding and PCness!)



Third, she seems to be a bottomless pit of powerful and useful training. Today was the first time I read her work and in the first 30 pages of her book I was able to overcome a load of WCF obstacles I was hitting with the go-live version.



Fourth, she has a very beautiful website. Not that she did it, but it does show that she cares about her environment. It rather bothers me when my fellow architects feel the need to go all hardcore and boring on me. She seems to be immune to that. Um...yes, I rate my favorite architects by more than their technical skills!



I swore to only buy book from Abrams and Troelsen, but I'm going to pre-order her book...something I've never done before. I'm extremely impressed with her work. Seriously, go check her blog, website, and book out!

WCF Beta 2 and Go-live license!

At last! We now have beta 2 of WCF and a corresponding Go live license! This is incredible news for architects and developers alike. We can finally use the foundation to help unite our current (and future) component services, web services, and MSMQ applications in production



Just the other day I was designing an architecture and I was thinking "Gosh, this would be so nice in WCF. I *REALLY* don't want to do this in the old school way...if only the beta 2 and the Go-live license would be released!" Three days later...BAM!



Woohoo!! Not only that but beta 2 of WWF with a corresponding Go-live license is also available. I haven't been this excited since Firefox 1.5 came out!!!




Here's the Go-live license and the WCF beta 2 download (as well as WWF beta 2).


Constrainted try with retry mechanism for .NET 2.0

Lately I've been working on building a framework of abstractions and features that I feel are rather missing from my daily life. One of these features is a try/retry. In the past I used gotos and a ton of code to do this...but such extra coding was the nature of .NET 1.x. This is the world of .NET 2.0 and therefore I can take it to the next level! My new ExceptionFramework includes a few items to help me with exceptions and I figured I would share the following bit with the world. (No I'm not reinventing the exception application block)



public static class ExceptionManager
{
public static void TryWithRetryConstraints(
int retryCount,
int sleepTime,
ExceptionConstraintCollection constraints,
ExceptionTryBlock tryBlock,
ExceptionCatchBlock catchBlock) {
int n = 0;
retry:
try {
tryBlock.DynamicInvoke();
}
catch (Exception ex) {
if (++n < retryCount) {
foreach (object constraint in constraints) {
if (constraint is Type) {
bool isException = false;
if (((Type)constraint).Name == "Exception") {
isException = true;
}

Type parent = ((Type)constraint).BaseType;
while (!isException && parent.Name != "Object") {
if (parent.Name == "Exception") {
isException = true;
}
parent = parent.BaseType;
}
if (isException) {
Exception thrownException = ex;
while (thrownException != null) {
if (thrownException.GetType().ToString( ) == constraint.ToString( )) {
Thread.Sleep(sleepTime);
goto retry;
}

thrownException = thrownException.InnerException;
}
}
}
else if (constraint is String) {
if (ex.Message.Contains((string)constraint)) {
Thread.Sleep(sleepTime);
goto retry;
}
}
catchBlock.DynamicInvoke(ex);
return;
}
}
else {
catchBlock.DynamicInvoke(ex);
}
}
}
}


Here are some of the support items...



public delegate void ExceptionTryBlock( );
public delegate void ExceptionCatchBlock(Exception ex);

public class ExceptionConstraintCollection : Collection<object>
{
public ExceptionConstraintCollection() {
// Always declare default constructors!
}

public ExceptionConstraintCollection(params object[] constraintSet) {
for (int n = 0; n < constraintSet.Length; n++) {
this.Add(constraintSet[n]);
}
}
}


This version allows me to retry only for certain types of failures. There is a simplified version which doesn't take the constraints, but this is one is a bit more useful for my scenarios (I actually think it's a good idea to always constrain it!) I found that the times I wanted to retry involved cases where I either wanted to retry based on a certain type of exception type or based on some text in the string.



Here's is how I use this version of the try/retry in one of my WPF applications. This is my little way of testing my laptop's RAM speed (as well as the CLR speed). I would grab 1GB of ram, free it, and quickly try to get it again (doesn't happen). The below try/retry helps me get a feel or how fast .NET 2.0 can free up the memory and get it again (sometimes it CAN get the 1GB back).



First, I set up the constraints collection which holds the types and strings to which retries will be constrained to. This could of course be inline with the primary call.



ExceptionConstraintCollection constraints = new ExceptionConstraintCollection(
typeof(OutOfMemoryException),
"invocation");


Here is the actual call to the try/retry. I tell the try/retry manager how many times to retry (6), how many milliseconds to wait between each try (1000), what constraints to put on the try/retry (the above constraints collection), the logic to run as the try block (a delegate; anonymous in this case), and the code to run as the catch block (also a delegate; also anonymous in this case) and then let it do all the work for me.



ExceptionManager.TryWithRetryConstraints(6, 1000, constraints,
delegate {
group = new MemoryGroup();
MessageBox.Show("Success");
},
delegate(Exception ex) {
ExceptionManager.Report("Unable to allocate memory group.", ex);
});



Now there are some obvious issues with this. The first: speed. Well, that's the nature of abstraction. You get ease of use and simplicity to life, but it costs a bit. The second is...this just seem weird, doesn't it? It just seems like theres a whole new bag of issues associated with this. Actually, this doesn't really bother me either. I'm keeping my code small enough so that I don't break the Ritcher anonymous delegate rule (never more than 3 lines of code in an anonymous block including comments) and I'm keeping in my mind that top level exceptions will really have the text of "Exception has been thrown by the target of an invocation." (which is, of course, true, but this means I better not be doing this stuff straight with COM interop!) As long as I keep that last one in mind I should be fine.



In any case, this has really been helping me out and have been proving to be a very powerful solution to the lack of a try/retry in the CLR.

Video 1 (FWD) - "Setting up your Firefox Development Environment"

Finally! Here's the long awaited part 1 of my Firefox for ASP.NET 2.0 Developers Video Series. I will be releasing more parts to the series over the next few weeks.



This video is titled "Setting up your Firefox Development Environment" and contains valuable information on setting up your web development environment for maximizing efficiency. More setup information relating to this video will be mentioned in future videos as the utilities used in future videos of course also require setup.



Furthermore, this video is valuable not only to the professional web developer (as well as the non-professionals who still use tables for layout), but it's also valuable for anyone interested in maximizing their web experience.



Below is the link to part 1 of the Firefox for ASP.NET 2.0 Developers video series. You can download Visual Web Developer 2005 Express and Firefox 1.5 below as well.



Firefox for ASP.NET 2.0 Developers Video Series

In September I recorded a video series I entitled the Firefox Web Developer Series. I've since renamed it to the Firefox for ASP.NET 2.0 Developers Video Series (clearly because the original title wasn't long enough). I put the project on hold because of the .NET 2.0 course I was teaching, which took almost all my time, but now I'm ready to take the time to get back into videos.



This series is for ASP.NET 2.0 developers who want to enhance their ECMAScript (JavaScript) skills and see how the powerful web development suite known as Firefox as simplify their lives as much as .NET 2.0 Framework does. In the series I use Beta 2 of Visual Web Developer 2005 and Firefox 1.0, but everything should be good for the final version of VWD2005 and for Firefox 1.5.



I will be releasing videos from this series over the next few weeks. For now, here is my introduction.



You can download the first video from the video below. You can download Visual Web Developer 2005 Express and Firefox 1.5 below as well.



try{}catch{} in .NET 2.0 - Note

Here is a comment Joe made about my previous post.




... One additional facet that will probably go (mostly) unnoticed is that you can throw exceptions across assembly boundaries, and the wrapping will occur based on the assembly-level attribute on the assembly whose catch block is being evaluated. This makes interoperability with code that isn't on the wrapping plan, e.g. COBOL or Eiffel, work seamlessly as you would expect.


...



This comment is rather hidden in how I have my page designed, but I thought it worthy of it's own posting anyhow.

try{}catch{} in .NET 2.0 - Part 2

As I pointed out in a previous entry, try{}catch{} works differently in .NET 2.0 as it does in .NET 1.x. In 2.0, non-exception "throwables" are wrapped in a RuntimeWrappedException which can be caught by try{}catch(Exception ex){}, while, to catch then in .NET 1.x, you were required to use try{}catch{}. This led me to wonder 1) how does this work? and 2) is there even a purpose for try{}catch{} anymore?



So I started my research by... well, passing the buck, or going to the source, depending on your view on things. The first thing I did was ask Brad Abrams if he had some insights about this. He then forwarded me to Jonathan Keljo who I guess then forwarded me to Joe Duffy...sheesh what a line up! The best of the best of the best right there! Goodness, I feel like an ant...



Anyhow... here's the thing. Joe affirmed that there are at least two purposes for try{}catch{} in .NET 2.0



Here are his exact words...



(1) If your assembly doesn't have "wrapping" turned on;



(2) If you don't care to access the exception information via a variable. This can help to reduce the temptation to accidentally do a catch(Exception e){ /*...*/; throw e; } when you meant to do catch { /*...*/ throw; }.




OK cool, now what about the mechanics? Joe explains that the wrapping of RuntimeWrapperException around non-exception throwables is due to the fact that C# and VB auto opt-in all assemblies to what they call "the wrapping plan". This means there is a RuntimeCompatibilityAttribute(...) on the assembly where, in this case, WrapNonExceptionThrows=true is set. When this is the case all non-System.Exception "exceptions" get wrapped into a RuntimeWrappedException, which, as Joe points out of course does inherit from System.Exception. Conversely, if WrapNonExceptionThrows=false is set, then there is no magical wrapping.



Let's see this all in action. But before we do, last time I wrote about this I forgot to what mention happens when you compile the below code (this is the same code from the previous blog entry about this topic)


// ThrowerHarness.cs
namespace ThrowerExample
{
class ThrowerHarness
{
static void Main(string[] args) {
try {
Thrower.ThrowException();
}
catch(System.Exception ex) {
System.Console.WriteLine("System.Exception error: " + ex.Message);
}
catch {
System.Console.WriteLine("Non System.Exception based error.");
}

try {
Thrower.ThrowString();
}
catch(System.Exception ex) {
System.Console.WriteLine("System.Exception error: " + ex.Message);
}
catch {
System.Console.WriteLine("Non System.Exception based error.");
}
}
}
}


Compiling this code actually gives the following warnings...



throwerlib.cs(16,7): warning CS1058: A previous catch clause already catches all
exceptions. All non-exceptions thrown will be wrapped in a
System.Runtime.CompilerServices.RuntimeWrappedException
throwerlib.cs(29,7): warning CS1058: A previous catch clause already catches all
exceptions. All non-exceptions thrown will be wrapped in a
System.Runtime.CompilerServices.RuntimeWrappedException


As you can see, we know at compile that try{}catch(Exception ex){} will grab the exceptions.



Here's the IL we are using, which contains the Thrower class and is referenced by the C# application.



// ThrowerLib.il
.assembly ThrowerLib { }

.class public Thrower {
.method static public void ThrowException( ) {
ldstr "ThrowException exception from the IL world!"
newobj instance void [mscorlib]System.Exception::.ctor(string)
throw
ret
}

.method static public void ThrowString( ) {
ldstr "Weird exception!"
throw
ret
}
}


Of course, there's our command syntax...


ilasm /t:dll ThrowerLib.il
csc Thrower.cs /r:ThrowerLib.dll


After a successful assembly and compilation, running this application gives the following output...



System.Exception error: ThrowException exception from the IL world!
System.Exception error: An object that does not derive from System.Exception has been wrapped in a RuntimeWrappedException.


Now, what about what Joe was saying about the RuntimeCompatibilityAttribute? Well, if we were to tack the following onto our existing class, we would get absolutely no warnings. Pretty cool...



using System.Runtime.CompilerServices;
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = false)]


Not only that, but here's the output as we would expect.



System.Exception error: ThrowException exception from the IL world!
Non System.Exception based error.


As you can see it did not wrap the exception. So, now, the picture of how things work and how to modify them is a bit more complete.



You can download the code for this entry by the link below.




Joe Duffy also has an explanation of this, although his is from the Beta 2 era (I only see one change -- WrapNonClsExceptions -> WrapNonExceptionThrows; but there may be more). Here is his article.




MSDN Nuggets WCF Mania!

I just did my weekly check of the MSDN nuggets page and found that Mike Taulty has been hard at work. He just released 6 more WCF videos.




  • Message Encoding

  • Message Patterns

  • Sessions

  • Instancing

  • Concurrency

  • Exceptions



Given the great quantity and quality of videos out there on WinFX technologies there is absolutely no reason people can't learn these new technologies. You don't need to read books, study whitepapers, or listen to those Geneva-convention-violating boring webcasts, all you have to do it click and pay attention. It's as if osmosis truely is a viable way of learning!



You can access these videos at the below link.



MSDN Nuggets

Gosh I hate SPs/SQL (a.k.a. LLBLGen Rocks!)

...well at least in my C# code. That stuff belongs in the world of reporting, integration services, and other places which are NOT IN CODE. You couldn't get me to use ADO.NET anymore; it's such a pain for large projects. I love it for mass importing and when I do extremely dynamics such as report generation and a few other things, but for a static data access teir it's PATHETIC.



Not only is everything you type not strongly typed and therefore prone to error and has no color syntax; SQL (including SP calls) is just abrupt. You are doing this beautiful array of C# 2.0 greatness. Generic collections all over and BAM you see "select * from Person where..." Yuck!



Long live LLBLGen! If you don't know what LLBLGen is, you are completely missing out. I've been using it for months on all my projects and it's just downright awesome. It's basically LINQ...NOW. It allows you to use strongly typed .NET code to access your data WITHOUT writing any data tier code yourself. Not only that, the full blown enterprise edition is only $300. There is NO reason to ever write any data access layer yourself. It will pay for itself in about a DAY. I recommending getting a copy of LLBLGen even for your HOME projects!



All you have to do is point the LLBLGen app to the database, select the tables (and other entities) you want, and hit generate. It automatically creates a Visual Studio 2005 (or 2003 if you HAVE to use that icky thing) project for you. You can either include that project into your solution or compile the assembly and just us the compiled files. You only need to use LLBLGen again when you schema changes, which, as every architect knows...shouldn't be happening that often.



This rant is brought to you by the following sponsor...



DataSet dataSet1 = new DataSet( );
SqlDataAdapter sqlDataAdapter1 = new SqlDataAdapter( );

SqlConn1 = new SqlConnection(connString);
SqlConn1.Open( );

SqlCommData = new SqlCommand("GetDraftBox", SqlConn1);
SqlCommData.CommandType = CommandType.StoredProcedure;

sqlDataAdapter1.SelectCommand = SqlCommData;
sqlDataAdapter1.Fill(dataSet1, "MailList");

return dataSet1;


I was porting this old app from .NET 1.x to .NET 2.0 and I kept seeing stupid garbage like this. I got SO sick of it I decided to disconnect the logic tier and connect it to the LLBLGen access layer. Here's what I have now...

DraftMailCollection draftMailBox = new DraftMailCollection( );
draftMailBox.GetMulti(null);
return draftMailBox;


THAT'S IT!!! Short, sweet, strongly-typed, intellisense LOVES it, it's pretty (you gotta LOVE the VS2005 color scheme), and it's VERY easy to extend.



As another quick example here's how you would translate the following code into LLBLGEN code. First, the SQL code...


select *
from Person
where
PersonUserName = username and
PersonPassword = password;


Now the LLBLGen code...


   
PersonCollection people = new PersonCollection( );
IPredicateExpression filter = new PredicateExpression( );
filter.Add(PredicateFactory.CompareValue(PersonFieldIndex.PersonUserName, ComparisonOperator.Equal, username));
filter.AddWithAnd(PredicateFactory.CompareValue(PersonFieldIndex.PersonPassword, ComparisonOperator.Equal, password));
people.GetMulti(filter);


Yes, joining is also BEYOND easy and, yes, it databinds to GridViews with no extra work. I use it all the time in my ObjectDataSources.



OK one last example... well two. This one should be the straw that breaks...something. Look at this ADO.NET code (I'll leave some of it out though)



sqlCommand = new SqlCommand();
sqlCommand.Connection = sqlConnection;
sqlCommand.CommandText = "insert into Customers (CompanyName, ContactName, ContactTitle, Address, City, Region, PostalCode, Country, Phone, Fax )values(@CompanyName, @ContactName, @ContactTitle, @Address, @City, @Region, @PostalCode, @Country, @Phone, @Fax)";
sqlCommand.Parameters.AddWithValue("@CompanyName", companyName);
sqlCommand.Parameters.AddWithValue("@ContactName", contactName);
sqlCommand.Parameters.AddWithValue("@ContactTitle", contactTitle);
sqlCommand.Parameters.AddWithValue("@Address", address);
sqlCommand.Parameters.AddWithValue("@City", city);
sqlCommand.Parameters.AddWithValue("@Region", region);
sqlCommand.Parameters.AddWithValue("@PostalCode", postalCode);
sqlCommand.Parameters.AddWithValue("@Country", country);
sqlCommand.Parameters.AddWithValue("@Phone", phone);
sqlCommand.Parameters.AddWithValue("@Fax", fax);

sqlConnection.Open();

string id = (string)sqlCommand.ExecuteScalar();

sqlConnection.Close();

Some would say that it would not look so bad if the insert was in an SP. Um, ok...so you want to code in more than one place? No thank you. Also, what happens if there is no id to return? I've noticed that .NET 2.0 doesn't like that too much.



Now heres the LLBLGen code...


CustomersEntity customer = CustomersEntity( );
customer.CompanyName = companyName;
customer.ContactName = contactName;
customer.ContactTitle = contactTitle;
customer.Address = address;
customer.City = city;
customer.Region = region;
customer.PostalCode = postalCode;
customer.Country = country;
customer.Phone = phone;
customer.Fax = fax;
customer.Save( );

string id = customer.CustomerId;


Yeah...wow. Not only that, but in the SQL code you also have to do all that ADO.NET stuff. Not with LLBLGen, it's all in one!



I've been using LLBLGen for almost a year now and I have to say that my productivity has SOARED because of it. LLBLGen + .NET 2.0 + Firefox is a smart, er..., GENIUS match that should not be ignored, but rather ran towards!



To get a 30-day trial copy of LLBLGen follow the below link. I'm sure you will love it and for only $300, your manager will as well.


C# 2.0 Self-Test

In the .NET course I'm teaching (".NET Complete") I gave a little project to the class, of which all of them are new to OO design, C#, .NET, and all the related items. The project requirement was for them to study the example and see what it does. The point of the project was to allow them to test their knowledge of C# syntax, collections, generics, and nullable types



It's almost as useless as hello world. Or,rather, hello world is almost as useless as this.



You simply type in string and it tokenized it into characters...but they didn't know that. Anyhow here you go...



using System;
using System.Collections.ObjectModel;
using System.Collections.Generic;

namespace CodeExamples
{
class Program
{
class Storage<T> where T : ICollection<char>, new( )
{
private Dictionary<string, T> list = new Dictionary<string, T>( );

public void ShowLines( ){
int? i;
foreach(KeyValuePair<string, T> collection in list) {
i = null;
if(collection.Key.Length > 2) {
i = collection.Key.Length;
}

Console.Write((i ?? -1) + " : " + collection.Key + " : ");
foreach(char thing in collection.Value) {
Console.Write(thing);
}


Console.WriteLine();
}
}

public void Save(string text) {
T parts = new T( );
foreach(char c in text.ToCharArray( )) {
parts.Add(c);
}

if(!list.ContainsKey(text)) {
list.Add(text, parts);
}
}
}

static void Main(string[] args) {
Storage<Collection<char>> storage = new Storage<Collection<char>>( );

bool done = false;

while(!done) {
string text = Console.ReadLine( );

if(text == "end") {
done = true;
continue;
}

storage.Save(text);
}

storage.ShowLines( );
Console.ReadLine( );
}
}
}

New Blog

In addition to my WinFX blog I'm also going to be working on this new dynamics blog, called Dynamic Bliss. This blog will cover client-side topics such as XML based, out-of-band procedure calling ("Ajax" though I don't approve of that name), ECMAScript dynamics, dynamic graphics, widget creation, other topics from my book and a few other browser-related topics.



This blog is the replacement of a book I was working on regarding the same topic. I'm a strong believer that blogging is the new book (for technology at the moment). Parts of the blog will include video chapters from the my video book as well as my Firefox Web Development Suite videos.



You can get to the blog here, Dynamic Bliss.

Firefox 1.5 released!

The last 32 days rocked! The release of .NET 2.0 and now Firefox 1.5. Both are absolutely revolutionary in their technology.



So, go get it! Woohoo!!! The link is in the list below.



Also, I remind everybody about my "What's new in Firefox 1.5" video, which is also in the list of links below.



...and yes, Chris Pederick's Web Developer Toolbar works great with Firefox 1.5. His page link is also below...


.NET Wikipedia Entry Edit

OK so I got SICK of the horrible midunderstandings written about .NET on Wikipedia...so much so that I rewrote much of it.



As of right now, 95% .NET 2.0 material written at http://en.wikipedia.org/wiki/Microsoft_.NET was written by me. The only parts I didn't write were the top two 'changes in 2.0' bullets. I added all other .NET 2.0 content.



Here are some snippets I added regarding .NET 2.0



".NET 2.0 is a severe redesign of not only the technology, but also the model of Microsoft's .NET agenda. While .NET v1.x was considered more of a Rapid Application Development (RAD) model and was often compared with Sun's Java. C# 2.0, part of the .NET 2.0 model, is now compared more closely with C++, so much so infact, that large portions of Microsoft's Windows Vista are written in C# and the .NET framework."



I also added information about how .NET was NOT the competition for Java, but was infact originally intended to be COM+ 2.5 by one team and "Next-Generation Web Services" by another. In addition, I removed anything about .NET 2.0 betas and updated the information about the express editions to be more proper.

A few .NET 2.0 life simplifiers...

I'm starting to realize that not everyone knows everything or watches every blog in the cosmos, so I'll start including blog entires which will help people very efficiently master .NET 2.0 and WinFX.



One thing that will help people who currently fight with .NET 1.x is the following video I saw earlier this month. It's an explanation of some of the life simplifiers in .NET 2.0.



One of my favorites they talk about is is the addition of a Contains( ) method for things. Now instead of typeing "string".IndexOf("str") > -1, we can use Contains( ). My next favorite thing...well, about a tie, would be the additions of the String.IsNullOrEmpty(string) method to replace if(myString == null || myString.Length < 1). Nice...



Ok so here's the video...


"Favorite v2.0 Features in the Base Class Libraries"

WSE3 MTOM

OK, so this week I found out that that there currently is no support the the Jet database provider on the x64 platform. That didn't change the fact that I was determined to do it (or create the illusion of it). I had to create a user-approachable report generator which exported the data into Excel and sent it on to the user all via a web interface. I also didn't want to use the XML version of Excel spreadsheets (it surprises me how many times people think I'm talking about Excel 12 when I say that. You can do XML-based sheets in old Excel versions too!) So I wanted this done via ADO.NET and the Jet provider creating a "real" xls file. Obviously what I wanted to do isn't even work with the framework, but...doing it on x64 is.



The solution? Simple, WSE3 provides you with the ability to use SOAP Message Transmission Optimization Mechanism (MTOM) very seamlessly. MTOM is a new W3C recommendation used to optimize messaging scenarios that involve transmitting binary data. Technical gibberish aside, MTOM is just AWESOME. Using WSE3/MTOM, all I had to do was create a WSE3 service on a different server which created the XLS binary data and returned to back to the caller which then sent it on to the client.



Want specifics? MSDN has a document which provides you with the hands-on training you sufficient to propel you into WSE3 services: WSE3 Hands-on Lab: Messaging. MTOM is the third lab, but basically all you do is enable WSE3 (and MTOM) on the client and server, set the server up to return a byte array to the caller, call the server, and stream that byte array into a file. In my case I then sent it out to the user...



Here's my code for sending the Excel worksheet out to the user...


Response.Buffer = true;
Response.Clear( );
Response.ClearContent( );
Response.ClearHeaders( );

Response.AddHeader("Content-Disposition", "attachment; filename=" +
"AutoGeneratedReport.xls");
Response.AddHeader("Content-Length", file.Length.ToString( ));
Response.ContentType = "application/vnd.ms-excel";
Response.WriteFile(fullpath);
Response.Flush( );


I'll have to beef up on WSE3 a bit for a future SOA lecture in my WinFX/.NET course.

Cool SMS/VS2005 Integration Feature

Today I discovered a very wierd feature regarding SQL Management Studio 2005 ("SMS") and Visual Studio 2005 (of course I'm using the FREE standards editions from the MSDN/Technet seminars)



OK so here it is...



  • Open SMS

  • Navigate to a table and modify it.

  • Copy the text of one of the columns

  • Go to an ASPX page in Visual Studio 2005 and paste.



If you did it right you will see the weirdest thing in the world: it pastes a GridView linked to a SqlDataSource, which it also pastes.



<asp:GridView ID="GridView1" runat="server"
DataSourceID="SqlDataSource2"
EmptyDataText="There are no data records to display."
AutoGenerateColumns="False">
<Columns>
<asp:BoundField DataField="ContactID"
SortExpression="ContactID"
HeaderText="ContactID">
</asp:BoundField>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
SelectCommand="SELECT [ContactID] FROM [Employee]"
ConnectionString="<%$ ConnectionStrings:AdventureWorksConnectionString1 %>"
ProviderName="<%$ConnectionStrings:AdventureWorksConnectionString1.ProviderName %>">
</asp:SqlDataSource>


You will also find that it pastes the appropriate connection string directly into your web.config.



<add
name="AdventureWorksConnectionString1"
connectionString="[string omitted; it was LONG"
/>


Cool, huh?



p.s. If you want to paste that particular name, as I wanted to do, you can always do the old school paste-into-notepad-copy-out-of-notepad trick that is a tried and true way to strip off Web Browser formatting.

Atlas October 2005

If you are anything like me, you consider a technology is new as long as it's marked as experimental. Atlas still qualifies for being new...or even, pre-new. In any case, the October 2005 version of Atlas has been released and can be downloaded at the link below.



http://atlas.asp.net/

You can find a list of changes here:
http://weblogs.asp.net/atlas/

Note that unlike WCF and WPF, which in my mind are stable for production, Atlas is still experimental and is only in the technical preview stages. Not that it will explode into pieces, but there is little to no documentation on almost all of Atlas and given the early nature of the product, things are almost guaranteed to change.

Learn WCF via MSDN Nuggets

Want to learn WCF (a.k.a. Indigo)? If so, you should head on over to MSDN UK to see Mike Taulty's latest MSDN Nuggets.



http://www.microsoft.com/uk/msdn/events/nuggets.aspx

Currently there are three videos:



  • Hello World

  • Type Serialization

  • Bindings



You will find that WCF looks much like old-school COM, but has the power of MSMQ, COM+, remoting, Web Services and the simplicity of .NET. Awesome!



For more information on WCF check out this great MSDN article: http://msdn.microsoft.com/library/en-us/dnlong/html/introtowcf.asp.

New Blog Separation

Alright! So I decided to separate my professional information from my personal by creating a few separate blogs instead of having them all crammed into my website. From here on out, my website at davidbetz.net will be for my own stuff and this one here in particular will be for WinFX.



In the next few weeks I plan on putting up a lot of new information and hopefully I'll keep up a nice flow of blogging...

.NET Course I'm teaching

So, for a while now I've been teaching a .NET 2.0/C# 2.0/Object-oriented desing class and decided to come up with a simple class website.



I'm covering not only the basics, but also many advanced topics that you would only find in footnotes. Mainly I'm going to be covering stuff that I wish someone would explain to me in plain english!! So, I'm going to be spending time explaining the differences between ref and out, const and readonly, and try{}catch{} and try{}catch(Exception ex){} among other topics. You can bet that I'll be spending A LOT of time just on delegation!!



There are actually a few series going on at once: C# Language (Intro, Intermediate, Advanced), .NET Framework and Design, Object Orientation and Design Patterns, SOA and Enterprise Development, ASP.NET 2.0 (web-standards "tableless"/CSS!!!), and WinFX concepts are the series all going on in parallel.



As far as the intro ASP.NET stuff is concerned, there are great ASP.NET books out for that kind of stuff. I'm mainly focusing on the middle layer and more advanced concepts. I'm actually planning a lecture for Microsoft Atlas. Given my love for Firefox, .NET, and remote scripting (err, Ajax), that should be fun! Also in the course of things I plan on having a lecture to discuss .NET design guidelines and another lecture on the architecture and mechanics of the CLR! .NET assembly language (yeah, yeah, the IL) rules!



Now what is my supplemental book recommendation? Basically anything that Troelsen has written. His latest book "Pro C# 2005 and the .NET 2.0 Platform" is written incredibly eloquently.



I absolutely love .NET... and this should show! maybe I can get an MVP out of this :D hint hint!!



Anyhow, here's the page I threw togther for it. I'll be posting more information, links, and samples as time goes along.http://www.davidbetz.net/dotnetcourse/

Saturday, March 25, 2006

Using Xaml to Represent Objects

Since most of the WinFX (.NET) world is going to declarative programming, I think it would be wise for us API designers to starting thinking the same way. Xaml is really our key to that. We don't need to have our own XML dialect to provide a declarative model to developers, we just need to realize that Xaml isn't just a markup language for graphical controls... nor is it solely for Microsoft created frameworks (i.e. WPF, WWF). We too can tap into the beauty of Xaml by simply understanding how simple it is.



In this video I demonstrate how to create a simple data-bound WPF application using Xaml using a C# class to feed the data. Then I alter the WPF application to be purely in Xaml... even the data binding to LLBLGen.



This video is really just a proof of concept of something that I personally consider very experimental at this stage. In the future however, I do expect most WinFX coding to go hand in hand with declarative programming. In fact, you can already see how ASP.NET, Atlas, WPF, WCF (the config file), and WWF are strongly declarative based. Since Xaml is not much more than an XML representation of .NET objects, exposing an API shouldn't be that difficult for us. Most of the time I'm sure a simple framework built with SOA principles in mind should be OK.



Here's the link to download the video:




Saturday, March 18, 2006

March 2006 WCF Resources

Heres just an update on the popular resources on WCF on the web.



Some links worth looking at...




Here's a list of the video Mike has up at the MSDN Nuggets website (link above).



  • "Hello World"

  • Type Serialization

  • DataContract Serialization

  • Typed and Untyped Messages

  • Bindings

  • Message Encoding

  • Message Patterns

  • Sessions

  • Instancing

  • Concurrency

  • Exceptions

  • Transactions

  • HTTPS Transport Security

  • Message Security

  • Authorisation

  • Auditing




Friday, January 20, 2006

WCF: A self-hosted service with multiple endpoints

Last night I started playing with more more interesting things in WCF (multiple endpoints) and I kept running into a wall: how do you set more than one http endpoint on the same service!? Nothing I was doing was working, then I ran into Indigo Girl's WCF book chapters online (see my next post). Her examples clearly explain what I was doing wrong. Let me explain how to do what I wanted to do in my own words...



Instead of having a different "server" for each endpoint of the same address scheme (i.e. http), you have a a base address for and then give each a name. There is one WSDL for all the endpoints of a service. That is: one service, one WSDL; not one endpoint, one WSDL. This stems from the fact that by default there are two endpoints repackages: mex and HTTP Get. The HTTP get one is the one that will help out with the WSDL.



Here is the fixed up code. By running this up and generating the proxy, we are able to have the complete mechanism for communication from the client to the service, including the configuration file (below).



Program.cs
Uri httpUri = new Uri("http://localhost:8081/");
using(ServiceHost hService = new ServiceHost(typeof(DemoService), httpUri)) {
hService.AddServiceEndpoint(typeof(IDemoService), new BasicHttpBinding( ), "BasicService");
hService.AddServiceEndpoint(typeof(IDemoService), new WSDualHttpBinding( ), "DualHttpService");

hService.Open( );

Console.WriteLine("Listening...");
Console.ReadLine( );
}


client app.config

<system.serviceModel>
<client>
<endpoint
address="http://localhost:8081/BasicService"
binding="basicHttpBinding"
name="BasicHttpService"
contract="IDemoService" />
<endpoint
address="http://localhost:8081/DualHttpService"
binding="wsDualHttpBinding"
name="DualHttpService"
contract="IDemoService" />
</client>
</system.serviceModel>


Even when using entitely different protocols (the higher level http and say the lower level tcp), you have one WSDL. Of course in this case, since there are more one address scheme (http and net.tcp), you have more than one base address; one per scheme.

Program.cs
Uri netTcpAddress = new Uri("net.tcp://localhost:8080/");
Uri httpAddress = new Uri("http://localhost:8081/");
using (ServiceHost service = new ServiceHost(typeof(DemoService), new Uri[] { netTcpAddress, httpAddress })) {
service.Open( );

Console.WriteLine("Listening...");
Console.ReadLine( );
}


server app.config

<system.serviceModel>
<services>
<service type="WcfDemo.DemoService">
<endpoint
address="NetTcpService"
contract="WcfDemo.IDemoService"
binding="netTcpBinding"
/>
<endpoint
address="DualHttpService"
contract="WcfDemo.IDemoService"
binding="wsDualHttpBinding"
/>
</service>
</services>
</system.serviceModel>


client app.config

<system.serviceModel>
<client>
<endpoint
address="net.tcp://localhost:8080/NetTcpService"
binding="netTcpBinding"
name="NetTcpService"
contract="IDemoService" />
<endpoint
address="http://localhost:8081/DualHttpService"
binding="wsDualHttpBinding"
name="DualHttpService"
contract="IDemoService" />
</client>
</system.serviceModel>


As you can see WCF really allows for some pretty powerful scenarios...




Monday, January 16, 2006

User Control Error: The base class includes the field 'xxx', but its type (yyy) is not compatible with the type of control (zzz).

I'm not a huge user of user controls, but today I was porting an ASP app over to the real world and I figured the particular scenario I was working with didn't really warrant the power of a server control. So after I went an took the 12 seconds out of the day to create a user control all was well. It was working beautifully and all that jazz...until I published the website to the test server!




The base class includes the field 'cltFemaleItems', but its type (Items)
is not compatible with the type of control (ASP.items_ascx).


WHAT!!!! I'm marking this one as an ASP.NET 2.0 bug. After a bit of searching online I realized that there aren't really ANY workarounds to this online.



I went back and read the message again and noticed this small hint: "( ASP.items_ascx)". Below is what my user control class declaration looked like and what the declarative directive looks like. Everything looks fine...



<%@ Control Language="C#" AutoEventWireup="true" CodeFile=" Items.ascx.cs" Inherits="Items" %>

public partial class Items : System.Web.UI.UserControl


Based on the error message hint, however, changed the name of the contro. Here is what I changed the above code to...



<%@ Control Language="C#" AutoEventWireup="true" CodeFile"Items.ascx.cs " Inherits="items_ascx" %>

public partial class items_ascx : System.Web.UI.UserControl


Then I republished and viola! All it well... That's one really weird ASP.NET 2.0 bug. Anyhow, this workaround seems to work well.

Tuesday, January 10, 2006

Video 2 (FWD) - "Introduction to the Firefox JavaScript Console"

Firefox comes with many incredible utilities right out of the box. One of these tools is the JavaScript console. Most developers who have done any web development at all utilizing Firefox has used this great tool, but few know of some of the more powerful features. In this video I touch lightly on a few features that you may have overlooked.



In the next video we will dive hard core into some code to see the Firefox Web Development suite in action.