广告系列效果报告在SubmitDownloadAsync上挂起 [英] Campaign Performance Report hangs on SubmitDownloadAsync

查看:62
本文介绍了广告系列效果报告在SubmitDownloadAsync上挂起的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用引用Microsoft.BingAds的net45版本的BingAds二进制文件(Microsoft.BingAds.SDK.10.4.2)的最新nuget包版本下载广告系列效果报告。


或多或少是从api参考示例*中复制的代码(而不是下载关键字效果报告,它正在下载广告系列效果报告)。我所做的唯一其他修改是在RunAsync
方法中添加DateTime参数。


问题出在"await ReportingService.SubmitDownloadAsync(reportRequest);"中。呼叫。我使用fiddler来确保请求正在运行,并且已经由Bing代表确认该请求是一个格式正确的SOAP请求
以及我同样收到的响应。但是,我运行代码(该行的断点),点击该行,继续调试,它只是坐在那里等待似乎永远得到这个响应。响应来自fiddler,但
代码不会继续。在代码中的任何位置之后,它都不会触及任何行。我现在评论了后续代码,因为我不想将其保存到文件中,而是在内存中运行一些计算。


这是我的代码:


 

公共类BingCostRetriever:ICostRetriever
{
private readonly IAlerter _alerter;
//私人ServiceClient< IReportingService> _服务;
public static ReportingServiceManager ReportingService;

public BingCostRetriever(IAlerter alerter)
{
_alerter = alerter;
}

公共IList< RTMChild>检索(日期时间日期)
{
var authorisationData = new AuthorizationData
{
Authentication =
new OAuthDesktopMobileAuthCodeGrant(" SENSITIVE",
ConfigurationManager.AppSettings [ " BingRefreshToken"]),
CustomerId = SENSITIVE,
AccountId = SENSITIVE,
DeveloperToken = ConfigurationManager.AppSettings [" BingDeveloperToken"]
};

RunAsync(authorisationData,date).Wait();
返回新列表< RTMChild>();
}

私有异步任务RunAsync(AuthorizationData authorizationData,DateTime日期)
{
ReportingService = new ReportingServiceManager(authorizationData);
ReportingService.StatusPollIntervalInMilliseconds = 5000;

var reportRequest = GetCampaignPerformanceReportRequest(authorizationData.AccountId,date);

等待SubmitAndDownload(reportRequest);
}

private ReportRequest GetCampaignPerformanceReportRequest(long accountId,DateTime date)
{
返回新的CampaignPerformanceReportRequest
{
格式= ReportFormat.Csv,
语言= ReportLanguage.English,
ReportName =" Bing Campaign Report",
ReturnOnlyCompleteData = false,
Aggregation = ReportAggregation.Daily,
Scope = new AccountThroughCampaignReportScope
{
AccountIds = new [] {accountId},
Campaigns = null
},
Time = new ReportTime {CustomDateRangeStart = GetBingDate(date),CustomDateRangeEnd = GetBingDate( date)},
Columns = new [] {CampaignPerformanceReportColumn.CampaignName,CampaignPerformanceReportColumn.Status,CampaignPerformanceReportCol umn.Spend}

};
}

私有异步任务SubmitAndDownload(ReportRequest reportRequest)
{
var reportingDownloadOperation = await ReportingService.SubmitDownloadAsync(reportRequest);

ReportingOperationStatus downloadStatus;
var waitTime = new TimeSpan(0,0,5);

//此示例每5秒轮询一次,最多2分钟。

for(int i = 0; i< 24; i ++)
{
Thread.Sleep(waitTime);

downloadStatus = await reportingDownloadOperation.GetStatusAsync();

// if(downloadStatus.Status == ReportRequestStatusType.Success)
// {
// break;
//}
}

// var resultFilePath = await reportingDownloadOperation.DownloadResultFileAsync(
// FileDirectory,
// ResultFileName,
// decompress:true,
// overwrite:true); //如果要覆盖同一文件,请将此值设置为true。

//OutputStatusMessage(String.Format("Download result file:{0} \ n",resultFilePath));
}


private Date GetBingDate(System.DateTime date)
{
返回新日期{Year = date.Year,Month = date.Month, Day = date.Day};
}
}

为什么会发生这种情况?


谢谢,


Kieran。



* https://msdn.microsoft。 com / zh-CN / library / bing-ads-reporting-request-and-download-a-keyword-performance-report-in-csharp.aspx?f = 255& MSPPError = -2147217396

解决方案

您可能已阻止同步上下文,并且正在观察死锁。当你调用RunAsync时,我会尝试使用await而不是.Wait。

 //当前
RunAsync(authorisationData,date).Wait();

//建议
等待RunAsync(authorisationData,date);


此处此处您可以阅读一些文章以获取更多信息。


异步和等待


不要阻止异步代码


异步编程使用Async和Await



我希望这有帮助!


Eric


I am trying to download a campaign performance report with the latest nuget package version of BingAds binaries (Microsoft.BingAds.SDK.10.4.2) referencing the net45 version of Microsoft.BingAds.

It is more or less the code copied from the api reference example* (rather than downloading a keyword performance report, it's downloading a campaign performance report). The only other modifications I have made is adding a DateTime parameter to the RunAsync method.

The problem is in the "await ReportingService.SubmitDownloadAsync(reportRequest);" call. I have used fiddler to assure that the request is being run, and have had it confirmed by a Bing Representative that the request is a well formed SOAP request and the response I receive likewise. However, I run the code (breakpoint on that line), hit that line, continue debugging and it just sits there waiting what seems like forever to get this response. The response comes through just fine on fiddler, but the code doesn't proceed. It doesn't hit any lines after that one, anywhere in the code. I have commented the subsequent code for now, as I'm not wanting to save it to a file, but run some calculations in memory.

Here's my code:

public class BingCostRetriever : ICostRetriever { private readonly IAlerter _alerter; //private ServiceClient<IReportingService> _service; public static ReportingServiceManager ReportingService; public BingCostRetriever(IAlerter alerter) { _alerter = alerter; } public IList<RTMChild> Retrieve(DateTime date) { var authorisationData = new AuthorizationData { Authentication = new OAuthDesktopMobileAuthCodeGrant("SENSITIVE", ConfigurationManager.AppSettings["BingRefreshToken"]), CustomerId = SENSITIVE, AccountId = SENSITIVE, DeveloperToken = ConfigurationManager.AppSettings["BingDeveloperToken"] }; RunAsync(authorisationData, date).Wait(); return new List<RTMChild>(); } private async Task RunAsync(AuthorizationData authorizationData, DateTime date) { ReportingService = new ReportingServiceManager(authorizationData); ReportingService.StatusPollIntervalInMilliseconds = 5000; var reportRequest = GetCampaignPerformanceReportRequest(authorizationData.AccountId, date); await SubmitAndDownload(reportRequest); } private ReportRequest GetCampaignPerformanceReportRequest(long accountId, DateTime date) { return new CampaignPerformanceReportRequest { Format = ReportFormat.Csv, Language = ReportLanguage.English, ReportName = "Bing Campaign Report", ReturnOnlyCompleteData = false, Aggregation = ReportAggregation.Daily, Scope = new AccountThroughCampaignReportScope { AccountIds = new[] { accountId }, Campaigns = null }, Time = new ReportTime { CustomDateRangeStart = GetBingDate(date), CustomDateRangeEnd = GetBingDate(date) }, Columns = new[] { CampaignPerformanceReportColumn.CampaignName, CampaignPerformanceReportColumn.Status, CampaignPerformanceReportColumn.Spend } }; } private async Task SubmitAndDownload(ReportRequest reportRequest) { var reportingDownloadOperation = await ReportingService.SubmitDownloadAsync(reportRequest); ReportingOperationStatus downloadStatus; var waitTime = new TimeSpan(0, 0, 5); // This sample polls every 5 seconds up to 2 minutes. for (int i = 0; i < 24; i++) { Thread.Sleep(waitTime); downloadStatus = await reportingDownloadOperation.GetStatusAsync(); //if (downloadStatus.Status == ReportRequestStatusType.Success) //{ // break; //} } //var resultFilePath = await reportingDownloadOperation.DownloadResultFileAsync( // FileDirectory, // ResultFileName, // decompress: true, // overwrite: true); // Set this value true if you want to overwrite the same file. //OutputStatusMessage(String.Format("Download result file: {0}\n", resultFilePath)); }

private Date GetBingDate(System.DateTime date) { return new Date { Year = date.Year, Month = date.Month, Day = date.Day }; } }

Any ideas why this is happening?

Thanks,

Kieran.

*https://msdn.microsoft.com/en-us/library/bing-ads-reporting-request-and-download-a-keyword-performance-report-in-csharp.aspx?f=255&MSPPError=-2147217396

解决方案

It is possible that you have blocked the synchronization context, and are observing deadlock. I would try using await instead of .Wait when you call RunAsync.

// Current
RunAsync(authorisationData, date).Wait();

// Proposed
await RunAsync(authorisationData, date);

Also here are a few articles you can read for more information.

Async and Await

Don't Block on Async Code

Asynchronous Programming with Async and Await

I hope this helps!

Eric


这篇关于广告系列效果报告在SubmitDownloadAsync上挂起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆