tags:

views:

30

answers:

2

We currently have a WCF Service which is beginning to reach it's limits performance wise.

We have decided to add another server which will host another instance of the WCF Service.

We have web applications which must communicate with a specific server based on context... e.g. If the web application is dealing with objects from ServiceInstance1 then requests must be directed to ServiceInstance1's EndPoint. If the web application is dealing with objects from ServiceInstance2 then requests must be directed to ServiceInstance2's EndPoint.

I initially thought that a "Intermediate Service" or "Service Manager" could be created, the web application's Service Reference would be updated from the individual Service Instance to the "Intermediate Service" or "Service Manager" and said service would act as a "Broker" to the various Service Instances.

How is this accomplished?

I have currently added a ServiceReference to each service from the Manager however it seems that once a Service is "Referenced" it's types becomes specific to the that of the ServiceReference e.g.

ServiceInstance1's type's are all {ServiceInstance1}. ServiceInstance2's type's are all {ServiceInstance2}.

I need the types to be the same on the web application end, so this obviously seems like the wrong way to do it.

I would also like that when methods are called on the client generated from referencing the "Intermediate Service" or "Service Manager" that the correct Service Instance is invoked, e.g.

IServiceManager.GetProjectById( {GUID} ) ->

Comes Back to ServiceManager -> Determines which host has the project and returns the ProjectObject from the correct ServiceInstance.

Where ProjectObject is a Type Defined in ServiceInstance1 and ServiceInstance2.

I think the original service needs to have some of the DLL's pulled out so they can be referenced from the web application side and ServiceManager and a GenericWCF Client can be made.

If I am right hooray for me If someone can point me in the right direction I would appreciate it. If I am wrong can someone please scold me and show me how this is properly done!

A: 

The easiest way to accomplish what you're trying to do is to stop generating your proxies using the server-hosted URL of the service. Instead, generate your proxies from the *.xsd and *.wsdl locally, and merely change the URL of the endpoint. Alternatively, you can use ChannelFactory<T> to generate proxies on-the-fly, and reference your interface .dll on the client side.

Once you've done that, you can use any common webserver load balancing technique to balance the load between the servers.

Not to put too fine a point on it, but Visual Studio's "Service Reference" is not useful, and should not be used, for services you develop. It's useful only for services developed externally, whose URL and contracts are likely to NEVER change. I personally have never had occasion to use it. For your own services, you should probably be using ChannelFactory<T> or a class based on ClientBase<T> to work out the proxies.

Mark
@Mark: what's wrong with using the "Add Service Reference" but changing the URL at runtime, as necessary.
John Saunders
Because we would like the multiple backend servers to be transparent to the web applications that use the services. This way all web applications have the same code base reguardless of which server they actually had to communicate with.
Jay
A: 

The way to solve your problem is to create shared assembly with types used by both services. Reference this assembly on the client consuming your services (manager) and when creating proxies by Add service reference mark Reuse types from referenced assemblies.

What you are building is very simple message router. In WCF 4.0 there is additional support for routing services so you should check those features before developing your own. For WCF 3.5 MSDN magazine contains articles about building message router - part 1, part 2.

Ladislav Mrnka
Thank you for the input... I figured it would be something like this.I will review the Message Routing stuff and pick my poision.Thank you again for your input.
Jay