c#
  • soap
  • bing
  • 2013-02-03 194 views 0 likes 
    0

    我一直在嘗試使用BingAds Soap API調用來獲得關鍵字性能。但是由於某種原因,下面的請求被拒絕了。如果有人能告訴我問題在哪裏,我將不勝感激。它將返回內部500錯誤。BingAds API肥皂請求

    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(); 
    
    
    } 
    
    +0

    嘗試從WSDL生成SOAP客戶端,而不是,處理非類型化,猜測XML的大塊時還有其他的方法很少適當的。 –

    回答

    0

    這條線:

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

    你不應該有WSDL的URL,就像這樣:?

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

    這似乎不是問題。我修復了這個URL。它仍然不起作用。 –

    +0

    不,這隻會讓它成爲wsdl的請求。 –

    1

    AFAIK的數組命名空間不應該是HTTPS。

    的xmlns:ARR = 'http://schemas.microsoft.com/2003/10/Serialization/Arrays'

    而且你不應該需要大約KeywordPerformanceReportRequest額外的引號。 「v8:KeywordPerformanceReportRequest」

    這應該不會影響請求,但不是必需的。

    我希望這有助於!

    埃裏克城市[MSFT Bing Ads廣告UA]

    相關問題