Search code examples
c#azureazure-batch

What Microsoft Azure service would be the best for me?


I am mainly a low level system developer so I am kind of lost with all those high level tools that Azure offers and all those buzz words.

So here's what I am trying to build: I am building a server that has a processing part (probably using Azure Batch) and a storage part (using storage, duh, and DBs). I would like to hide all of this behind an interface where client applications could:

  • Log in the users

  • Upload/Download selected files

  • Manage their currently running jobs or start some new ones

The client application might be on an iPad,Web browser, PC, ect... New features might arise or change on the server side. This is why would opt for a "server interface" to standardize all clients interactions, but i do not know what Azure tool would fit my needs for this interface. I am not looking for something low level as in building my own protocol and server, just something that would get the job done simply.

Cheers

Léon Cantin


Solution

  • I ended opting for a Web API which let me "call" functions from the server trough the HTTP protocole. the URL is the "name" of the function and the data are either serialized in body or in the URL. Really simple and flexible, it should work out of the box on any framework that can use HTTP or i might be able to find a library that lets me do it.

    My Test code looks like this :

    Client:

    private async Task SubmitJob()
        {
    
            JobModel job = new JobModel { ID = 42, name = "HelloJob", completion = 100.0f };
    
            try
            {
                HttpClient client = new HttpClient();
                HttpResponseMessage response = await client.PostAsJsonAsync<JobModel>("http://localhost:53122/Jobs/Submit", job);
                if (response.IsSuccessStatusCode)
                    lblSuccess.Text = "Success!";
                else
                    lblSuccess.Text = "Failure!";
    
            }
            catch (Exception ex)
            {
                string s = ex.ToString();
            }
        }
    
        private async Task GetJobs()
        {
            try
            {
                HttpClient client = new HttpClient();
                HttpResponseMessage response = await client.GetAsync("http://localhost:53122/Jobs/Info");
                if (response.IsSuccessStatusCode)
                {
                   List<JobModel> jobList = await response.Content.ReadAsAsync<List<JobModel>>();
                   txtConsole.Text = "";
                   foreach(var job in jobList)
                   {
                       string line = "ID: " + job.ID + " Name: " + job.name + " completion: " + job.completion + "\r\n";
                       txtConsole.Text += line;
                   }
                }
                else
                {
                    txtConsole.Text = "Failure!";
                }
    
            }
            catch (Exception ex)
            {
                string s = ex.ToString();
            }
        }
    

    Server:

            public async Task<IHttpActionResult> GetJobInfo(int jobId)
        {
            try
            {
                JobModel a = new JobModel { name = "jobA", ID = 102, completion = 100.0f };
                JobModel b = new JobModel { name = "jobB", ID = 104, completion = 42.0f };
                JobModel c = new JobModel { name = "jobC", ID = 106, completion = 0.0f };
    
                List<JobModel> result = new List<JobModel> { a, b, c };
                return Ok(result);
            }
            catch (Exception ex)
            {
                return InternalServerError(ex);
            }
        }
    
        [HttpPost]
        public async Task<IHttpActionResult> SubmitJob([FromBody] JobModel submitedJob)
        {
    
            return Ok();
        }