locked
Is ML web service implemented to Visual Studio 2010? RRS feed

  • Question

  • I'm programming C# application by using Azure ML that i made.

    Although I copy and paste sample C# code provided by Microsoft to C# script, I can't build that code.

    Below the capture is Error message window.

    What should i do, masters?

    ps. I installed Nuget Lib. and Microsoft.AspNet.WebApi.Client -Version 4.0.30506

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.IO;
    using System.Net.Http;
    using System.Net.Http.Formatting;
    using System.Net.Http.Headers;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace ConsoleApplication81
    {
        public class StringTable
        {
            public string[] ColumnNames { get; set; }
            public string[,] Values { get; set; }
        }
    
        class Program
        {
            static void Main(string[] args)
            {
                InvokeRequestResponseService().Wait();
            }
    
            static async Task InvokeRequestResponseService()
            {
                using (var client = new HttpClient())
                {
                    var scoreRequest = new
                    {
    
                        Inputs = new Dictionary<string, StringTable> () { 
                            { 
                                "input1", 
                                new StringTable() 
                                {
                                    ColumnNames = new string[] {"Main Problem", "DIA", "Length(mm)", "Material", "Pre-Weld", "Sch", "Final Process", "Weight", "Num of Parts", "Num of Joints", "Making Bendor", "Warehouse", "A_ManufacturingCDT"},
                                    Values = new string[,] {  { "value", "0", "0", "value", "0", "value", "value", "0", "0", "0", "value", "value", "0" },  { "value", "0", "0", "value", "0", "value", "value", "0", "0", "0", "value", "value", "0" },  }
                                }
                            },
                                            },
                                        GlobalParameters = new Dictionary<string, string>() {
    }
                    };
                    const string apiKey = "abc123"; // Replace this with the API key for the web service
                    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue( "Bearer", apiKey);
    
                    client.BaseAddress = new Uri("https://ussouthcentral.services.azureml.net/workspaces/029d6bb2ad4845a8bc11b56eabb0cede/services/070ba6d27cb84b5398fa1a68d8d67646/execute?api-version=2.0&details=true");
                    
                    // WARNING: The 'await' statement below can result in a deadlock if you are calling this code from the UI thread of an ASP.Net application.
                    // One way to address this would be to call ConfigureAwait(false) so that the execution does not attempt to resume on the original context.
                    // For instance, replace code such as:
                    //      result = await DoSomeTask()
                    // with the following:
                    //      result = await DoSomeTask().ConfigureAwait(false)
    
    
                    HttpResponseMessage response = await client.PostAsJsonAsync("", scoreRequest);
    
                    if (response.IsSuccessStatusCode)
                    {
                        string result = await response.Content.ReadAsStringAsync();
                        Console.WriteLine("Result: {0}", result);
                    }
                    else
                    {
                        Console.WriteLine(string.Format("The request failed with status code: {0}", response.StatusCode));
    
                        // Print the headers - they include the requert ID and the timestamp, which are useful for debugging the failure
                        Console.WriteLine(response.Headers.ToString());
    
                        string responseContent = await response.Content.ReadAsStringAsync();
                        Console.WriteLine(responseContent);
                    }
                }
            }
    
        }
    }
    


    • Edited by Mr Ham Thursday, November 12, 2015 10:28 AM
    Thursday, November 12, 2015 10:25 AM

Answers

  • Hello Mr. Ham,

    Unfortunately, async/await did not make it to Visual Studio 2010. See this SO thread for potential workarounds. One of them basically says type in VS2010 but compile using the newer .NET framework tools.

    If you're just testing stuff out, VS2015 is free!

    If you must build using the 2010 toolset, note that the only really critical part of that sample code is the network call using HttpClient. Here's an example of synchronous networking from SO.

    Let us know if you need any more help!

    Regards,

    AK

    • Marked as answer by Mr Ham Friday, November 13, 2015 1:02 AM
    Thursday, November 12, 2015 4:12 PM

All replies

  • Sorry we cannot see the error message. could you please stick it in here
    Thursday, November 12, 2015 11:14 AM
  • Hello Mr. Ham,

    Unfortunately, async/await did not make it to Visual Studio 2010. See this SO thread for potential workarounds. One of them basically says type in VS2010 but compile using the newer .NET framework tools.

    If you're just testing stuff out, VS2015 is free!

    If you must build using the 2010 toolset, note that the only really critical part of that sample code is the network call using HttpClient. Here's an example of synchronous networking from SO.

    Let us know if you need any more help!

    Regards,

    AK

    • Marked as answer by Mr Ham Friday, November 13, 2015 1:02 AM
    Thursday, November 12, 2015 4:12 PM
  • thank you~
    Friday, November 13, 2015 1:02 AM