Friday, March 28, 2008

From MCT to DPE !!

I've just signed my contract to start working as a .NET Platform Developer Evangelist with Microsoft!! I'm really excited to be part of the Microsoft team here in Malta and some of the challenges that lie ahead are really great. It's a chance to interact in a deep way with some great people that work on the Microsoft products that I've used everyday and taught so many people how to use, plus the chance to get involved with a lot of the cutting edge technology that Microsoft are currently working on.

If ever you've heard the term above and wondered what exactly it's all about, here is a quick run down.

  • Engaging the broad community of Developers in Academia and the public and private sectors,
  • Driving excitement around Microsoft's software developer related technologies,
  • To interact through events, specialist training workshops, community engagement, relationship marketing and the growth of an exciting solutions portfolio.

More details to follow as I find out more about the role!!!

Wednesday, March 26, 2008

Domain specific language - Primer

Perhaps you may have seen this term in VS2008 when it loads up on the start screen or perhaps you have seen it in some academic course of study, or perhaps you have no idea what it is!! Well this short post will hopefully give you some answers to what it is, why you need it and how to get started using it.

What is it?
Well firstly it is not a GPL, a general purpose language like VB.NET,C# or any other programming language that lets you code using a specific language to suite a diverse set of tasks. It’s actually the other way round, it’s useful for a specific task to fix a problem within that domain. Using it allows you to build a modeling tool or define a modeling language for that task. It also makes implementing the solution to that problem a lot easier, however it does shift a lot of the work up front. i.e developing the tool is hard work, but once it’s built it’s a lot easier to solve problems using it!!! Domain-specific languages focus on doing one kind of task well. It’s kinda like UML, but without the U.

What can you do with it?
For example, you can create a specialized language that describes a user interface, a business process, a database, or the flow of information, and then you can generate code from those descriptions. The DSL does not have to fit just IT or programming tasks, you may wish to model other things like solar systems. By using Domain-Specific Language Tools, you can create a custom graphical designer that uses your Domain-specific diagram notation. You can then create custom text templates that use models that are created in your designer to generate source code and other files.
What tools are there out there?

What does the VS2008 DSL tool consist of ?
· A project wizard that creates a fully configured solution. In this solution, you can define a domain model that consists of a designer and a text output generator. If you run a completed solution from inside Visual Studio, a test solution opens in a separate instance of Visual Studio so that you can test the designer and the text output generator.

· A graphical designer for defining and editing domain models.

· Designer definitions in XML. The code for implementing designers is generated from these definitions so that you can define a graphical designer hosted in Visual Studio without manually writing any code.

· A set of code generators, which take a domain model definition and a designer definition as input and produce code that implements both of the components as output. The code generators also validate the domain model and the designer definition, and they raise errors and warnings accordingly.
· A framework for defining text output generators. These template-based generators take data (models) that use a domain model as input and generate text output that is based on the template. Parameters in the template are substituted by using the results of running a Visual C# script that is embedded in the template.

What VS editions support DSL
For creating a DSL you will need any of the following:
· Visual Studio 2008 Professional Edition
· Visual Studio 2008 Team Edition for Software Architects
· Visual Studio 2008 Team Edition for Software Developers
· Visual Studio 2008 Team Edition for Software Testers
· Visual Studio 2008 Team Suite

In order to use the DSL you create you will need on of the following VS IDE’s@
· Visual Studio 2008 Standard Edition
· Visual Studio 2008 Professional Edition
· Visual Studio 2008 Team Edition for Software Architects
· Visual Studio 2008 Team Edition for Software Developers
· Visual Studio 2008 Team Edition for Software Testers
· Visual Studio 2008 Team Suite

OK so not much choice, you can’t use VS2005 or 2003 I’m afraid.

OK enough already! How do I create a DSL? That will be the topic of my next post!!

Thursday, March 20, 2008

New Visual Studio 2008 Certifications

Microsoft Learning have released six MCTS certifications on Visual Studio 2008. Two exams are required for each, just like for the 2005 track, and luckily the same code is required for all six, and it's the same core exam that was used for 2005 certifications.

The following core exam is required for all six certifications.
Exam 70-536: TS: Microsoft .NET Framework 2.0 – Application Development Foundation

The actual certifications can be divided into two, ones which are the .NET Framework 3.5 versions of the previous tracks, and those wich are brand new technologies.

Similar to the previous ones are:
  • MCTS: .NET Framework 3.5, Windows Forms Applications, Exam
  • MCTS: .NET Framework 3.5, ADO.NET Applications, Exam 70-561
  • MCTS: .NET Framework 3.5, ASP.NET Applications, Exam 70-562

Brand new technologies are:

  • MCTS: .NET Framework 3.5, Windows Presentation Foundation Applications, Exam 70-502
  • MCTS: .NET Framework 3.5, Windows Communication Foundation Applications, Exam 70-503
  • MCTS: .NET Framework 3.5, Windows Workflow Foundation Applications, Exam 70-504

Most of these exams have not yet been released but should be available this month or next

Monday, March 17, 2008

My new Gadget I forgot to blog about

This is something I got back in January from Berlin. I MUST say a great big THANK YOU to Tjeerd Veninga at Microsoft for asking me to help as part of the MCT planning Commitee for the MCT summit. It was great collaborating with so many great people around Europe and then to finally meet them all at such a great event.

Anyway was was the gadget, well its a Solar powered charger that is so versatile!! It's made by a company called PowerGuy. They do loads of battery stuff but this is great. It can be charged from the mains, the USB on a PC or by the sun, which here in Malta is abundant!!! Once fully charged it can discharge into any device, loads of phone models, including my HTC touch!!! Here are some picks:

Sunday, March 16, 2008

Low audio volume on HP 6820s laptop

I had a client bring over his laptop saying that the sound was really quiet, even with the volume pumped up to the max!! Then he said perhaps it's because there is only sound coming from one speaker. I thought that one speaker had gone so I plugged in some headphones and sure enough both worked and balance shifted the sound from one ear to the other. However on the built in speakers it had no effect. I thought, hmm looks like a mono speaker system, but who makes them now a days?? Well checking the HP site here, confirms stereo mic and headphones but MONO built in speaker, what the heck!! So I guess the moral is always check the small print!!

Thursday, March 13, 2008

Really Simple .NET Remoting Tutorial with VB.NET

So I've seen lots of examples of remoting on the net, this is not a new topic, but for some it can be a tough subject. Add to this the fact that many choose C# and some just want a good old VB sample so here goes for my longest post to date!!!

So what is remoting anyway
It lets you call objects located in different processes and on different machines just as though they were within the same application, much like when you call a .dll referenced by your app.

So you may say we can do this with WebServices, true, but here the requirement is that both client and server MUST reside on the .NET framework. So with the interoperability gone we get much better performance with a little more complexity.

How to go about it: Server side
First thing we have to do is make our class remoteable by inheriting from MarshalByRefObject.

Public Class clsRemoteObject
Inherits MarshalByRefObject

Public Function getRemoteString() As String
Return Now.ToString()
End Function

End Class

Make sure you put this code in a new class library project and call it: RemotingClassLib

This can then be hosted in any of the following:

  • Console (Must be started manually, but simple to administer)
  • Windows App (Must be started manually, but simple to administer)
  • ASP.NET Web App (Limited to HTTP, but you have session state, start up automatically etc)
  • Windows Service (Use Fast TCP comms, Start automatically but can e complex)

The host must then register a channel to accept incoming requests on. This is important! Most problems arise because of mis-configurations between client and server settings.

Now create another project in the same solution called ConsoleHost and chose the console Application type. Type any of these 3 in the Sub Main.

Create and register a TCP channel:
 Dim tcpChannel As IChannel
tcpChannel = New TcpServerChannel("8085")
ChannelServices.RegisterChannel(tcpChannel, False)
Same for an HTTP and now, new to .NET 2.0, IPC
 Dim  httpChannel As IChannel
httpChannel = New HttpServerChannel("8086")
ChannelServices.RegisterChannel(httpChannel, False)
 Dim  ipcChannel As IChannel
ipcChannel = New IpcServerChannel("Server")
ChannelServices.RegisterChannel(ipcChannel, False)

Next, hook up our remote class to the registered channel. Again you can use any of the following.

The type of object instantiation can also be controled in the hosting app:

  • Singleton: Good for multiple calls where server maintains object between calls and also state:
    RemotingConfiguration.RegisterWellKnownServiceType( _
GetType(RemotingClassLib.clsRemoteObject), "MyRemoteObject", _
  • SingleCall: Good to keep overheads down 
    RemotingConfiguration.RegisterWellKnownServiceType( _
GetType(RemotingClassLib.clsRemoteObject), "MyRemoteObject", _
  • ClientSide Activation: Client controls activation and recieves a dedicated object.
    RemotingConfiguration.RegisterActivatedServiceType(  _

That’s all for now on the server side, now to the calling client!

The Client Side
Here we must reference the Classlibrary that contains the class we wish to instantiate. Oh you say, that kind of negates the whole point because this will take a local copy, then if we update the class library we have a problem. Yes you are absolutely right but what you should do is create an interface in a separate assembly. Then implement that interface in your class library, after setting a reference to the interface library. Then you get the client remoting app to reference the interface also. This way your implementation code is not copied to the client. I’ll tweak the code at the end of this article, but for now let’s keep it simple. So with the reference we can instantiate the object, all we need is a line to redirect calls to methods on this object to the remote object, easy:

Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles Me.Load

RemotingConfiguration.RegisterWellKnownClientType( _
GetType(RemotingClassLib.clsRemoteObject), _

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click

Dim rs As New RemotingClassLib.clsRemoteObject
Me.Text = rs.getRemoteString()

End Sub

That’s it !!!!

Refactor!™ for Visual Studio® - Refactoring support for VB.NET at last

Well C# has had it since 2005 and VB still does not have it. However here is a way to get some of the goodies until it gets added as part of the standard IDE. This is the free version and it has some good stuff. Be sure to register to get the bonus free refactoring goodies. No quite the same as C# but it's a start. If you want the works, the go to the PRO version, ( or C# :) )

Friday, March 7, 2008

Getting ready for Silverlight 2.0 - Part 1

The Silverlight 2 Beta 1 is here. It now includes support for mobile devices and is another step towards helping developers create Rich Internet Applications (RIA). Silverlight 2 includes a cross-platform, cross-browser version of the .NET Framework, and enables a rich .NET development platform that runs in the browser. Developers can write Silverlight applications using any .NET language now (including VB, C#, JavaScript, IronPython and IronRuby) as opposed to having to learn JavaScript as with previous versions. WHat's more it does not require the .NET Framework to be installed on a computer in order to run. The Silverlight setup download includes everything necessary to enable all Silverlight features on a Mac OSX or Windows machine.

So let's get things started:
  1. Install the .NET Framework 3.5 (if you have VS2008 this is not necessary, you have it already) first before you install Expression Blend 2.5.
  2. Install Silverlight 2 Beta 1
  3. Install Expression Blend 2.5 March 2008 Preview (25 megabytes)

My next post will take you through creating you first project.

Customising the WebService Help Page

I remember someone asking this question when I was in a course a long while back and the trainer had said, yeah it can be done,but he didn't tell us how :)

So some years later I'm gonna show you how.

The trick is in the Web.Config. Inside System.web you can set up a WebServices Tag and then include a wsdlHelpGenerator Tag to place your settings. Some options are now available:

Turn of ALL WSDL and Help!!
<remove name="Documentation"/>

Or you can point it to your own file:
<wsdlHelpGenerator href="Default.aspx"></wsdlHelpGenerator>

But like this you have to do the whole page again yourself, there must be an easier way to just add some custom bits like a compnay logo, contact details etd, well there is. If you dig around, %Windows%\Microsoft.NET\Framework\v2.0.50727\CONFIG you'll find a file called DefaultWsdlHelpGenerator.aspx. Now you know what you have to do: Copy it and customise it :) if you want just your webservice changed, or alter it to alter all WebService DOcumentation across the whole machine!!

Adding a WebReference to a Windows Forms Application in VS2008

I'm on a blog posting frenzy this week, since I'm not training :) What with country elections rapidly approaching this weekend!!

So adding a webreference was very straight forward in VS2005, just right click the project and select Add WebReference.

In VS2008 it is still easy if you are making the reference from a Website ASP.NET app, but try and do it from Windows!!! This is usually one of my favourite demos to show how VS makes it so easy for a windows forms to consume data server across the web. Well we all know that SOA is upon us and so the asnwer is in just that. Ideally we would have a WCF app to consume, not the Webservice directly.

We could go down this route but I will save that for another post ;) To do it the 'old way' we start with a right click on the project and select Add Service Reference. You should now see a new window like this.

Two options exist: The WS way or the WCF way.
  • Clicking Discover will find the Webservice in the solution and create a Service reference that must be consumed via the WCF route.
  • The other way is to click Advanced at the bottom and then select WebService. The rest should be very familiar!!

    What's really interesting is that fact that once you have one WebService Reference you can now do it the old way!!! Right click and you get the image below !!

Wednesday, March 5, 2008

Thank you ProcessMeNtOR for the Bottle Warmer!!

I've been meaning to post this since I got back from Barcelona! These cool thermos beer bottle coolers are great at keeping our baby's bottles warm for atleast 4 hours!! My wife loves them and wants more!! :)
Thank you ...

Creating a One-Way Webservice to improve responsiveness

By default a call to a webmethod will wait for the webservice method to complete the whole webmethod, even if it does not return a value. Now you could invoke the method Asynchronously, but considering you don't care what comes back, because nothing its gonna come back why bother? Well let's see how you can make the method one way, so processing resumes on the client straight after the call to the method. Consider the following:

<SoapDocumentMethod(Oneway:=True)> _
<WebMethod()> _
Public Sub Oneway()
End Sub

<WebMethod()> _
Public Sub Twoway()
End Sub

And then we would call theses like this:

Dim proxy As New localhost.Service()
Dim dtStart As New Date
dtStart = Now
MessageBox.Show(DateDiff(DateInterval.Second, dtStart, Now))
dtStart = Now
MessageBox.Show(DateDiff(DateInterval.Second, dtStart, Now))

When you run the code the one way method returns instantly, no delay, the two way will wait 10 seconds and stall the client app!!

Using Session State in a Webservice AND calling from a Windows Form

So setting up a WebMethod to use Session is not that difficult:

<WebMethod(EnableSession:=True)> _
Public Function HelloWorld() As String

If Session("FirstCall") Is Nothing Then
Session("FirstCall") = Now
End If

Return Session("FirstCall")
End Function

And calling this from a webform is not a problem since the browser can handle session information in a cookie etc. However it gets just a little tricky when you call it from a windows form because it has no idea about cookies. So you have to take care of it in the call like this:

Private Cookies As System.Net.CookieContainer

Private Sub Button1_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button1.Click

Dim proxy As New localhost.Service()
' Set the Cookie Container on the proxy
If Cookies Is Nothing Then
Cookies = New System.Net.CookieContainer()
End If
proxy.CookieContainer = Cookies

End Sub

A great explanation can be found here:

Caching a WebService Call

<WebMethod(CacheDuration:=10)> _
Public Function HelloWorld() As String
Return "Hello World" & Now
End Function

The duration is defined in seconds.

Tuesday, March 4, 2008

devNET Malta is now a member of Culminis

A few days ago our Maltese .NET Developer Usegroup was accepted as a member of Culminis.

Culminis is an international not-for-profit organization devoted to the development and growth of the IT community. After supporting and connecting professional user groups and associations, student organizations, and solution providers for more than two years we have come to understand the goals and needs of each group, as well as the resources they have to share. With this knowledge we are developing programs that ensure a meaningful and equitable exchange of those resources, ultimately elevating the status of the IT Pro both in their industry and in the community.

This is a greatopportunity for us to contribute globally to .NET development as well as allow us to benefit from the support of a global network of IT professionals that share our same goals... To make IT Fun!!

Cannot reply to email through Outlook Web Access (OWA) on Windows Vista

Just had a call this morning form a client that was trying to reply to email through the SBS 2003 Outlook Web Access Client. The thing is on Windows XP all works OK and Internet Explorer 7 is installed on both machines. Now after suggesting Firefox as a quick fix I dug deeper. It seems that Firfox will use OWA basic mode by default and so the problem would appear Client side or browser based. However this is not true, it's actually Server side. Exchange uses ActiveX that will not work on Vista. So you have two choices:

  • Work in Basic mode in IE7 or Firefox and lose some of that great Webclient interface or

  • Install the this MS fix to use iFrames on the exchange server!!

Monday, March 3, 2008

Alias a namespace/library in C# with Using;

Just a quick tip on how to make your code a little shorter... and yes this is my first C# post :)

Have a look at the using directive help on the MS site here.

This allows you to turn this:
System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection();

into this:
using myData=System.Data.SqlClient;

myData.SqlConnection = new myData.SqlConnection();

This is much moreuseful when you have to work with smo in Microsoft.Server.Management.Smo!!!!

Big thank :)

Just wanted to drop a BIG THANK YOU to everyone who visits my blog and also those that leave comments. The hit stats are looking quite respectable now, almost 2000 a month is not too bad!! I will do my best to boost my input over the next few months with more on VS 2008 and most especially Silverlight. So please keep coming back :)

Multiple connections to a server or shared resource by the same user, using more than one user name, are not allowed.

I was removing WinXP clients from a domain and then joining them to a newone the other day and came across this error:

Multiple connections to a server or shared resource by the same user, using more than one user name, are not allowed. Disconnect all previous connections to the server or shared resource and try again.

My leaving the domain was fine, it was the joining the domain that was the problem. However I had failed to read the message, I still had mapped drives to the shared folders on the old domain with the same user nameand folders. So I quickly disconnected the shares and the joining to the domain was instant!! I could then remap them all again.

Moral of the story: READ THE ERROR MESSAGE!!! They sometimes make sense :)