Search code examples
asp.net-mvctcpazureazure-web-roles

How to Access WebRole data from .aspx page?


Hi I am working on TCP/IP in Windows Azure and am successfully able to develop a TCP client to send and web-role to receive the TCP data.

I want to display this received data in a .aspx page. How should I access the webrole data from .aspx page?

UPDATE:

I looked into MVC architecture and understood the flow.

My question is how can i fetch the data into Controller from Webrole.cs/WorkerRole.cs file. I am using the following code to receive the TCP data: msdn.microsoft.com/en-us/hh285885


Solution

  • In either case (web or worker role) there is one general solution - use an intermediate storage for the data you want to transfer. For the worker role - it is obvious, the worker role itself is different role than the web role, so no direct communication between them. For the web role it is almost the same situation. Your WebRole.cs is instantiated in different process (WaIISHost.exe) than your web application (w3wp.exe).

    So, the generic solution - use an intermediate store for your data. You can find different approaches on how to communicate between different roles (and here, and here). Depending on your specific requirements, you might find it even easier to use an Azure Table Storage Serivce to store your data from the TCP, and then read the table from the Controller. You might even need to just use Azure Storage Queues.

    At the end, it really depends on your specific and concrete requirements - you can chose the solution that would best fit your needs.

    UPDATE

    Hi, the data reading part is done in Webrole for my appication in Run() function.

    Well, your run function has no direct communication point of contact with you rcontroller. So I don't know what are you reading there, if you only need the data in the controller.

    I think you shall revise your primary application arcitecture. Your controller's method (aka Action) is only executed upon a valid HTTP request is made from client browser to your application. I don't see any reason whay would you read a data before it is requested. Especially a fast changing data. Just wait for a request from browser (which might be an AJAX request also) and then read the data. You could have some good partition/row keys strategy, so that you could store the data read in a local application cache, and read just what has not been yet read. Or just delete from the table once data is read? Don't know you overall application requirements, semantics and arcitechture.

    As for your other question:

    If I implement the data reading partt in controller of ASP.net MVC, what will the webrole be doing?

    Well, your "webrole.cs" is just there so that the Windows Azure Fabric Controller knows that you have a web application live and running. You may leave it completely blank (non-implement)! There is a default implementation of the Run() method in the RoleEntryPoint class itself, which is just infinite sleep, with no harm to anyone.