当我在getresponsedata上放置一个断点时,代码运行良好,但是没有断点则不起作用

时间:2019-06-03 09:15:54

标签: c#

    //webservice connection
 CRB_WEBSERVICE.CBS_SERVICE.BatchPublicServiceClient proxy = new CRB_WEBSERVICE.CBS_SERVICE.BatchPublicServiceClient("BasicHttpBinding_IBatchPublicService");
                    proxy.ClientCredentials.UserName.UserName = "";
                    proxy.ClientCredentials.UserName.Password = "";
                    string currdte = DateTime.Now.ToString("yyyyMMdd");
                    //Open Connection for webservice
                    proxy.Open();
    //batchid is a string requested in format the client wants
                    string batchid = "" + currdte + "_" + "D" + "_" + "**" + "_" + num + "_" + "XML" + "_" + "T"; 
//generatexml is generating an XML file which is then zipped and sent via //webservice
                    GenerateXML(batchid);
     try
                        {
//process to send zipped file via webservice

                            byte[] data = File.ReadAllBytes(batchid + ".zip");
                                     proxy.Begin(batchid);
                            proxy.PutData(batchid, 1, data);
                            proxy.Finish(batchid, 1);
                            var b = proxy.GetBatchInfo(batchid);
                          // thread so it waits for the response
                            Thread.Sleep(11000);
// this is where my issue is.if i put a breakpoint i get a response of a //zipped file. if i dont nothing happens
                           **var result = proxy.GetResponseData(batchid, 1);**
                            //Thread.Sleep(100);
                            System.IO.File.WriteAllBytes(@"C:\CBS_WEBSERVICE\Response.zip", result);

}

请注意,这不是完整的代码。我需要帮助,因为当我在GetResponseData上设置断点时,我的代码运行得很好,但是如果我不这样做,它不会带来响应。我尝试添加thread.sleep,以便它等待来自Web服务的响应,但仍然没有运气。我已经添加了评论。

1 个答案:

答案 0 :(得分:0)

我应该在调用方法BatchStatus之前检查第一个参数:GetDataResponse。我再次阅读了API文档。没有batchstatus GetDataResponse将为null,因此代码在释放模式下挂起,仅在调试模式下工作。

 var b = proxy.GetBatchInfo(batchid);

 while (b.BatchStatus != CRB_WEBSERVICE.CBS_SERVICE.BatchStatuses.Finished)
                        {
                            b = proxy.GetBatchInfo(batchid);
                        }
if (b.BatchStatus == CRB_WEBSERVICE.CBS_SERVICE.BatchStatuses.Finished)
                        {
                            if (b.BatchResult == CRB_WEBSERVICE.CBS_SERVICE.BatchResults.Success)
                            {  
                                var result = proxy.GetResponseData(batchid, 1);
}
}