我正在按照Github的教程进行操作,当我调用下面的“ await client”行时,似乎出错了。错误是Simple.OData.Client.WebRequestException: 'Resource Not Found'
,但是当我在浏览器中访问该URL时,它可以正常工作。知道如何进一步解决此问题吗?
Main.cs:
using Simple.OData.Client; //Install-Package Simple.OData.Client
static void Main(string[] args)
{
MCdemo().GetAwaiter().GetResult();
Console.WriteLine("Press any key to exit");
Console.ReadKey();
}
public static async Task<string> MCdemo()
{
var client = new ODataClient("https://packages.nuget.org/v1/FeedService.svc/");
var x = ODataDynamic.Expression;
IEnumerable<dynamic> packages = await client
.For(x.Packages)
.Filter(x.Title == "Simple.OData.Client")
.FindEntriesAsync();
foreach (var package in packages)
{
Console.WriteLine(package.Title);
}
return "success";
}
答案 0 :(得分:0)
您将收到该异常,因为那是Nuget软件包的旧URL。本教程应该已更新。新的Nuget网址为https://api.nuget.org/v3/index.json,请参见此SO和Github
但是对于您的教程,您可以使用此http://services.odata.org/V4/TripPinServiceRW/
var client = new ODataClient("http://services.odata.org/V4/TripPinServiceRW/");
var x = ODataDynamic.Expression;
IEnumerable<dynamic> values = await client
.For(x.Photos)
.FindEntriesAsync();
foreach (var photo in values)
{
Console.WriteLine(photo.Name);
}
return "success";