rest - How to consume a ASP.NET Core WebAPI in a C# UWP application? -


i trying understand how possible consume asp.net core webapi within uwp/uap application. thought possible consume webapi similar consuming wcf service haven't found yet.

furthermore tried install microsoft.aspnet.webapi.core had no success not compatible uap (version=v10.0).

i bit lost now. maybe give me hint how use webapi within uwp application.

this same consuming api call. use httpclient class invoke endpoint , handle response, there no difference in expected behaviour.

imagine have asp.net core web api endpoint defined this:

public class stackoverflowcontroller : controller {         // wanted exemplify async capabilities.     // you'd use async/await getting database values, etc.     [         httpget,         allowanonymous,         route("api/greeting")     ]     public task<greetingresult> greeting() =>         task.fromresult(new greetingresult { message = "hello world!" }); }  public class greetingresult {     public string message { get; set; } } 

assuming hosted on `localhost:5000' following:

public class consumer {     public async task<string> getgreetingasync()     {         using (var client = new httpclient())         {             var response =                  await client.getstringasync("http://localhost:5000/api/greeting");             // response object string looks this:             // "{ message: 'hello world!' }"         }     } } 

additionally, deserialize typed object use newtonsoft.json. have example of uwp app doing thing here.


Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -