c#.NET Web服务连接丢失,无法将数据传递到Windows Phone应用程序

c#.NET Web服务连接丢失,无法将数据传递到Windows Phone应用程序,c#,mysql,web-services,windows-phone-8,C#,Mysql,Web Services,Windows Phone 8,我们正在开发一个windows phone 8应用程序,它可以从.NET Web服务获取数据。 我们必须从一个大记录列表中检查哪个记录被修改或删除,并将其传递回应用程序。 目前记录超过46000;我解释: 我们的Windows phone应用程序执行此呼叫: private const int HUGE_OPERATION_TIMEOUT_MINUTES = 10; public static Task<GetCustomersCompletedEventArgs>

我们正在开发一个windows phone 8应用程序,它可以从.NET Web服务获取数据。 我们必须从一个大记录列表中检查哪个记录被修改或删除,并将其传递回应用程序。 目前记录超过46000;我解释:

我们的Windows phone应用程序执行此呼叫:

    private const int HUGE_OPERATION_TIMEOUT_MINUTES = 10;

    public static Task<GetCustomersCompletedEventArgs> GetClientiAsyncTask(this GridwaySoapClient client,
    Guid AuthenticationToken, DateTime LastUpdate, 
    int i, string jsonEntityKeyList)
    {
        var tcs = new TaskCompletionSource<GetCustomersCompletedEventArgs>();

        client.Endpoint.Address = WsAddress();
        client.Endpoint.Binding.ReceiveTimeout = new TimeSpan(0, HUGE_OPERATION_TIMEOUT_MINUTES, 0);
        client.Endpoint.Binding.OpenTimeout = new TimeSpan(0, HUGE_OPERATION_TIMEOUT_MINUTES, 0);
        client.Endpoint.Binding.CloseTimeout = new TimeSpan(0, HUGE_OPERATION_TIMEOUT_MINUTES, 0);
        client.Endpoint.Binding.SendTimeout = new TimeSpan(0, HUGE_OPERATION_TIMEOUT_MINUTES, 0);           
        client.InnerChannel.OperationTimeout = new TimeSpan(0, HUGE_OPERATION_TIMEOUT_MINUTES, 0);
        client.GetCustomersCompleted += (s, e) => TransferCompletion<GetCustomersCompletedEventArgs>(tcs, e, () => e);

        try
        {
            client.OpenAsync();
            client.GetCustomersAsync(AuthenticationToken, LastUpdate, jsonEntityKeyList, string.Empty, i);
        }
        catch (Exception ex)
        {
            throw ex;
        }

        return tcs.Task;
    }
private const int巨型\u操作\u超时\u分钟=10;
公共静态任务GetClientAsyncTask(此GridwaySoapClient客户端,
Guid AuthenticationToken,DateTime LastUpdate,
int i,字符串jsonEntityKeyList)
{
var tcs=new TaskCompletionSource();
client.Endpoint.Address=WsAddress();
client.Endpoint.Binding.ReceiveTimeout=新的时间跨度(0,巨大的\u操作\u超时\u分钟,0);
client.Endpoint.Binding.OpenTimeout=new TimeSpan(0,巨大的\u操作\u超时\u分钟,0);
client.Endpoint.Binding.CloseTimeout=新的时间跨度(0,巨大的\u操作\u超时\u分钟,0);
client.Endpoint.Binding.SendTimeout=新的时间跨度(0,巨大的\u操作\u超时\u分钟,0);
client.InnerChannel.OperationTimeout=新的时间跨度(0,巨大的\u操作\u超时\u分钟,0);
client.GetCustomersCompleted+=(s,e)=>TransferCompletion(tcs,e,()=>e);
尝试
{
client.OpenAsync();
getCustomerAsync(AuthenticationToken,LastUpdate,jsonEntityKeyList,string.Empty,i);
}
捕获(例外情况除外)
{
掷骰子;
}
返回tcs.Task;
}
GetCustomerAsync调用另一个方法,该方法调用WS传递ID列表;使用下面的脚本在数据库中检查这些ID

我们就是这样做的:

  • 我们从应用程序传递ID列表,这些ID是已经传递的记录的ID
  • db检查,通过在db上获取所有记录的id,如果传递的id仍然在此列表中
  • WS传回一个新的ID列表,这些ID是从db中删除或编辑的ID

    [WebMethod(BufferResponse = false)]
    public string GetCustomers(Guid AuthenticationToken, DateTime LastUpdate,
        string jsonEntityKeyList, ref string jsonDeleteKeyList, int chiamataNumero)
    {
        List<CUSTOMER> customers = new List<CUSTOMER>();
    
        if (GridwayAuthenticationToken.Exist(AuthenticationToken))
        {
    
            List<string> EntityKeyList = JsonConvert.DeserializeObject<List<string>>(jsonEntityKeyList);
            var crmCtx01 = new CrmGridwayAdapter().GetXrmServiceContext();
    
            // if it's the first time we don't ned to remove anything from app
            // 01/01/1900 is the defauld date used if there's no lastUpdate's date
            if (LastUpdate == null || LastUpdate == new DateTime(1900, 01, 01))
            {
    
    
                List<Account> clienti = new List<Account>();
                try
                {
                    clienti = crmCtx01.AccountSet.Skip(chiamataNumero * 500).Take(500).ToList();
                }
                catch
                {
                    return Serializer.Serialize(customers);
                }
                var clientiToPick = clienti.Where(x => !EntityKeyList.Contains(x.Id.ToString())).ToList();
    
                if (clientiToPick.Count == 0 && clienti.Count > 0)
                {
                    List<CUSTOMER> fake = new List<CUSTOMER>();
                    CUSTOMER fakeS = null;
                    fake.Add(fakeS);
                    return Serializer.Serialize(fake);
                }
    
                if (clientiToPick != null)
                {
                    customers = clientiToPick.Select(x => new CUSTOMER()
                    {
                        ID = (Guid)x.AccountId,
                        FULL_NAME = x.Name,
                        PHONE_NO = x.Telephone1,
                        PIVA_CF = x.new_piva,
                        MODIFIED_ON = (x.ModifiedOn == null ? CRMMinDate() : Convert.ToDateTime(x.ModifiedOn))
                    }).ToList();
                }
            }
            //if it's not the first time we sync there might be datas on app
            else
            {
                //we do this step only the first time
                if (chiamataNumero == 0 && EntityKeyList.Count() > 0)
                {
                    try
                    {
                // THIS is the step stopping connection
                        List<string> customersId = crmCtx01.AccountSet
                            .Select(x => x.AccountId.ToString()).ToList();
                        List<string> noMoreExistingRecords = EntityKeyList.Where(x => !customersId.Contains(x)).ToList();
                        List<string> editedRecords = crmCtx01.AccountSet.Where(x => x.ModifiedOn > LastUpdate).Select(x => x.AccountId.ToString()).ToList();
                        List<string> AddressCessatiIds = crmCtx01.AccountSet.Where(x => x.StateCode != 0).Select(x => x.AccountId.ToString()).ToList();
                        noMoreExistingRecords.AddRange(editedRecords);
                        noMoreExistingRecords.AddRange(AddressCessatiIds);
                        EntityKeyList.RemoveAll(x => editedRecords.Contains(x));
    
                        jsonDeleteKeyList = Serializer.Serialize(noMoreExistingRecords);
                    }
                    catch (Exception ex) { }
                }
    
    
                List<Account> clienti = new List<Account>();
                try
                {
                    clienti = crmCtx01.AccountSet.Where(x => x.ModifiedOn > LastUpdate).Skip(chiamataNumero * 500).Take(500).ToList();
                }
                catch
                {
                    return Serializer.Serialize(customers);
                } 
                var clientiToPick = clienti.Where(x => !EntityKeyList.Contains(x.Id.ToString())).ToList();
    
                if (clientiToPick.Count == 0 && clienti.Count > 0)
                {
                    List<CUSTOMER> fake = new List<CUSTOMER>();
                    CUSTOMER fakeS = null;
                    fake.Add(fakeS);
                    return Serializer.Serialize(fake);
                }
    
                if (clientiToPick != null)
                {
                    customers = clientiToPick.Select(x => new CUSTOMER()
                    {
                        ID = (Guid)x.AccountId,
                        FULL_NAME = x.Name,
                        PHONE_NO = x.Telephone1,
                        PIVA_CF = x.new_piva,
                        MODIFIED_ON = (x.ModifiedOn == null ? CRMMinDate() : Convert.ToDateTime(x.ModifiedOn))
                    }).ToList();
                }
            }
    
            return Serializer.Serialize(customers);
        }
        else
        {
            throw GridwayAuthenticationToken.AuthenticationExceptions.AuthenticationRequired();
        }
    }
    
    [WebMethod(BufferResponse=false)]
    公共字符串GetCustomers(Guid AuthenticationToken、DateTime LastUpdate、,
    字符串JSONENTYKEYLIST,参考字符串jsonDeleteKeyList,int chiamataNumero)
    {
    列出客户=新列表();
    if(GridwayAuthenticationToken.Exist(AuthenticationToken))
    {
    List EntityKeyList=JsonConvert.DeserializeObject(jsonEntityKeyList);
    var crmCtx01=新的CrmGridwayAdapter().GetXrmServiceContext();
    //如果这是我们第一次不想从应用程序中删除任何内容
    //如果没有最新更新的日期,则使用1900年1月1日的默认日期
    if(LastUpdate==null | | LastUpdate==new DateTime(1900,01,01))
    {
    List clienti=新列表();
    尝试
    {
    clienti=crmCtx01.AccountSet.Skip(chiamataNumero*500).Take(500).ToList();
    }
    抓住
    {
    返回序列化程序。序列化(客户);
    }
    var clienttopick=clienti.Where(x=>!EntityKeyList.Contains(x.Id.ToString()).ToList();
    如果(clienttopick.Count==0&&clienti.Count>0)
    {
    List fake=新列表();
    客户假货=空;
    伪造。添加(伪造);
    返回序列化程序。序列化(假);
    }
    if(clientTopick!=null)
    {
    customers=clientiToPick.Select(x=>newcustomer()
    {
    ID=(Guid)x.AccountId,
    全名=x.名称,
    电话号码=x.Telephone1,
    PIVA_CF=x.新的PIVA,
    MODIFIED_ON=(x.ModifiedOn==null?CRMMinDate():Convert.ToDateTime(x.ModifiedOn))
    }).ToList();
    }
    }
    //如果这不是我们第一次同步,应用程序上可能会有数据
    其他的
    {
    //我们只是第一次做这一步
    if(chiamataNumero==0&&EntityKeyList.Count()>0)
    {
    尝试
    {
    //这是停止连接的步骤
    列表customersId=crmCtx01.AccountSet
    .Select(x=>x.AccountId.ToString()).ToList();
    List noMoreExistingRecords=EntityKeyList.Where(x=>!customersId.Contains(x)).ToList();
    列出editedRecords=crmCtx01.AccountSet.Where(x=>x.ModifiedOn>LastUpdate)。选择(x=>x.AccountId.ToString()).ToList();
    列表地址cessatiids=crmCtx01.AccountSet.Where(x=>x.StateCode!=0)。选择(x=>x.AccountId.ToString()).ToList();
    noMoreExistingRecords.AddRange(editedRecords);
    noMoreExistingRecords.AddRange(AddressCessatiIds);
    RemoveAll(x=>editedRecords.Contains(x));
    jsonDeleteKeyList=Serializer.Serialize(noMoreExistingRecords);
    }
    捕获(例外情况除外){}
    }
    List clienti=新列表();
    尝试
    {
    clienti=crmCtx01.AccountSet.Where(x=>x.ModifiedOn>LastUpdate).Skip(chiamataNumero*500).Take(500).ToList();
    }
    抓住
    {
    返回序列化程序。序列化(客户);
    } 
    var clienttopick=clienti.Where(x=>!EntityKeyList.Contains(x.Id.ToString()).ToList();
    如果(clienttopick.Count==0&&clienti.Count>0)
    {
    List fake=新列表();
    客户假货=空;
    伪造。添加(伪造);
    返回序列化程序。序列化(假);
    }
    if(clientTopick!=null)
    {
    customers=clientiToPick.Select(x=>newcustomer()
    {
    ID=(Guid)x.AccountId,
    全名=x.名称,
    电话号码=x.Telephone1,
    PIV