0
votes

I have created a simple web application which runs locally and makes use of a simple web socket server which I implemented using Alchemy Web Sockets. Now I need to deploy this app to Windows Azure.

Currently the solution is made up of an MVC4 website and a console app for the web socket server. My question is how would I deploy my current solution to Windows Azure? Is it even possible to use Azure for the console app?

From what I've seen on the Azure website I can deploy the MVC4 website as an Azure website and the console app (server) on either a virtual machine or a cloud service. It seems to me that a cloud service makes more sense (since the infrastructure is managed by Microsoft and I am not interested in that), but I am completely new to these technologies so I am not sure which is the best approach/if it is even possible.

EDIT:

I have implemented the web socket server console app as part of the web role as suggested by Sandrino. However, when loading the page which connects to the server I get the following error in the chrome debugger Unexpected response code: 200 .

I have left everything the same except that I use @HttpContext.Current.Request.ServerVariables["HTTP_HOST"] to connect to the server on the client side since different servers will be used in Azure, I have tried this in a local app and it worked. I still have not deployed to Azure but am testing locally, maybe the server is not actually running, how can I check this? Using breakpoints it seems that the necessary methods to start the server are being entered.

1
I'm sorry to poke at a question that's been long dead, but I'm using Alchemy WebSockets and I can't seem to get it up on either Compute Emulator or on Azure itself. I've added the TCP endpoint for port 81, if that helps, so your code should work fine, but when I try an echo test (websocket.org/echo.html) at ws://hostname.cloudapp.net:81/ it's a no go... Any idea? I've been spending quite a while on this :(matt

1 Answers

0
votes

I suggest you take the code from your console application and move it to the WebRole.cs of your Cloud Service. This file is the entry point of your instance meaning your code will run when the instance starts. This will allow you to run the WebSocket server together with your ASP.NET MVC application in the same role.

So in Visual Studio you'll need to create a new Cloud Service and choose an MVC4 Web Role.

public class WebRole : RoleEntryPoint
{
    public override bool OnStart()
    {
        Task.Factory.StartNew(OnStartWebSocketServer, TaskCreationOptions.LongRunning);
        return base.OnStart();
    }

    private void OnStartWebSocketServer()
    {
        var aServer = new WebSocketServer(81, IPAddress.Any)
        {
            OnReceive = OnReceive,
            OnSend = OnSend,
            OnConnect = OnConnect,
            OnConnected = OnConnected,
            OnDisconnect = OnDisconnect,
            TimeOut = new TimeSpan(0, 5, 0)
        };
        aServer.Start();
    }
}