在.dotNet 4.5上Azure和使用REST / JSON Web服务

时间:2015-09-25 09:23:37

标签: c# rest azure .net-4.5 visual-studio-2015

我正在使用.NET Framework 4.6运行Microsoft Visual Studio Community 2015。我必须开发一个与Azure上的REST / JSON Web服务连接的基本客户端(控制台或其他)。我已经获得了以下示例代码,但它不起作用(可能是因为我对此很新,所以请原谅我!)。我的问题是我如何使这个工作或你有任何指针,如我如何设置Visual Studio(引用,包等)。我也相信我需要调用System.IdentityModel而不是Microsoft.IdentityModel,但这对我来说都是新手?这很难吗? Visual Studio似乎认识到任何方法(即使我在构建3.5之前有Build)。

var username = "<username>";
var password = "<password>";

// The Azure AD tenant address
var tenant = "mytest.onmicrosoft.com";

var clientApiId = “111111-222-3333-4444-3232342432";
var appId = “22222-333-5555-1111-3234343434";

var authority = String.Format(CultureInfo.InvariantCulture, “https://login.microsoftonline.com/{0}", tenant);

var authContext = new AuthenticationContext(authority);
var uc = new UserCredential(username, password);
var authResult = authContext.AcquireToken(clientApiId, appId, uc);

var httpClient = new HttpClient();

httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(authResult .AccessTokenType, authResult.AccessToken);

非常感谢您的帮助/协助。我真的没有想法从哪里开始以及如何使它工作......原则上看起来很容易但是: - (

0 个答案:

没有答案
相关问题