Oracle SOA briefcamp

I attended a "briefcamp" at Oracle London today. A bit of a strange one this, it was really an overview of the SOA suite. Unfortunately the demo Gods were at the very worst today and nothing really worked, a little bit worrying since this is released code but I’ve been around computers too long to worry too much about that. As my blog probably shows I’m very much a Microsoft shop developer so I have to try very hard to keep an open mind about Oracle development tools but here goes. There are a lot of comparisons to be made between the offerings from Oracle and Microsoft but from a Architectural point of view they achieve pretty much the same thing. However, in my unbiased(?) view the .net Framework seems better that the Oracle versions. I would say that you can achieve what want with Oracle but the tools are unpolished, they have the feel of tools that are 5 years old. The demonstrator was pleased to show off the fact you could create a web service from a component in one click…really, that’s something I demand from a dev’ tool, not something I’d hope was there. The biggest gap for me was in configuration. An example give was the way of avoiding the performance cost when communicating with a web service. Oracle have a special in-memory type of wrapper that allows you to call a web service but really it doesn’t use http (et el). The problem is that if you use this wrapper you lose the portability of moving the service to a different location, i.e. the other side of a firewall. I asked how do you configure it to use the web service rather than the in-memory wrapper thinking that it would be like Microsoft’s Communication Foundation, "you recompile it" was the answer…hmm not exactly SOA in my book.

Overall though I’m not knocking Oracle on this, what is clear is that whether you chose Oracle or Microsoft as your preferred development platform, they both will do pretty much the same thing, it will probably come down to past preferences and political issues more than technical advantages…although I prefer Microsoft’s 😉

Programmatically Wake Up On Lan using .net

I’ve been meaning to write a web site to list a number of machines and allow the user to issue a Wake Up On Lan command to them. Looking around the web I found a great VB sample to issue the command. However, I didn’t want to pollute my nice c# with yukky VB  so converted it to c# and changed a few bits to bring it align with Microsoft standards.
 

using

System;

using

System.Collections.Generic;

using

System.Text;

using System.Net;

using

System.Net.Sockets;

using

System.Globalization;

 

namespace

Utilities.Network

{

/// <summary>

/// Utility class to wake machines up that are configured to "Wake Up On Lan"

/// </summary>

/// <remarks>Code orginally written in VB from http://www.lucamauri.com/snippet/snip.aspx?id=6</remarks>

public sealed class WakeUpOnLan

{

/// <summary>

/// Initialise using the default values

/// </summary>

/// <remarks>The default IPEndPoint transmit on port 7. Other choices for WOL are port 0 or 9</remarks>

public WakeUpOnLan()

{

this.endPoint = new IPEndPoint(IPAddress.Broadcast, 7);

}

/// <summary>

/// Initialise using a specific port

/// </summary>

/// <param name="port">A valid port number</param>

/// <remarks>If the port number is invalid, the IPEndPoint is created to port 7. Ports normally used for WOL are 0, 7 or 9.</remarks>

public WakeUpOnLan(int port)

{

if (port >= 0 && port < 65535)

{

endPoint =

new IPEndPoint(IPAddress.Broadcast, port);

}

else

{

endPoint =

new IPEndPoint(IPAddress.Broadcast, 7);

}

}

 

/// <summary>

/// The IPEndPoint object that will act as a trasport for the packet.

/// It is automatically created by New statement, but you can modify it or read it.

/// </summary>

/// <value>An IPEndPoint object</value>

/// <returns>An IPEndPoint object</returns>

/// <remarks>Normally there is no need to change this manually.</remarks>

public IPEndPoint EndPoint

{

get

{

return this.endPoint;

}

set

{

this.endPoint = value;

}

}

/// <summary>

/// The target machine Network Interface Card MAC address.

/// It must be dash-separated, i.e. in the 11-22-33-44-55-66 form

/// </summary>

/// <value>A string with dash-separated values</value>

/// <returns>A string with dash-separated values</returns>

/// <remarks>The standard (IEEE 802) separator for cotet are dash (-) and semicolon (:). I resolved to use dashes only in order to avoid any possible confusion and misunderstanding with upcoming IPv6 addressing space.</remarks>

public string MacAddress

{

get

{

StringBuilder textMAC = new StringBuilder();

foreach (byte currByte in this.macAddress)

{

textMAC.Append(

"-");

textMAC.Append(currByte.ToString(

"X2"));

}

return textMAC.ToString().Substring(1);

}

set

{

if (String.IsNullOrEmpty(value))

{

throw new FormatException(MacFormatMessage);

}

Queue<byte> values = new Queue<byte>();

string[] hexValues = value.Split(‘-‘);

if (hexValues.Length != 6)

{

throw new FormatException(MacFormatMessage);

}

foreach (string currByte in hexValues)

{

byte convertedByte;

if (Byte.TryParse(currByte, System.Globalization.NumberStyles.HexNumber,

CultureInfo.InvariantCulture, out convertedByte))

{

values.Enqueue(convertedByte);

}

else

{

throw new FormatException(MacFormatMessage);

}

}

this.macAddress = values.ToArray();

}

}

/// <summary>

/// Total bytes sent by WakeIt method. It is 0 until the method is called at least once for this class instance.

/// </summary>

/// <returns>Integer value, total bytes trasmitted</returns>

/// <remarks></remarks>

public int BytesSent

{

get

{

return this.bytesSent;

}

}

/// <summary>

/// It represent the Magic Packet broadcasted.

/// </summary>

/// <returns>String containing the text parsing of the Magic Packet</returns>

/// <remarks></remarks>

public string PacketSent

{

get

{

return packetSent;

}

}

/// <summary>

/// Creates a WOL Magic Packet, the datagram that will awake the target PC upon broadcast on the network.

/// </summary>

/// <param name="macAddress">An array of byte representing the target machine Network Interface Card MAC address</param>

/// <returns>An array of byte representing the Magic Packet</returns>

/// <remarks>This method can be used indipendently from the rest of the class. If necessary it can create a Magic Packet just providing the MAC address.</remarks>

private byte[] MagicPacket(byte[] macAddress)

{

if (macAddress.Length == 0)

{

throw new FormatException("Invalid MAC address");

}

byte[] payloadData = new byte[0];

StringBuilder packet = new StringBuilder();

 

payloadData =

new byte[HeaderLength + MacLength * repMAC];

for (int i = 0; i < HeaderLength; i++)

{

payloadData[i] =

Byte.Parse("FF", System.Globalization.NumberStyles.HexNumber);

}

for (int i = 0; i < repMAC; i++)

{

for (int j = 0; j < MacLength; j++)

{

payloadData[HeaderLength + i * MacLength + j] = macAddress[j];

}

}

foreach (byte currLoad in payloadData)

{

packet.Append(

"-");

packet.Append(currLoad.ToString("X2"));

}

packetSent = packet.ToString().Substring(1);

 

return payloadData;

}

private int SendUdp(byte[] payload, IPEndPoint endPoint)

{

int byteSend;

if ((payload != null) && (endPoint != null))

{

Socket socketClient = new Socket(endPoint.AddressFamily, SocketType.Dgram, ProtocolType.Udp);

socketClient.Connect(endPoint);

byteSend = socketClient.Send(payload, 0, payload.Length,

SocketFlags.None);

socketClient.Close();

}

else

{

byteSend = 0;

}

return byteSend;

}

/// <summary>

/// It is the main method of the class. It must be called after the MAC address has been set. It does not return any code, you can see the result of the operation with the bytesSent and packetSent properties of this class.

/// </summary>

/// <remarks></remarks>

public void WakeIt()

{

bytesSent = SendUdp(MagicPacket(macAddress), endPoint);

}

const int HeaderLength = 6;

const int MacLength = 6;

const int repMAC = 16;

const string MacFormatMessage = "Mac Format should be; XX-XX-XX-XX-XX, e.g. 00-13-71-BC-C2-CE";

IPEndPoint endPoint;

byte[] macAddress;

int bytesSent = 0;

string packetSent;

}

}

Calling the instance of a ContextBoundObject

ContextBoundObjects are useful for implementing Aspect Orientated Programming (AOP), however one thing that I wanted to do was to call methods on the instance that the context "shadows". Since it caused me some pain I though I’d publish it here to avoid others suffering as I did.
 
1. Save the MarshalByRefObject that is passed into the AttributeContext, this represents the object that we’re shadowing

public IMessageSink GetObjectSink(MarshalByRefObject obj, IMessageSink nextSink)

2. Assuming you can put your AOP attribute on any class, you’ll need to get hold of the type that is really inside the Marshalled object. There are a number of ways of doing this, this was the first mechanism I tried and it worked so I left it at this

private

void Postprocess(IMessage msg, IMessage msgReturn)

…msg.Properties[

"__TypeName"];

3. Marshal the object into the discovered type and call methods on it. All done.
 

Type

sourceType = Type.GetType(typeName);

ObjRef objectRef = RemotingServices.Marshal(this.sourceMarshalByRefObject,null,sourceType);

object o = Activator.GetObject(sourceType, objectRef.URI);

if (o is IMyKnownInterface)

{

IMyKnownInterface myInterface = (IMyKnownInterface)o;

myInterface.MyMethod()

 

A couple of File path tips in Visual Studio 2005

I thought I’d share a couple of VS tips related to file paths:

1. Copy full path from the tab
The simplest way to get the full path to a source file is to open the file in the editor and the right-click the source panes tab. One of the options is to copy the full path
2. Quick way to open another file located in the same folder as an existing  source file
When you have a number of source files opened from various locations it can be frustrating to go through the File->Open and navigation process time and again. One trick is to keep open an existing project file located in the folder you want to navigate to. When you select File->Open it will start in the same folder location as the active file in the editor.

Cannot add databases on Windows XP or can I?

When I installed SQL Server 2005 on my Windows XP machine everything seemed to work fine. However, whenever I tried to create a new database via the Workbench I’d get an error complaining about COM+ initialization. I tried "everything" but couldn’t persuade it to work. Eventually I gave up! However, I recently installed IE7 and discovered that I couldn’t type a new URL into the address bar and have IE goto that page. After trawling the web I found someone with the same problem and the solution was to uninstall the NVidia (motherboard) firewall client. It suddenly struck me that perhaps that was the cause of my SQL Server problems and…yes it was! SQL Workbench is now working correctly. Bad old NVidia 😉
 

Mocking Framework

The projects I work on make use of Unit Testing via the NUnit Framework and the TestDriven Visual Studio addin. However, we haven’t made use of a Mocking Framework and I finally decided to have a look around and a quick experiment.
The basic problem is that you want to test the working of a method/property on a class but you don’t want to let the class call further dependant objects. Why not? The most important reasons for me is that I don’t want to configure a whole system in order to run a simple test.
A number of Mocking Frameworks use the ‘Mock Object Pattern’ that relies upon the dependant service classes always exposing interfaces. I really don’t like this pattern, ok some would argue that it is good OO to always expose an interface, but I don’t like implementing code features for the sake of supporting a framework that isn’t required for the solution. But the real problem is that I now have to pass the interfaced object into the dependant clients…NO!
So I quickly gravitated to TypeMock which uses the CLR Profiler to intercept the calls to the services and inject code to mock the results. It’s very good, however IMO the documentation is surprisingly poor. I recommend reading through the Test Patterns documents but the code snippets do have a few bugs. So I’ve included a VS2005 solution (ConsoleApplicationTypeMock.zip) with this blog entry that implements the first authentication sample. I’ve used it a few times to test my tests when I get bugs with the mocking framework.
Another quick tip, when you do get errors from the Mocking Framework, pay very close attention to the "type" in the message.

A fundamental difference between OSX (UNIX) and Windows

I spend most of coding time using .net and Windows. However, I do like to experiment in the world of OSX, hence my interest in MONO. It’s pretty low down and dirty and really it doesn’t feel like development on Unix has moved on in the last 10 years having to use command line arguments and the like, I mean really! 😉 This isn’t for me, so I went looking for a nice development IDE and found things like the monodevelop project. Then the eureka moment for me. After reading the instructions for Linux I found a link to someone with instructions for OSX. Part of the instructions included a warning that recompiling these libraries may have an adverse effect on the system…or something like that. There you have it, UNIX is great no doubt, but to get into it you really have to be brave. Windows, these days, mothers us far too much but it’s difficult to accidentally foul it up just by compiling your code. Whereas in UNIX everything is still about running scripts and making changes that make your buttocks clench. I do detect a real effort in both UNIX variants and Windows to protect the system from the user and to provide much better installation mechanisms. So I’ll probably drag my feet with Mono until I get a lovely installer that works directly with OSX rather than via GNome or the like.

An Inconvient Truth

Just watched this "film". I have to say that I had a pretty good idea what was going on, I’ve not actually lived in a cave for the last 10 years, but this is a really well presented argument. I was tempted to say arguments but really there is only one basic issue.  If you’ve not seen this film then do the World a favour and invest 90mins of your life.

Wireless tab gone…and back again

I made the fatal mistake of opening the E2C, a "helper" communications program. Suddenly I couldn’t connect to the web. Worse still the wireless tab (Windows Mobile 5) had completely disappeared! After about a days worth of fiddling around I sat down, opened my laptop and got ready for one last attempt. Without doing anything the wireless tab was back, 2 mins later I was back on the web, very weird. So if the tab goes, close everything down, maybe even soft reset and then leave it for a while. I know, sounds more baking a cake but hey that’s all I did.

SEO, how long does it take to get indexed?

I often read or hear people talking about Search Engine Optimizations (SEO) and how to get their site at the top of a search engine list. I’m not going to repost the good ideas (see http://www.clearbreezedesign.com/searchable.htm for a good introduction) or go on about all the nonsense and superstition surrounding the subject but merely share my experience with two major search engines, MSN and Google.

After launching a site and sending the details to both MSN and Google the speed to getting an index was dramatically different. MSN showed the site after only a few weeks whereas Google took close onto 10 months to becoming fully indexed. At the start I used Google Alerts to register my interest in the words used by the site and got the odd alert about unrelated sites. During this time the web logs were showing that Google had indexed the site but no index and no alerts. Then after the 10 months the site was suddenly indexed and I started to get a steady stream of alerts for each of the pages of the site. I’d never claim to understand how Google works or how it will work tomorrow, but my observations are that Google does seem to index a site and at some point later the index becomes public knowledge. Now whether this is down to the well touted Sandboxing of sites or simply a queue of indexes I can only guess. But if you’ve designed your site correctly and are tearing your hair out wondering why you’re not getting a Google index, then don’t fret too much but be prepared for a wait. Maybe just everyone you meet to use MSN 😉