【发布时间】:2014-09-14 22:12:24
【问题描述】:
我正在使用 Azure ML,并且我有代码示例来调用我的 Web 服务(可惜它仅在 C# 中)。有人可以帮我把它翻译成 F# 吗?除了 async 和 await 之外,我什么都完成了。
static async Task InvokeRequestResponseService()
{
using (var client = new HttpClient())
{
ScoreData scoreData = new ScoreData()
{
FeatureVector = new Dictionary<string, string>()
{
{ "Zip Code", "0" },
{ "Race", "0" },
{ "Party", "0" },
{ "Gender", "0" },
{ "Age", "0" },
{ "Voted Ind", "0" },
},
GlobalParameters = new Dictionary<string, string>()
{
}
};
ScoreRequest scoreRequest = new ScoreRequest()
{
Id = "score00001",
Instance = scoreData
};
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/19a2e623b6a944a3a7f07c74b31c3b6d/services/f51945a42efa42a49f563a59561f5014/score");
HttpResponseMessage response = await client.PostAsJsonAsync("", scoreRequest);
if (response.IsSuccessStatusCode)
{
string result = await response.Content.ReadAsStringAsync();
Console.WriteLine("Result: {0}", result);
}
else
{
Console.WriteLine("Failed with status code: {0}", response.StatusCode);
}
}
谢谢
【问题讨论】:
-
顺便说一句:期待您的下一篇博文 :-) 听起来会很酷!
-
谢谢。现在无法在记录上键入映射。查看 Fiddler,它显示 ErrorCode=MissingScoreInstance。我确保案例匹配。我想知道 Json 是否以不同的方式处理记录和类型?看起来 is 在后挂一个 @ 符号?
-
就是这样。从记录类型更改为类使其工作。我周二的博客会很有趣
标签: azure f# azure-machine-learning-studio