Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 未激发WCF客户端代理BeginExecute回调_C#_.net_Wcf_Odata - Fatal编程技术网

C# 未激发WCF客户端代理BeginExecute回调

C# 未激发WCF客户端代理BeginExecute回调,c#,.net,wcf,odata,C#,.net,Wcf,Odata,我发现有时候OData服务(v2)的BeginExecute方法的回调不会触发。只有在运行多个并行异步请求时才会发生这种情况。 一些演示代码: public void Run() { Service = new SAP.TEST_SRV_Entities(new Uri(@"https://...")); Service.Credentials = new NetworkCredential("user", "password");

我发现有时候OData服务(v2)的BeginExecute方法的回调不会触发。只有在运行多个并行异步请求时才会发生这种情况。 一些演示代码:

    public void Run()
    {
        Service = new SAP.TEST_SRV_Entities(new Uri(@"https://..."));
        Service.Credentials = new NetworkCredential("user", "password");
        Service.MergeOption = System.Data.Services.Client.MergeOption.NoTracking;

        for (int i = 0; i < 6; i++)
        {
            AsyncCallback callback = new AsyncCallback(Response);
            string url = @"https://...";
            Service.BeginExecute<SAP.Folder>(new Uri(url), callback, null);
            Console.WriteLine("Request");
            //System.Threading.Thread.Sleep(1000);
        }
    }

    void Response(IAsyncResult asyncResult)
    {
        Console.WriteLine("Response");
        List<SAP.Folder> sapfolders = Service.EndExecute<SAP.Folder>(asyncResult).ToList();
    }
启动了6个请求,但只有4个请求结束。 我的服务器上没有收到丢失的两个请求。如果我在请求之间插入一个sleep,或者它们被称为synchronous,那么一切都很好,我得到了所有的响应。 在我看来,最初的请求似乎不正确。增加ServicePointManager.DefaultConnectionLimit会导致更多已完成的请求。 代码由wpf按钮的eventhandler调用,因此应用程序没有退出

如果在http请求的WebResponse上未调用close,则会出现类似的错误。在WCF中找不到“关闭”


你知道如何得到所有的回应吗?是否缺少一些东西,如第一次响应时的关闭/结束呼叫?

由于我没有找到解决方案,我将使用一种变通方法。将在自己的线程中使用同步方法,而不是使用异步方法

Request
Request
Request
Request
Request
Request
Response
Response
Response
Response