Question

Not sure if this is possible in Azure services and if it is whats the best approach.

I have a class which is extracting data from my database and building an xml output. Under normal circumstances since this is running in a worker role, it will run when necessary and push the XML to an external web service. However I also need the ability to expose that functionality as a service so that a different external web service can make a web service call to my system and get that very same XML response. I can setup a RESTful webservice in a worker role and build the same functionality as exists in my worker role - the problem is that I now have duplicate code.

How can I set this up so that my code to extra data from the DB, perform some calculations, generate the xml all sits in one location that is accessible from both a webrole (triggered by external web service call) and worker role (on regular running schedule).

I have looked through all the questions regarding TCP internal endpoints and worker webrole communication but none of them seem to cover this case of allowing a webrole to call a method on the workerrole and pass that data on to the caller.

If someone can help me with this would be very much appreciated. Thanks

Was it helpful?

Solution

Well, technically the solution is that you create a class library (.NET assembly) that contains all the shared code and use it from both roles projects. You'll have to set "copy local" to "true" on the reference to that assembly in each role project so that the assembly gets packed into role packages.

However in your case there might be a better solution. You might just use the web role for both purposes. I mean a web role is like a worker role, just has a bonus IIS installed. Unless you really (really-really) need to scale and update them separately you can save a lot of management and deployment pain and also some money just using the web role for everything.

OTHER TIPS

If I were you I would make it as the Web Role then would send a message to Worker Role and based on this message, would trigger the event on the worker role to start the required process.

You can do that using the queue storage or a WCF service.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top