Sergio Ordine

Hi All!

I was thinking about using the following architecture on a part of a system we are designing (Web - IIS hosted):

- Based on a set of parameters get a class able to execute a command associated with these parameters (using Command Pattern).

- In order to guarantee that the actions of those commands are done in a transactional context , use a WCF service that could provide it as the unique entry point for this (call a WCF service passing the parameters, get the command handler using a factory and execute it).

Using it our presentation layer shall deal with less services/stubs and got the information it needs in a more "transparent" way than calling specific services and also reduces the number of WCF client classes I need to generate and use... An issue that I can foresee is declaring the parameters as Knows Types on the WCF generic service (what is anoying but not critical)

My question is: If I use this unique WCF/WCF method as the communication path between my presentation and business layers (represented in this case by the Command classes) could cause any performance issue Is it worst or better than having several different services I don`t know how WCF(or IIS, as it hosted there) handles several access to this kind of service...

PS: If anyone sees another issue regarding this approach I'm not forseeing, please let me know.. (It would be great it as it could spare me future headaches...)

PS2: I wrote a lot but I don't know if it is clear.. Please let me know if further information is needed....

Thanks a lot,

Re: Architecture General WCF+Command Pattern -> performance question....


You can also consider using Windows Service to host WCF. This arrangement allows you to use NetTcpBinding to gain better performance. If you want to use IIS for NetTcpBinding, you have to wait for IIS 7.0.

Re: Architecture General WCF+Command Pattern -> performance question....

Ronald Ricardo Ramirez Moran

A service can only return DATA no OBJECTS, because this contains a reference schema for each entity to return or receive. But you can create a "Service Factory", also known as a "Intermediary Service" or "Intermediary Router", that returns the "handle" of one Service depending on your needs and executes a operation implemented on.

Another good approach is to make a generic service, that will return a value depending on parameters but using a Factory Pattern, returning the value of a method that accomplish with the requirements.

The perfomance of your service only depends on the resources that you have. But, also exists concurrency problem, when you have many clients, you will need to configure a Throttling behavior or define the instances configuration.

You can find more information about throttling at:

Re: Architecture General WCF+Command Pattern -> performance question....


I have a concern with the original approach outlined. I agree that sometimes there are many services, or operations on a single service platform that you may need to talk to, to achieve a particular goal. You are also right in not wanting to lock all this logic into the UI, as you will just end up writing this again should you implement another interface to you service layer. However by providing a single "super service" that wraps all others, or provides pointers to other services that are required are you implementing the "Loosey Gooseyí▒ pattern describe in this article

I would like to propose another way of going about this. Why doní»t you build a class library that provides functionality that a UI would require and have this talk to the web services directly Then in the future if you decide that maybe you would like to put this in a service you can. This is a pattern the Microsoft has used often, and off the top of my head Team Foundation Server does this. There are a number of web services for Team Foundation, and you can use them directly. However Microsoft recommends you use the class libraries they provide that wrap the services and provide some logic and common code that people would have to write to access them.

Obviously this will not help if you are writing you services in .Net but the UI in say Java, but I doní»t get the impression that this is the case. Also like I said if you do have this scenario in the future, turning the library into ití»s own service should not be overly difficult or expensive.



Re: Architecture General WCF+Command Pattern -> performance question....

Sergio Ordine

Hi Tim,

First of all, thanks for the article... Let me explain what I intend to do and I'd appreciate and the options I can see...

We are creating a system that will be a kind of workflow system (I'm not considering using Workflow Foundation to do it) and in order to make it flexible what I thought to do is:

1 - the presentation layer just calls a command using a "command id"

2 - based on this command id I can get a handler that:

- gets the data from the presentation layer;

- populates it into a parameter map (based on mapping rules I have in a XML file) and validates it.

3 - with this structure calls a generic execute command passing the parameters and command id (that shall guarantee a

transactional context for this execution)

4 - get, through a factory, a Command class that shall perform the command:

- it shall parse the parameters;

- execute a series of tasks (implemented on Business Objects)

- perform a state transition based on rules (XML or DB based),the command executed and the tasks result

- return a list of resturn values

5 - this returned values are populated into the interface based on mapping rules (XML based)

I have thought about using WCF just as a container to control the transaction context and maybe decouple the presentation and business layers (currently both shall be deployed into the same machine, so it is not an issue)... But, yes, it makes the workflow controller a kind of "ubber service" that violates SOA principles... (altough the "contract" itself is managed by my mapping/validation rules instead of the service itself). What make me think:

- I can use the same approach without using WCF (controlling the transaction myself) and implementing a WCF service just if I need some of my business logic to be exposed for future projects (in this case the WCF will be just a wrapper for my business objects, that have fine grained business services).

- Use "wrongly" WCF for this specific purpose (it is a service just used by our application, not a ) and provide services with better defined contracts for other applications

- Use well defined services (in this case my approach of configurable commands and transitions is lost, at least in the way I first designed it...)

Do you know another article discussing the Loosey Goosey "anti-pattern" I'd like to check the issues and pitfalls I can face using the approach (the issues listed into the article does not applies here, I think, but based on the article I can figure out several people had bad experiences using it, so it is something I must seriously consider)... My goal here is not make a hiper-ultra-super flexible service for the outside world, just on my own application (what shall be a more controlled one), providing more specific services for other applications when needed (based on my business objects)

Thanks a lot!

Re: Architecture General WCF+Command Pattern -> performance question....


Looking at your problem the Uber service does seem like a viable option. Sometimes it is okay to do things "the quick way" however you will end up relying on behaviours inside the service that are not at first obvious when consuming the contract. If you can be sure that no one ever will use your services for anything other than your WinClient then, sure bind it up.

However, and here is the big however - well designed services written for one application will almost always end up being reused by another part of the company, and badly written ones will often end up in the same scenario. When this happens the level of documentation, and support you will need to provide to the consumers of these services will be enormous. The calculation service has been an example of this in our company, it was a generic service like you mentioned. When other parts of the business starting finding out about this service they all wanted to use it, but we were often getting rung by third party companies and had to hand hold them through the experince. We refactored this service to provide actual methods for each of the calculations, and versioned the interfaces. This had the effect of reducing our documentation to a single page and very few if any calls at all to integrate.

I would question why you need to be able to say that a various commands are to be configured at the UI end Would you not be better off calling specific commands from the frontend and having the service make decisions and store configuration Without knowing all of the business requirements I can't make a definitive decision for you (and that's your job anyway) but that is my 2c.

Also as a side note when looking at your application, I like your thinking of using WCF to communicate between the business logic and ui. However I would suggest that if you really will be deploying both layers to a single machine, you include the business.dll in the UI and reference it from there rather than hopping over a boundary. I would still design the services in the same manor, including putting the correct member attributes, the interfaces, and datacontracts that WCF asks for, as these are really just good practices for all coding (and it will make seperating the system a matter of just making a web project and a bunch of SVC files to reference your services Smile .



Re: Architecture General WCF+Command Pattern -> performance question....

Ron Jacobs

I'm the guy that came up with the "Loosey-Goosey" anti-pattern. You can hear my presentation from Tech-Ed 2006 on the ARCast show.

You can listen to more reasoning why this is an anti-pattern on these episodes

Patterns and Anti-Patterns for SOA part 1

Patterns and Anti-Patterns for SOA part 2

Ron Jacobs

Host of ARCast.TV

Re: Architecture General WCF+Command Pattern -> performance question....


Here is what i suggest, have a generic service first, when you need a specific service, just inherit the generic service and the implementation should be the same. How a service processes a message is upto it. All services process the message using the same implementation unless you have some additional stuff to be done.
Walmart has 1 entrance to get into it.
Once you are in you can choose to go to Groceries or Software or Hardware.
So to get in you can have a generice service as entrance.
Once you are in, you have a message called Groceries or a service called Groceries is upto you.
My 2cents.

Re: Architecture General WCF+Command Pattern -> performance question....


I know, and thanks for that! I heard you talk at Tech Ed 2006 in New Zealand, and there you put a name to a problem I had been seeing over and over again, both from suppliers and from other teams in our oganisation. It was brillant as I had some of our coders with me, and now they point out when they find these anti-patterns in existing systems or a slipping into them in an application.

So Ron your talk has made my life easier, and if you happen to come down to Auckland again, drop me a note and we can show you around some of the cool things we have done with your architectual concepts



Re: Architecture General WCF+Command Pattern -> performance question....

Rob Daigneau


You might find something useful here ...

You can also find the code for this presentation on the site.


Rob Daigneau