2

I have this topology : ( notice WAS )

each Service1 , service2 ...service-n is in a separate appdomain in iis. enter image description here

Service1 need to consume Service2.However he can access service2's endpoints via nettcp or http endpoint.

Where is the decision ? ( nettcp ot http )

In a separate Config file. (which is in c:\cfg folder , and of course service1 reads the cfg in order to decide to which binding he should access at service2.)

Service2 also should be able to see the file cause he consumes other services as well. but lets talk(for now) about service1 as calling service2.

a typical entry in cfg file will be :

key : current_service2_Active_endpoint
val : nettcp

So here is my problem :

  • I need to find a solution that will read the CFG into a cache or something so service1 will read the cfg entries from cache and not via filesystem. but Service2 should also read it but the cache wont be the same ( different appdomain). how should I do it ? where should I write the code (uploading to cache) ? I only have this 2 files : ( maybe when the service is up - but what is the code for that ? )

enter image description here

  • I want that each change in the CFG file - will reload the entries into cache. this seems as a classic cache task. Cache dependency on a file seems to be the solution , but again there will be [n] cache dependencies because of [n] appDomains....
Royi Namir
  • 144,742
  • 138
  • 468
  • 792

1 Answers1

1

How about writing a new service, called maybe 'CacheService', which holds the cache? This should be a single-instance service, which just has an internal and static concurrent dictionary with the key/value pairs from the cache.

It should also hold a 'FileSystemWatcher' so it gets notified when the CFG file changes and then it can update its internal mapping.

All your services would call this service, which should have a very simple interface ('GetConfigSetting(string key)'). You can host this service either in IIS or self-host it in a Windows Service (I'd go for the second option, because this way it's always up).

You can look at this as some sort of rudimentary distributed cache. It shouldn't be more complicated than this anyway. The protocol should be net.tcp or event net.pipes, because you want a latency as lower as possible.

Marcel N.
  • 13,726
  • 5
  • 47
  • 72
  • thinking about 1000 calls to service2 which yields 1000 calls to a cache service - is less efficient than inproc cache object....no ? – Royi Namir Oct 29 '12 at 09:05
  • @RoyiNamir: You can get under 20ms read times as long as you keep everything in memory. The 'ConcurrentDictionary' is very efficient for concurrent access and a singleton WCF service adds practically no overhead to method calls. – Marcel N. Oct 29 '12 at 09:07
  • @RoyiNamir: Otherwise just see this: http://blogs.msdn.com/b/dotnetinterop/archive/2008/09/22/custom-service-config-file-for-a-wcf-service-hosted-in-iis.aspx, taken from herE: http://stackoverflow.com/questions/482835/wcf-configuration-split-it-out-of-app-config – Marcel N. Oct 29 '12 at 09:10
  • you got a point , also , if i MOVE service2 to france so I would'nt need to copy/clone the CFG file - I could just call a service which yields - where should I connect to. What about : "code when service is up in WAS ( so i can read the cfg into cache ) " ? – Royi Namir Oct 29 '12 at 09:11
  • @RoyiNamir: That implies creating all WCF client elements (practically deserializing them from your custom CFG file), as described here: http://www.paraesthesia.com/archive/2008/11/26/reading-wcf-configuration-from-a-custom-location.aspx. This has to be called before you want to actually invoke the services from any particular service. – Marcel N. Oct 29 '12 at 09:18
  • my serivce is under iis and has only svc files. So I dont have any place where i can write code . ( i didnt find in the article a WAS solution)....am I wrong ? – Royi Namir Oct 29 '12 at 09:21
  • @RoyiNamir: I'm not sure I understand. You must have some code-behind where you implement your service logic. Can you post some code about how you call the Service2 from Service1? – Marcel N. Oct 29 '12 at 09:23
  • Thanks for helping. the stage where Service1 calls Service2 is too late. **when Service1 is UP** - he needs to read the cfg file. but how ? – Royi Namir Oct 29 '12 at 09:25
  • @RoyiNamir: Then I think you need to add a custom behavior for detecting when service1 operations are called. This can be done via a 'IOperationInvoker' implementation, as described here: http://msdn.microsoft.com/en-us/magazine/cc163302.aspx. So, when any method of service1 is called, your IOperationInvoker impl will also get called (before, actually). There you can call the cache service or look into the CFG file by some other means. There's no general way to detect when your service has been activated by WAS. – Marcel N. Oct 29 '12 at 09:31
  • @RoyiNamir: Let's change that to "no better way" :). – Marcel N. Oct 29 '12 at 09:40