C# BingAds API Soap请求

C# BingAds API Soap请求,c#,soap,bing,C#,Soap,Bing,我一直在尝试使用BingAds Soap API调用来获得关键字性能。但由于某种原因,下面的请求失败了。如果有人能告诉我问题在哪里,我将不胜感激。它返回内部500错误 private void button1_Click(object sender, EventArgs e) { string xml = @"<?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv='h

我一直在尝试使用BingAds Soap API调用来获得关键字性能。但由于某种原因,下面的请求失败了。如果有人能告诉我问题在哪里,我将不胜感激。它返回内部500错误

private void button1_Click(object sender, EventArgs e)
{

      string xml = @"<?xml version='1.0' encoding='utf-8'?><soapenv:Envelope
      xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'
      xmlns:v8='https://adcenter.microsoft.com/v8'
      xmlns:arr='https://schemas.microsoft.com/2003/10/Serialization/Arrays'>
      <soapenv:Header>
      <v8:UserName>xxx</v8:UserName>
      <v8:Password>xxx</v8:Password>
      <v8:DeveloperToken>xxx</v8:DeveloperToken>
      <v8:CustomerId>xxx</v8:CustomerId>
      <v8:CustomerAccountId>xxx</v8:CustomerAccountId>
      <v8:ApplicationToken></v8:ApplicationToken>
      </soapenv:Header>
      <soapenv:Body>
      <v8:SubmitGenerateReportRequest>
      <v8:ReportRequesti:type=""v8:KeywordPerformanceReportRequest""xmlns:i='http://www.w3.org/2001/XMLSchema-instance'>
      <v8:Format>Csv</v8:Format>
      <v8:Language>English</v8:Language>
      <v8:ReportName>MyReport</v8:ReportName>
      <v8:ReturnOnlyCompleteData>false</v8:ReturnOnlyCompleteData>
      <v8:Aggregation>Daily</v8:Aggregation>
      <v8:Columns>
      <v8:KeywordPerformanceReportColumn>AccountId</v8:KeywordPerformanceReportColumn>
      <v8:KeywordPerformanceReportColumn>AccountName</v8:KeywordPerformanceReportColumn>
      <v8:KeywordPerformanceReportColumn>Keyword</v8:KeywordPerformanceReportColumn>
      <v8:KeywordPerformanceReportColumn>KeywordId</v8:KeywordPerformanceReportColumn>
      <v8:KeywordPerformanceReportColumn>AdGroupName</v8:KeywordPerformanceReportColumn>
      <v8:KeywordPerformanceReportColumn>CostPerConversion</v8:KeywordPerformanceReportColumn>
      </v8:Columns>
      <v8:Scope>
      <v8:AccountIds>
      <arr:long>xxx</arr:long>
      </v8:AccountIds>
      </v8:Scope>
      <v8:Time>
      <v8:PredefinedTime>LastSevenDays</v8:PredefinedTime>
      </v8:Time>
      </v8:ReportRequest>
      </v8:SubmitGenerateReportRequest>
      </soapenv:Body>
      </soapenv:Envelope>";

        HttpWebRequest req = (HttpWebRequest)WebRequest.Create("https://adcenterapi.microsoft.com/Api/Advertiser/v8/Reporting/ReportingService.svc");

        req.ContentType = "text/xml; charset=utf-8";
        req.Method = "POST";
        req.Accept = "text/xml";

        using (StreamWriter writer = new StreamWriter(req.GetRequestStream()))
        {
            writer.Write(xml);
        }

        WebResponse response1 = req.GetResponse();
        Stream responseStream = response1.GetResponseStream();
        StreamReader myStreamReader = new StreamReader(responseStream);
        string responseData = myStreamReader.ReadToEnd();


}
private void按钮1\u单击(对象发送者,事件参数e)
{
字符串xml=@“
xxx
xxx
xxx
xxx
xxx
Csv
英语
我的报告
假的
每日的
帐户ID
帐户名
关键词
关键字ID
AdGroupName
成本转换
xxx
最后七天
";
HttpWebRequest req=(HttpWebRequest)WebRequest.Create(“https://adcenterapi.microsoft.com/Api/Advertiser/v8/Reporting/ReportingService.svc");
req.ContentType=“text/xml;charset=utf-8”;
请求方法=“POST”;
req.Accept=“text/xml”;
使用(StreamWriter writer=newstreamwriter(req.GetRequestStream()))
{
Write.Write(xml);
}
WebResponse response1=req.GetResponse();
流responseStream=response1.GetResponseStream();
StreamReader myStreamReader=新的StreamReader(responseStream);
字符串responseData=myStreamReader.ReadToEnd();
}
此行:

HttpWebRequest req = (HttpWebRequest)WebRequest.Create("https://adcenterapi.microsoft.com/Api/Advertiser/v8/Reporting/ReportingService.svc");
您不应该在URL中包含?wsdl,如下所示:

HttpWebRequest req = (HttpWebRequest)WebRequest.Create("https://adcenterapi.microsoft.com/Api/Advertiser/v8/Reporting/ReportingService.svc?wsdl");

AFAIK数组命名空间不应为https

xmlns:arr=''

此外,在关键字PerformanceReportRequest周围不需要额外的引号。 “v8:关键字PerformanceReportRequest”

这不应影响请求,但不是必需的

我希望这有帮助


Eric Urban[MSFT Bing Ads UA]

这似乎不是问题所在。我修复了这个URL。它仍然不起作用。不,这只会使它成为对wsdl的请求。请尝试从wsdl生成soap客户机,当有其他方法可用时,处理大量未类型化的猜测XML很少是合适的。