我正在尝试使用Simple Odata Client动态打印数据。 我想得到与此查询相同的结果: Northwind
我用以下代码创建了一个简单的控制台应用程序:
class Program
{
static void Main(string[] args)
{
//Query Model : https://services.odata.org/Northwind/Northwind.svc/Products?$filter=SupplierID%20eq%201
Console.WriteLine("Press Enter when the job is completed");
SimpleQuery();
Console.ReadLine();
}
static async void SimpleQuery()
{
var client = new ODataClient("https://services.odata.org/Northwind/Northwind.svc/");
try
{
var x = ODataDynamic.Expression;
IEnumerable<dynamic> Products = await client
.For(x.Products)
.Filter(x.SupplierID == 1)
.FindEntriesAsync();
foreach (var Product in Products)
{
Console.WriteLine(Product.ProductName);
}
}
catch (Exception e)
{
Console.WriteLine("Simple Query " + e);
}
}
}
不幸的是,我总是收到此错误消息:
> Press Enter when the job is completed
Simple Query System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a send. ---> System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
at System.Net.Sockets.Socket.EndReceive(IAsyncResult asyncResult)
at System.Net.Sockets.NetworkStream.EndRead(IAsyncResult asyncResult)
--- End of inner exception stack trace ---
at System.Net.TlsStream.EndWrite(IAsyncResult asyncResult)
at System.Net.PooledStream.EndWrite(IAsyncResult asyncResult)
at System.Net.ConnectStream.WriteHeadersCallback(IAsyncResult ar)
--- End of inner exception stack trace ---
D:\Workspaces\Ronan\TestODATA\TestODATA\Program.cs:line 26
我的目标是能够在运行时执行过程中动态更改我的Odata查询。
在这个主题上您可以帮我吗?
此致