WCF Services - a compatibility hack

August 20th, 2008

I’ve recently had to start developing a set of WCF services for my company to use.  All good stuff, you might say - and tyou’d be right.  For the most part.

The area in which things get “interesting” is around the requirement for backwards-compatibility with some existing .Net 1.1 applications that consume traditional web services.  These applications are horrendously complex, and the fewer changes to the code base we have to make, the better.  With this in mind, we created the WCF services to mirror the old web services as closely as possible and that’s where the fun began.

The issue that set me on a journey of discovery and hackery was around a method that returned a simple boolean type.


public bool NameIsInList(string name)

{

// implementation

return true;

}

Nothing fancy there.  However, exposing the service using basicHttpBinding had an unfortunate side effect.  The method signature was refactored to :


public void NameIsInList(string name, out bool NameIsInListResult, out bool NameIsInListResultSpecified);

Less than ideal.

No matter what I tried (including contacting Amit) I couldn’t make the down-level compatible web service return a simple boolean result.  Given how much effort we would have to go to to update the calling methods in the legacy systems, I had to find another way forward.

In the end, the solution was extremely simple, if a little hacky.  Create an ASMX web service that handled the calls to the WCF service, and presents the legacy apps with the data they expect.


[WebMethod]
public bool NameIsInList(string name)
{
using (MyWcfService.ServiceClient WcfClient = new MyWcfService.ServiceClient("WSHttpBinding_MyService"))
{
return WcfClient.NameIsInList(name);
}
}

Not the prettiest solution, but it works.

There are a few extra benefits that I wasn’t expecting from this approach, too.  I’ll post about those tomorrow.

Stack Overflow - pretty darned cool

August 12th, 2008

Over the course of the last week, I have been participating in the private beta of a new website, Stack Overflow.

The site is for programmers, by programmers and focussed on - you guessed it - programming.  So far it all looks pretty sweet.  Users aren’t required to register, and more importantly they aren’t required to pay to use the service (I’m looking at you, Experts Exchange!).  The overall quality of questions and answers seems pretty high, although I understand that the site is still in beta.  The quality may change once the site goes live, but the system of self management by the community should keep standard fairly high overall.

If you want to keep up to date with the project, and hopefully learn when the public launch is going to happen check out the blog.

The little things in life

July 16th, 2008

More often than not, it’s the little things in life that make a difference.  for example, I arrived at the office this morning to discover that our new chairs had been delivered.  Not a major thing by any means, but given that my old chair had virtually no back support I was long overdue for a new one.

And what did the company provide for us?  To my surprise, Herman Miller Mirras - from the same people who took an unfair amount of flack during the dotcom bubble.

I am impressed.

Hint text in ASP.NET TextBox controls

June 3rd, 2008

More and more often these days, you see hint text in a textbox control on a web form.  You know the kind of thing - “user name” or “password” appearing in silver text within an input control.  Well, I had to implement that functionality today and it is surprisingly easy to achieve.

The first thing you need to do is create your TextBox control on the page.  Once you’ve done that, add the following method to your codebehind file.


private void SetTextBoxHints(TextBox textBox, string defaultText)
{
textBox.Attributes.Add("onfocus", "clearText(this,'" + defaultText + "')");
textBox.Attributes.Add("onblur", "resetText(this,'" + defaultText + "')");
if (textBox.Text == "")
{
textBox.Text = defaultText;
textBox.ForeColor = System.Drawing.Color.Silver;
}
else if (textBox.Text == defaultText)
{
textBox.ForeColor = System.Drawing.Color.Silver;
}
else
{
textBox.ForeColor = System.Drawing.Color.Black;

}

 Next, you’ll need to add the javascript to the page/user control to look after the dynamic changes in content/colour. 


<script type="text/javascript" language="javascript">
<!--
function clearText(ctrl,defaultText) {
if(ctrl.value == defaultText)
ctrl.value = ""
ctrl.style.color = "#000000";
}
function resetText(ctrl,defaultText) {
if(ctrl.value == "")
{
 ctrl.value = defaultText
 ctrl.style.color = "#C0C0C0";
}
}
// -->
</script>

Then, you need to call the setup method for each Textbox you want to control.


SetTextBoxHints(myControl, "the text you want to show as default...");

And that, as they say, is that. Enjoy.

Multiple Async calls to a web service

May 21st, 2008

I’m currently working on a project that requires making several concurrent asynchronous calls to a web service.  Now, the service work fine synchrounously, but change the pattern slightly and I was getting the following error.

“There was an error during asynchronous processing. Unique state object is required for multiple asynchronous simultaneous operations to be outstanding.”

The solution, courtesy of a post on the MSDN forums was to pass a new GUID as a state object.

Problem solved.

 

Got to love the tech

December 4th, 2007

Who’d have thought, just a few short years ago, that I could be sitting on a train, using my MP3 player to write a blog post?  Got to love the tech. :)

Wild Garden

July 26th, 2007

I’ve been a bit slack with my back garden, but I have to say, I’m quite pleased that I left a couple of small patches to their own devices. They’ve sprouted a small number of wild flowers, and last weekend, they were just about as good as I’ve seen them.

The Amazing Google Strike Again!

July 3rd, 2007

This morning I was given a tracking number for a parcel I am expecting.  However, I didn’t get the name of the company who were to deliver it.  Not a good start if I wanted to use the tracking number to actually track the parcel.

Then I remembered a discussion at work about Google’s recognition routines, and one of my few remaining synapses fired into life.

I went to Google’s homepage, typed in my tracking number (nothing else, just the number) and hit search.  I have to admit I was very pleasantly surprised when the top of the results page said “Track UPS package 1Z6 …..  70″

Very neat.

Picasaweb - new slideshow feature

July 2nd, 2007

I’ve just seen that picasaweb have added a slideshow feature to their web photo albums.  I was going to post about something else, but I thought this was cool enough to put the other post to one side for a while.

 Here’s an example…

It had to happen sometime

June 23rd, 2007

It is almost inevitable in the modern world that someone will manage to get hold of at least part of your identity.  It happened to me this week.

I went downstairs first thing this morning to see what snail-mail had been delivered, only to find an urgent letter from my bank.  It seems that someone has managed to get hold of my bank card details and used them to spend around 4-500 pounds of my money.  It would have been more, but something tipped the bank off that there was something wrong and the put a stop on my card.

I am happy that the bank managed to catch this behaviour, and prevented another 500 pound being spent.  I can’t help but wonder, though, whether we are all a little complacent about our details.  I’ve always taken time to destroy paperwork that could hold vital information for use by an identity thief, but it seems that is not enough.  Just using your debit or credit card in the wrong place is enough to leave you open to fraud - a quick skim of your card details is all it takes…

It’s easy to be wise after the event, but now may be a good time to fall back on using good old cash for a while.