Kristian Kristensen’s Blog


Exporting WSDL from WCF

Posted in Code, Microsoft, WCF by Kristian Kristensen on the November 26th, 2007

WCF brings many good stuff to service development. A lot of thought and care has been put into the stack to ensure that it is flexible and future proof. Given that it is new and involves a lot of rethinking it also implies that it might do things differently than previous stacks.

One such change is in the generation of the WSDL from a service. Assuming that we have a service bound to the endpoint http://localhost/MyService we could obtain the WSDL for this service by hitting http://localhost/MyService?wsdl. By default his WSDL will be split up into separate files containing the necessary information to describe the services operations and input/output. This is pretty neat since it makes it more human readable than one big file containing everything. So far so good.
Another web service implementation from Microsoft is ASP.NET Web Services or ASMX. It uses/used the latter method of WSDL publication: one big file. So did other stacks. Recently I had to make a client built using Delphi 7 use a service from WCF. The built in web service stack in Delphi prefers/requires that the WSDL is contained in one file. If it is not it cannot generate a proxy class, and cannot communicate with the service. There is a discussion of the issue by one of the Delphi 7 developers here. He recommends either flattening the WSDL (ie. include all the WCF generated files in one big file), or use RPC encoded services.. The latter option isn’t really an option in my current context, so I looked at how to flatten the WSDL. Of course I’m not the only one with this request, so a quick Google search reveals a number of solutions:

Using Weyer’s FlatWSDL class I was able to generate a Delphi proxy class. However, I still couldn’t call my methods. The reason was that my contract is specified in an interface.
Tomas Restrepo writes:

This will not get rid, however, of any wsdl that WCF might be generating, such as the case when the service implementation and the service contract interface are in different namespaces.

My problem exactly. So if I remove my interface based services, and use plain classes, I can call my service operations. So far so good. But I still have one problem, the Delphi generated SOAP request is somehow not recognized by WCF. The correct operation gets called, but the parameters are not transferred correctly.

So where do I stand? I’ve flattened my WSDL for backwards compatibility. But my Delphi (dare I say legacy) client still cannot call my operation. I think that my next step is to convert my service into a POX service, and expose it via some kind of plain RPC. It doesn’t get any simpler than that, and this method should be supported by any type of client. If all else fails you can handcraft the request XML yourself and POST it to the service.

Retiring Mort and Replacing him with Ben

Posted in Microsoft, Misc, WVU by Kristian Kristensen on the November 25th, 2007

Paul Vick discusses whether it’s time to replace Mort or not. Mort is the personification of VB the language, as Elvis is C#’s and Einstein’s C++. Mort has a bit of a bad rep, so Vick suggests he should be replaced with Ben for the Franklin-guy ie. the president, scientist, multitalent. Anyway during his discussion of Mort, Vick writes:

But to a large slice of the world who have an opinion about Mort, this is who they see. A toothless, unkempt hillbilly who’s best kept up in the mountains of West Virginia and away from all nice and normal folks.

I spend my 9th semester as an exchange student at West Virginia University, so that’s kind of funny to see him described as a WV hillbilly.

Serializing Enums in WCF

Posted in Code, Microsoft, WCF by Kristian Kristensen on the November 24th, 2007

I’ve been doing some development using WCF recently. A couple of days ago I experienced an odd problem. My service client would get an exception saying that the HTTP transport layer was unexpectedly closed. Debugging the service didn’t yield an immediate solution; the operation was executed, and returned successfully. So the problem was apparently after the return from the operation. To try and get some perspective on the problem I configured diagnostics and tracing for my service. Fairly easy stuff, and it allows you to plug into all aspects of WCF. Using svctraceviewer.exe that gets installed with the framework you can easily analyze the trace and log files. Locating my operation execution in the log file I found the culprit. Apparently there was an error serializing an enum I was using to signal status messages. It hinted towards the EnumMemberAttribute, so I looked up the documentation for it. Bottom line in order to serialize an enum you need to specify what value to serialize it to. I thought that it would use the default ToString representation when you decorated the enum with a DataContract attribute (which btw is also required), but apparently not. It makes sense to decouple the enum code from the actual serialized format going over the wire. Later I read this post from Dare Obasanjo about code generation and web services in which he advises not to use enums in web service implementation. He points to a previous post of his regarding enums and web services. With this in mind it makes perfect sense having to specify the serialization value of the num. It helps decouple the client from future changes in the enum from the service side, and in that respect helps interoperability and future versioning.

Next Step – A Change in Direction

Posted in MACH, Microsoft, Misc by Kristian Kristensen on the November 18th, 2007

So change is ahead. After graduating in June I’ve been looking for a job. I’ve applied and been interviewed for some. But haven’t quite seemed to find what I was looking for. This includes a job in the banking industry, one with a big SAP shop, plus a couple of consulting gigs. In the end I chose between a couple of big international companies as a consultant, and for a smaller dev shop in Aalborg. One of the big companies was Microsoft. I’ve accepted a job offer as an associate consultant for Microsoft Denmark in Copenhagen. There’s a bit of information up on www.microsoft.dk/ng. Basically it’s a Microsoft Academy for College Hires (MACH) job, which is sort of a trainee position. During a year you get a bunch of training both technical and non-technical to prep you for “life as a consultant”. It looks really exciting and I’m really looking forward to starting in the beginning of December.
Microsoft are going to hire 4 guys for this programme. I’m going to start in December and the 3 others will start in January. My job for December is to figure out how the internal stuff works at Microsoft, get set up with compueter, etc. and help the 3 in January hit the ground running.
Part of the programme entails training in Holland and the US. Upwards of 3 months will spend on training during the first year. This too is really exciting and a big part of why I chose this position.
A nice addition is that Microsoft Denmark was chosen as the best workplace amongst IT companies in Denmark.
So in a couple of weeks time I’ll be moving to Copenhagen. I’ll crash at a friend of mine’s place until I find my own.

Other than the above mentioned applying and interviewing I’ve been tinkering with WCF and WF for gig. I’ve been using Visual Studio 2008 Beta 2, and it’s been working out very nice. So much the better that Soma announced at TechEd a little over a week ago that VS 2008 will be released during November. Recently I read that it will hit the servers early this week. So cool.