c# - communicate with WEB Api from windows phone project -
ive got web api project hosts data service. ok , can consume console client using code:
private static async task runasync() { using (var client = new httpclient()) { client.baseaddress = new uri("http://localhost:15017/"); client.defaultrequestheaders.accept.clear(); client.defaultrequestheaders.accept.add(new mediatypewithqualityheadervalue("application/json")); // http httpresponsemessage response = await client.getasync("api/products"); if (response.issuccessstatuscode) { var products = await response.content.readasasync<list<product>>(); foreach (var product in products) { console.writeline(product.name); console.writeline(product.description); console.writeline(product.shortdescription); console.writeline(product.prize); console.writeline("\n"); } } } } private static void main(string[] args) { runasync().wait(); }
works perfect.
than have windows phone 8 app. has such structure have viewmodels create instances of irepository interfaces. try connect web api , load data irepository classes using same code in console app when try add reference system.net.http.formatting needed ive got error whiole installing package:
adding 'microsoft.aspnet.webapi.webhost 5.1.2' phoneapp. install-package : not install package 'microsoft.aspnet.webapi.webhost 5.1.2'. trying install package project targets 'windowsphone,version=v8.0', package not contain assembly references or content files compatible framework. more information, contact package author.
so how can consume web api inside windows phone app ?
Comments
Post a Comment