
Quick test of the Azure WCF service
Azure now has support for input endpoints on Worker Roles! (Azure Tools Nov 2009) This is awesome as it greatly simplifies building WCF services in the cloud. David Aiken has written an excellent Channel 9 post on exactly how to do this (here).
As per usual, I’ve gone ahead and ported the most important components to F# and I have included a short list of some of the difficulties I had while doing so.
Lessons Learned;
1. In Azure, you cannot just specify the input endpoints in code, you have to specify the endpoints in the properties for the role. It will work in the Dev fabric but will not initialize in the cloud. (thanks to Daniel C Wang)
Wrong:
let baseAddress = Uri("http://kapow.cloudapp.net:8080/service")
let myServiceHost = new ServiceHost((typeof<GreetingService>), [|baseAddress|])
Right:
using Microsoft.WindowsAzure.SerivceRuntime;
var listenAddress = RoleEnvironment
.CurrentInstance
.InstanceEndpoint["<name of your input endpoint >"]
.IPEndpoint;
string uri = String.Format("http://{0}" ,listenAddress)
2. TryGetValue can return the value in a 2-tuple instead of by ref – this makes it a lot more F# friendly. (from here)
This:
SessionInformation session;
bool exists = sessions.TryGetValue(sessionId, out session)
Becomes this:
let (exists,session) = sessions.TryGetValue(sessionId)
3. KnownTypes – By default, you cannot use a subclass of a data contract class instead of its base class. This took me a while to figure out. (From Programming WCF Services – O’Reilly)
In C#:
[DataContract]
[KnownType(typeof(Custoemr))]
class Contact
{..}
[DataContract]
Class Customer : Contact
{..}
4. You have to take down an Azure deployment in order to change the input endpoints, so no in place upgrades with new endpoints. The Dr. Watson error for this wasn’t very clear.
Things I still can’t figure out;
I am assuming that the ICommunicationObject interface is added by an attribute, I just can’t cast to it. I get an invalid cast error at runtime. I need to do this, so if anyone knows how, please let me know.
In C#:
((ICommunicationObject)client).Abort();
In F#: (from here)
(box client :?> ICommunicationObject).Abort()
The Code:
Continue reading »