Blogging, Conference, TechDays09, Twitter, WCF

Twitterized

Since all the cool kids are hanging out at Twitter, I am too. I’m slightly late to join the party, but at least I made it.


With the upcomming TechDays I meaned to keep it updated with my experiences during the conference, however my Xperia X1 smartphone has become broken just in time, and my loaner is a 3 year old sonyericsson with no internet capabilities, so we’ll see how that goes. My alias is JoHed.


Although you should expect my Twitter space to update much more often then this blog, We’re also just starting up two new BizTalk projects, as well as doing some really interesting internal work, so I’m sure I’ll continue to have lots to write about here as well.


Another announcement worthy of being mentioned in the blog as well as on Twitter is that not only did I recently pass my WCF exam (70-503), I also did so in time before begining to teach the WCF course I had scheduled to start this week. It’s a multi-week engagement taking place in the evenings, with the goal being that people will have a try at the certification, so we’ll see how that works out. I have high hopes.

.NET 3.5, Download, WCF

How-to: Get status from a windows service?

I was asked: “How can I call into a Windows Service to get it’s status?”


A little more background said that status was to be retrieved by clients (a website) on the same machine.


My response was to use WCF with the NetNamedPipeBinding. Since the recipient of my response, by his own accord, was unaccustomed to WCF, I decided to write up a small app that showed the concept.


The key thing here is that service expose an endpoint at an address that looks like this: net.pipe://localhost/ServiceMonitoringEndpoints/<name_of_service>. Name of service will be the same name as the ServiceName property of the ServiceInstaller component. This enables us to et the status of an arbitrary service just by knowing its name. First we look at the status through ServiceController and then, if the service is running, we call the WCF service to get the actual status, in this case in the form of a string. Pretty simple, wrapped up in a Library component ready to be used by both Windows Service servers and their clients. The Windows Service server is configured through its config file in my sample, but that’s something you can alter should that be one of your requirements.


Basically the server configuration is (mex of course not really necessary):

<services>
  <service behaviorConfiguration=“includeExBehavior”
      name=“SharedMonitoringUtilityLibrary.MonitoringService”>
    <endpoint address=“” binding=“netNamedPipeBinding”
              contract=“SharedMonitoringUtilityLibrary.IMonitoringService” />
    <endpoint address=“mex” binding=“mexNamedPipeBinding”
              contract=“IMetadataExchange” />
  </service>
</services>

and the it uses one of ServiceHosts constructors to supply that takes type and address:

protected override void OnStart(string[] args)
{
    host = new ServiceHost(typeof(SharedMonitoringUtilityLibrary.MonitoringService),
        new Uri(“net.pipe://localhost/ServiceMonitoringEndpoints/MonitorMeWithWCFService_Service1/“));
    host.Open();
    MonitoringService.Status = “Started at ” + DateTime.Now.ToString();
}
protected override void OnStop()
{
    if (host != null)
        host.Close();
}

as you can see from the code above, I’m simply using a static method to supply the status to the running WCF Service. This particular point of interaction wasn’t my primary point of this post or code. A better option could be getting an instance of the host from the other direction using an overloaded ServiceHost and Get the host using OperationContext.InstanceContext.Host.. Another option might even be where the server is a client to it’s own service, using a set method to set the status. What you don’t want to do is make the service hostdependent. Just be aware that my choice above is clearly limiting, and that you have plenty of other options.


The client is dynamically configured to look for and call the service using the following method:

Binding binding = new NetNamedPipeBinding();
EndpointAddress endpoint = new EndpointAddress(
    string.Format(@”net.pipe://localhost/ServiceMonitoringEndpoints/{0}/“, serviceName));
MonitoringServiceClient client = new MonitoringServiceClient(binding, endpoint);
statusInfo = client.GetStatus();

Although it’s surrounded by other things as well in the actual sample code, like the call to ServiceController.


Here is the sample code.


It contains three projects. The Windows Service Server, the library and a simple console client. Compile the sample code, install the service using installutil and run the client. Now that you’ve validated it and it’s running you can begin expanding it.


Additional Resources:
Hosting WCF Service in Windows Service screencast
Hosting and consuming WCF services
NamedPipe activation

Conference, PDC, WCF

PDC Pre-Con – WCF

PDC Pre-con


Conference Tip #1: A Pre-Con is an introduction. At least the first part of the pre-con will be taking it from the beginning. Don’t be dissapointed if you feel you know all the stuff they say during the first hour or two.


Conference Tip #2: Don’t leave after the first hour or two. It will get more interesting.


WCF Pre-Con session


I’ve heard Juval Löwy of IDesign talk about WCF in the past. In fact I’ve even read his book (Programming WCF Services), now being sent to the presses for a 2nd edition. It is a comprehensive thing that gives a good introduction to WCF as well as introduces patterns and re-usable code for working with it. In a video recorded on Channel9 I’ve heard Juval say that everything should be a service. At the time I thought that sounded slightly crazy. This time the message was that the introduction of WCF is the same kind of semantic shift from .NET development as .NET was from VB or C++ and C++ was from C. Syntax is the small part, sematics is everything really. Overall what WCF gives us is a proven library of best practices and guidelines available out of the box. After an entire day he had has me convinced, of both of the points above. Now, I’m not saying that all classes should be a service and all methods a service call, but I definatly can tell you that I can see the advantages of such a situation after a full days worth of hammering it in by Juval.


It’s really all about the glue. Research has shown that as much as 95% of time is spent buidling, maintaining and troubleshooting glue code. That only leaveas 5% for doing the real stuff, the stuff that you are really getting payed for. WCF is out-of-the-box glue. All that security, transactional support, serialization, versioning etc etc that you’d want your application to have, without you having to spend any time on developing it. A sweet deal really.

Configuration, Maintenance, WCF

WCF issue after installing updates

After installing updates this past night our webservers began exhibiting odd behaviour. All our Windows Communication Foundation (WCF) services began returning 405 Method Not Allowed. I’m not sure which patch was responsible for causing this, but I strongly dislike it when applying updates change my configuration. When I tried to access the svc file directly from a browser I got a 404. This led me to check the .svc mapping. Don’t ask me why, but as it turns out this mapping had been removed. Adding it back solved the problem. I haven’t tracked it down, and I don’t think I will, but the culprit is most likely part of either Microsoft .NET Framework 2.0 Service Pack 1 (KB110806) or Microsoft .NET Framework 3.0 Service Pack 1 (KB929300). The other updates installed can almost certainly be disregarded.

BizTalk, Conference, ESB Guidance, SOA, WCF, Webcast, WF

SOA and Business Process Post Conference DVDs arrive in Sweden

For those of you who like me attended the Microsoft SOA and Business Process conference in late october 2007 you might have been waiting for the post conference DVDs. And it feels like we have been waiting quite awhile. Perhaps the US participants have gotten them earlier and it’s just the international mailouts that are taking the extra time. Anyways, I am off to watch some of the content I missed. For those of you who didn’t attend and won’t be receiving a DVD you have two choices. Either borrow from a collegue or watch the selected webcasts published online at TechNet Spotlight.