最近在我的客户机域中试用了Azure函数,我成功地部署了一个,并从一个.NET控制台应用程序调用了它。
尽管花了好几个小时在谷歌上搜索,但我所能实现的只是激活AppService身份验证,如前所述
here
我的控制台应用程序然后开始失败,代码401未经授权和“你没有权限查看此目录或页面”的响应内容-到目前为止,良好。。。然后我想我可以告诉Azure需要一个广告组的成员身份来调用这个函数,la WCF,
但是怎么做呢?
下面是我调用函数的代码:
private static async void CallMyTypedFunctionAsync()
{
var functionAddress = "https://[...].azurewebsites.net/api/MyTypedFunction";
var requestDto = new DataContracts.MyTypedFunctionReqest { X = 6, Y = 7 };
HttpRequestMessage message = new HttpRequestMessage(HttpMethod.Post, functionAddress)
{
Content = new StringContent(JsonConvert.SerializeObject(requestDto), Encoding.UTF8, "application/json")
};
var httpClient = new HttpClient();
var response = await httpClient.SendAsync(message);
var responseContent = await response.Content.ReadAsStringAsync();
if (response.StatusCode == System.Net.HttpStatusCode.OK)
{
var responseDto = JsonConvert.DeserializeObject<DataContracts.MyTypedFunctionResponse>(responseContent);
Console.WriteLine("CallMyTypedFunctionAsync's result: {0}", responseDto.Z); // 42
}
else
Console.WriteLine("CallMyTypedFunctionAsync has failed. {0}: {1}", response.StatusCode, responseContent);
}