Getting acquainted with xsd

…I had to define a REST interface, returning XML data. I already did such things before, but I’ve hesitated to learn the XSD syntax for all the usual reasons: yet another useless language, you can’t express with it all the requirements to the data anyway etc, etc. So I’ve usually created my C# classes, serialized them to XML, generated an XSD from it, sent it out to the other party and forgot about it.

 
This time, I decided to give it a try. Partly because I didn’t really liked the XML you get from the XmlSerializer in C#. And partly because I’ve got to see some specifications of XML structures done by others, and I’ve been impressed by clarity and professional look of defining XML-Elements not in terms of C# classes and types, but using XPath and XSD.
 
So I did it this way. I’ve created a fake REST server and written responses of its methods in XML files (one file per method). I’ve written the responses manually, freely replacing the tags and structure until I liked it. Then, I’ve let Visual Studio to generate XSD automatically for each of this XML snippets. Finally, I’ve combined all the snippets into one XSD and factored out common types. That’s easier as one may think, because of intellisence and of build-in help system. Besides that, there are not so much concepts in XSD to learn, it is possible to learn the most of them in a day or two.
 
When I had my hand-crafted XSD file ready, I’ve written a client calling all of the fake REST methods and checking the responses against the schema. It is not really straightforward, but there is a build-in class for that.
 
When I had all of my REST-tests in the green state, I could easy incorporate changes requested by the customer (and there are plenty of them, at the end of the day not more than 40% of the original schema survived). For every change, I’ve changed the schema first, then run the REST-tests to see a couple of them turned red, then fixed the fake REST methods and run the tests to see them green again. Thus I could keep XSD-snippets defining elements and XML-snippets showing an example of a such element perfectly in sync.

Limiting the number of outgoing SOAP web service calls

If you create a web app, which consume information from other web services, you eventually need a possibility to control the number of outgoing SOAP web requests. On the one hand, the default maximum number of connections is 2, which could be a performance bottleneck. On the other hand, if you call another web service too intense, you may be banned there either technically (by a firewall or Windows server itself detecting DOS attack) or manually by a server administrator.
 
You can set the number of connections so:
ServicePointManager.DefaultConnectionLimit = 25
 
or so:

ServiceReference1.BackendServiceSoapClient cl = new BackendServiceSoapClient();
ServicePoint p = ServicePointManager.FindServicePoint(cl.Endpoint.Address.Uri);
p.ConnectionLimit = 20000;

You can tell how many connections are open so:

p.CurrentConnections

One interestring point it that although .NET uses background threads to handle connections, the number of threads doesn’t correspond to the number of opened connections. For example, when I set the limit to 20000, I actually see 20000 opened TCP connections in the performance monitor, but only 18 running threads. Does anybody have any info about how it works?

Make Object ID

The biggest problems Microsoft has with their products and tools is that they hide intersting features. Under “hide” I understand here failure to communicate, advertise or evangelize the features to the public.
 
For example, did you know, that you can install any module of Vista in the command line. There is now a command line package manager, similar to those we know from Linux (aptget etc).
 
Did you know what Vista is a DVR with time shift function – and this is for free?
 
Did you know there is the HttpListener class (since WinXP SP2) allowing you to create your own simple web server without needing to install and configure IIS (can be handy if you develop an installable client side software and do not want to have users to install IIS for it).
 
And todays example is the Make Object ID menu in the Visual Studio debugger. You can mark any object with and ID during debugging, so if you have problems understanding if you have the identical object on several place of your code, or just copies, you need this feature badly (before, I had to use GetHashCode() for that).

Open Space Rant

I’m a strong proponent of the open space office concept. I need this empowering feeling emerging from several people actively working at the same time in the same place on similar problems. How wonderful is that to hear someone being thrilled with some very good news about a complicated project! You can share his happiness.
 
And you get your daily news for free, just hearing what others are saying. And if you have something to share, or to ask, all that you need is just rise your head and look at your collegue.
 
There are two killers of this great office concept. When it is too loud and when it is too quiet.
 
In a too loud environment you cannot concentrate on your task. But this is not I personally find a very bad thing: if you really have to concentrate on something for a long time, it is a sign you’re doing something overcomplicated, which is a bad sign indeed. And for short concentration periods you can use the time in the early morning or in the late evening.
 
On the other hand, quietness builds a virtual wall in the office, preventing you asking or telling something just “at will”. Therefore, some companies play an ambient background music in their offices, preventing building the virtual wall.
 
But the thing I hate most is when people speak so quiet with each other, that I can still know they’re speaking, but cannot hear, what exactly is being told. I’d almost say it is malicious against all other office inhabitants. Okay, sometimes there are things that have to be said privately. In this case, using the meeting room could be an appropriate solution. But, generally, what’s the point of discussing something secretly in sight of a dozen collegues?

Change happens

When I’ve got my firt box of visit cards, the first thought was “what a waste, I’ll never gonna need it”. Really, in the world, when you’re trying to hide and protect your email address from spammers as good as possible, the idea of giving out your contact informations to unknown people seemed ridiculous to me.
 
Nevertheless, I took several visit cards and placed them into my moneybag. Just in case. When you’re in a bank asking for conditions, it can help giving them your VC stating you’re a project manager :) And if an accident happened to me, the police would know where to call…
 
Yesterday, I had been yet again on a customer workshop. There were three other persons in the meeting, with whom I’m going to work in the future. So I wanted to get their contact info. I’m opening my moneybag and, what a shock, I’m realizing there are only two visit cards left!
 
Others are already gone on different workshops I had since the beginning of this year, and I never updated the “cache”, because I initially thought it will last forever…
 
Now I’m trying to understand if it is a good or a bad change.