locked
ReportingService V5.1 not working for me. RRS feed

  • Question

  • I have created classes to call the reporting service for Google and Yahoo and am trying to do the same for MSN. I attempted to use the sample java client code posted, but am not having any luck.
    I always received the error faultString: Cannot create an abstract and further down in the trace I see System.MemberAccessException

    I generated the stubs using ant wsdl2java using the -a option and all the necessary classes are getting created.

    However, the sample class does not compile as is because the setAccounts method wants and ArrayOfInt object.
    I made the following changes to get it to compile
    int
    [] accountIds = { 12345,1234};
    ArrayOfint aoi =
    new ArrayOfint();
    aoi.set_int(accountIds);
    scope.setAccountIds(aoi);

    I had to make a similar change for "reportRequest.setColumns".
    The strange thing is that when I get it to compile and capture the SOAP message, it appears pieces are missing.

    I am using Spring to inject username, etc... Below is my code:

    package com.roving.search.campaign.dto;

    import java.io.*;
    import java.util.*;
    import java.util.Date;
    import java.net.URL;

    import com.microsoft.adcenter.api.advertiser.v5.*;
    import com.microsoft.schemas._2003._10.Serialization.Arrays.ArrayOfint;
    import com.roving.search.campaign.dto.ASearchEngineCampaign;
    import com.roving.so.common.helper.DateHelper;

    public class MSNSearchEngineCampaign extends ASearchEngineCampaign

    {

    // The Microsoft adCenter API namespace,
    // which is used in the SOAP header.
    String namespace =
    "https://adcenter.microsoft.com/api/advertiser/v5";

    // This example URL is for the sandbox environment.
    // Update the URL as needed when using the production environment.
    // String url = "https://sandboxapi.adcenter.microsoft.com/Api/Advertiser/V5.1/Reporting/ReportingService.svc?wsdl";
    // The following is the production environment URL.
    String url = "https://adcenterapi.microsoft.com/Api/Advertiser/V5.1/Reporting/ReportingService.svc?wsdl";

    //String url = "http://localhost:8181";
    public void process()
    {
    // Administration.getQuotaBalance();

    // Select data retrieve date to use. Usually previous day, but can be overridden
    Date dataRunDate = getDataRetrieveDate();
    Date dataOverRideDate = this.getDataOverRideDate();

    Calendar runDate = Calendar.getInstance();
    Calendar today = Calendar.getInstance();

    if (dataOverRideDate != null)
    runDate.setTime(dataOverRideDate);
    else
    runDate.setTime(dataRunDate);
    if (DateHelper.dateDiffInDays(runDate.getTime(), today.getTime()) < 1) {
    System.out.println("Run date of " + runDate.getTime() + ". Data is current. Cancelling execution...");
    return;
    }
    com.microsoft.adcenter.api.advertiser.v5.Date msnDate = new com.microsoft.adcenter.api.advertiser.v5.Date();
    int day = runDate.get(Calendar.DATE);
    int month = runDate.get(Calendar.MONTH);
    int year = runDate.get(Calendar.YEAR);
    msnDate.setDay(day);
    msnDate.setMonth(month);
    msnDate.setYear(year);

    //int[] accountIds = { 489 }; // Application-specific value.
    int[] accountIds = { 12345,123456 };


    ArrayOfint aoi = new ArrayOfint();
    aoi.set_int(accountIds);


    // This example URL is for the sandbox environment.
    // Update the URL as needed when using the production environment.
    //String url = "https://sandboxapi.adcenter.microsoft.com/Api/Advertiser/V5.1/Reporting/ReportingService.svc?wsdl";
    // The following is the production environment URL.
    // String url = "https://adcenterapi.microsoft.com/Api/Advertiser/V5.1/Reporting/ReportingService.svc?wsdl";

    IReportingService reportManagement = null;

    ReportingServiceLocator reportServiceLocator = null;

    BasicHttpBinding_IReportingServiceStub stub = null;

    QueueReportRequest queueReportRequest = null;
    QueueReportResponse queueReportResponse = null;

    GetReportStatusRequest getReportStatusRequest = null;
    GetReportStatusResponse getReportStatusResponse = null;

    ReportRequestStatus reportRequestStatus = null;
    ReportRequestStatusType status = null;

    String reportId = null;

    UserCredentials userCredentials = null;

    ApplicationToken appToken = null;

    DeveloperToken devToken = null;

    try {

    reportServiceLocator = new ReportingServiceLocator();

    reportServiceLocator.setBasicHttpBinding_IReportingServiceEndpointAddress(url);

    reportManagement =
    reportServiceLocator.getBasicHttpBinding_IReportingService();

    userCredentials = new UserCredentials();
    devToken = new DeveloperToken();
    appToken = new ApplicationToken();

    // The application token is reserved for future use and
    // does not need to be assigned a value.
    userCredentials.setUsername(getUsername());
    userCredentials.setPassword(getPassword());
    devToken.setValue(getDeveloperToken());
    appToken.setValue(null); // Not used yet

    stub = (BasicHttpBinding_IReportingServiceStub)
    reportManagement;

    // Assign the necessary values to the header.
    stub.setHeader(namespace,"ApplicationToken", appToken);
    stub.setHeader(namespace,"DeveloperToken", devToken);
    stub.setHeader(namespace,"UserCredentials", userCredentials);


    // Create and initialize the keyword performance report request
    // object.
    KeywordPerformanceReportRequest reportRequest =
    new KeywordPerformanceReportRequest();

    // Specify the language of the report.
    reportRequest.setLanguage(ReportLanguage.English);

    // Specify the format of the report.
    reportRequest.setFormat(ReportFormat.Xml);
    reportRequest.setReturnOnlyCompleteData(false);
    reportRequest.setReportName("My Keyword Report");
    reportRequest.setAggregation(ReportAggregation.Daily);

    // Specify the time frame of the report.
    ReportTime reportTime=new ReportTime();
    // reportTime.setPredefinedTime(ReportTimePeriod.LastSixMonths);
    reportTime.setPredefinedTime(null);
    reportTime.setCustomDates(null);
    //reportTime.setCustomDateRangeStart(null);

    reportTime.setCustomDateRangeStart(msnDate);
    reportTime.setCustomDateRangeEnd(null);
    reportRequest.setTime(reportTime);

    // Specify the scope of the report. This example goes
    // only to the account level, but you can request a report
    // for any number of accounts, ad groups, and campaigns.
    AccountThroughAdGroupReportScope scope =
    new AccountThroughAdGroupReportScope();
    scope.setAccountIds(aoi);
    reportRequest.setScope(scope);

    // Specify the filter for the report. The report request
    // in this example specifies only the search ads that were
    // displayed in the United States.
    KeywordPerformanceReportFilter filter =
    new KeywordPerformanceReportFilter();
    String[] adDist = { "Search" };
    filter.setAdDistribution(adDist);
    String[] langAndRegion = { "UnitedStates" };
    filter.setLanguageAndRegion(langAndRegion);
    filter.setDeliveredMatchType(null);
    filter.setKeywords(null);
    reportRequest.setFilter(filter);

    // Specify the columns that will be in the report.
    KeywordPerformanceReportColumn[] columns;
    columns = new KeywordPerformanceReportColumn[6];

    columns[0] = KeywordPerformanceReportColumn.AccountName;
    columns[1] = KeywordPerformanceReportColumn.CampaignName;
    columns[2] = KeywordPerformanceReportColumn.Keyword;
    columns[3] = KeywordPerformanceReportColumn.TimePeriod;
    columns[4] = KeywordPerformanceReportColumn.Impressions;
    columns[5] = KeywordPerformanceReportColumn.Conversions;

    ArrayOfKeywordPerformanceReportColumn aok = new ArrayOfKeywordPerformanceReportColumn();
    aok.setKeywordPerformanceReportColumn(columns);

    reportRequest.setColumns(aok);


    // Create the service operation request object, and assign values.
    queueReportRequest = new QueueReportRequest();
    queueReportRequest.setReportRequest(reportRequest);

    // Make the call to queue the report.
    System.out.println(
    "Calling ReportManagement.QueueReport");
    queueReportResponse =
    reportManagement.queueReport(queueReportRequest);

    // Display the ApiCallTrackingData that was returned in
    // the response header.
    System.out.println("Successful QueueReport call.");
    System.out.println(
    "ApiCallTrackingData output from response header:");
    System.out.println(
    stub.getResponseHeader
    (
    namespace,
    "ApiCallTrackingData")
    );
    System.out.println(); // A blank line to separate the text
    // that follows.

    reportId = queueReportResponse.getReportRequestId();
    System.out.print("ReportRequestId: ");
    System.out.println(reportId);


    // Poll to get the status of the report until it is complete.
    int waitMinutes = 15;
    int maxWaitMinutes = 120;
    int elapsedMinutes = 0;

    do
    {
    // Wait the specified number of minutes before you poll.
    System.out.print(String.format(
    "Waiting another %d minutes. ",
    waitMinutes));
    System.out.println(String.format(
    "Total wait time so far is %d minutes.",
    elapsedMinutes));
    Thread.sleep(waitMinutes * 60 * 1000);
    elapsedMinutes += waitMinutes;

    getReportStatusRequest = new GetReportStatusRequest();
    getReportStatusRequest.setReportRequestId(reportId);

    // Make the call to get the report status.
    System.out.println(
    "Calling ReportManagement.GetReportStatus");
    getReportStatusResponse =
    reportManagement.getReportStatus(getReportStatusRequest);

    // Display the ApiCallTrackingData returned
    // in the response header.
    System.out.println("Successful GetReportStatus call.");
    System.out.println(
    "ApiCallTrackingData output from response header:");
    System.out.println(
    stub.getResponseHeader
    (
    namespace,
    "ApiCallTrackingData")
    );
    System.out.println(); // A blank line to separate the text
    // that follows.


    reportRequestStatus =
    getReportStatusResponse.getReportRequestStatus();

    status = reportRequestStatus.getStatus();

    // If the report was created, download it.
    if (ReportRequestStatusType.Success == status)
    {

    String fileName = null;
    String downloadURLString = null;
    URL downloadUrl = null;
    InputStream inputStream = null;
    FileOutputStream fileOutputStream = null;
    int count = 0;

    fileName = reportId + ".zip";

    // Open a connection to the URL where
    // the report is available.
    downloadURLString =
    reportRequestStatus.getReportDownloadUrl();
    downloadUrl = new URL(downloadURLString);
    inputStream = downloadUrl.openStream();

    // Open the report file.
    fileOutputStream = new FileOutputStream(fileName);

    // Read the report data.
    while (-1 != (count = inputStream.read()))
    {
    // Write the report data to the file.
    fileOutputStream.write(count);
    }

    // Flush and close the file.
    fileOutputStream.flush();
    fileOutputStream.close();

    System.out.println(String.format(
    "The report named %s was successfully downloaded.",
    fileName));
    break;
    }
    else if (ReportRequestStatusType.Pending == status)
    {
    // The report is not yet ready.
    continue;
    }
    else
    {
    // An error occurred.
    throw new Exception(status.toString());
    }

    } while (elapsedMinutes < maxWaitMinutes);

    }

    // Exception handling.

    // Capture adCenter API exceptions.
    catch (ApiFaultDetail fault)
    {
    System.out.println("ApiFaultDetail exception encountered!");
    System.out.println(String.format("Tracking ID: %s",
    fault.getTrackingId()));

    // Display any service operation error information.
    ArrayOfOperationError aoe = fault.getOperationErrors();
    OperationError[] oe = aoe.getOperationError();
    // Display any service operation error information.
    for (int i = 0; i < oe.length; i++){
    System.out.println("Operation error encountered:");
    System.out.println("Error Code: " + oe[i].getCode());
    System.out.println("Error Message: " + oe[i].getMessage());
    }

    // Exit the application or take other action.
    System.exit(-1);
    }

    // Capture exceptions on the client that are unrelated to
    // adCenter API.
    catch (Exception e)
    {
    System.out.print("Error encountered: ");
    e.printStackTrace();
    // Exit the application or take other action.
    System.exit(-1);
    }
    }

    public String getUsername() {
    return username;
    }

    public void setUsername(String username) {
    this.username = username;
    }

    public String getPassword() {
    return password;
    }

    public void setPassword(String password) {
    this.password = password;
    }

    public String getDeveloperToken() {
    return developerToken;
    }

    public void setDeveloperToken(String developerToken) {
    this.developerToken = developerToken;
    }

    public String getApplicationToken() {
    return applicationToken;
    }

    public void setApplicationToken(String applicationToken) {
    this.applicationToken = applicationToken;
    }

    }


    This is the SOAP request generated:
    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
       <soapenv:Header>
          <ns1:ApplicationToken soapenv:actor="http://schemas.xmlsoap.org/soap/actor/next" soapenv:mustUnderstand="0" xmlns:ns1="https://adcenter.microsoft.com/api/advertiser/v5>
          <ns2:DeveloperToken soapenv:actor="http://schemas.xmlsoap.org/soap/actor/next" soapenv:mustUnderstand="0" xmlns:ns2="https://adcenter.microsoft.com/api/advertiser/v5">
             <ns2:Value12345XXX</ns2:Value>
          </ns2:DeveloperToken>
          <ns3:UserCredentials soapenv:actor="http://schemas.xmlsoap.org/soap/actor/next" soapenv:mustUnderstand="0" xmlns:ns3="https://adcenter.microsoft.com/api/advertiser/v5">
             <ns3:Password>pas123</ns3:Password>
             <ns3:Username>CC</ns3:Username>
          </ns3:UserCredentials>
       </soapenv:Header>
       <soapenv:Body>
          <QueueReportRequest xmlns="https://adcenter.microsoft.com/api/advertiser/v5">
             <ReportRequest>
                <Format>Xml</Format>
                <Language>English</Language>
                <ReportName>My Keyword Report</ReportName>
                <ReturnOnlyCompleteData>false</ReturnOnlyCompleteData>
             </ReportRequest>
          </QueueReportRequest>
       </soapenv:Body>
    </soapenv:Envelope>

    Below is the error message stack trace:
    Error encountered: AxisFault
    faultCode: {http://schemas.microsoft.com/net/2005/12/windowscommunicationfoundation/dispatcher}InternalServiceFault
    faultSubcode:
    faultString: Cannot create an abstract class.
    faultActor:
    faultNode:
    faultDetail:
    {http://schemas.datacontract.org/2004/07/System.ServiceModel}ExceptionDetail:<HelpLink i:nil="true"/><InnerException i:nil="true"/><Message>Cannot create an abstract class.</Message><StackTrace> at System.Runtime.Serialization.FormatterServices.nativeGetUninitializedObject(RuntimeType type)
    at System.Runtime.Serialization.FormatterServices.GetUninitializedObject(Type type)
    at ReadReportRequestFromXml(XmlReaderDelegator , XmlObjectSerializerReadContext , XmlDictionaryString[] , XmlDictionaryString[] )
    at System.Runtime.Serialization.ClassDataContract.ReadXmlValue(XmlReaderDelegator xmlReader, XmlObjectSerializerReadContext context)
    at System.Runtime.Serialization.XmlObjectSerializerReadContext.InternalDeserialize(XmlReaderDelegator reader, String name, String ns, DataContract&amp; dataContract)
    at System.Runtime.Serialization.XmlObjectSerializerReadContext.InternalDeserialize(XmlReaderDelegator xmlReader, Type declaredType, DataContract dataContract, String name, String ns)
    at System.Runtime.Serialization.DataContractSerializer.InternalReadObject(XmlReaderDelegator xmlReader, Boolean verifyObjectName)
    at System.Runtime.Serialization.XmlObjectSerializer.ReadObjectHandleExceptions(XmlReaderDelegator reader, Boolean verifyObjectName)
    at System.Runtime.Serialization.DataContractSerializer.ReadObject(XmlDictionaryReader reader, Boolean verifyObjectName)
    at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.DeserializeParameterPart(XmlDictionaryReader reader, PartInfo part, Boolean isRequest)
    at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.DeserializeParameter(XmlDictionaryReader reader, PartInfo part, Boolean isRequest)
    at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.DeserializeParameters(XmlDictionaryReader reader, PartInfo[] parts, Object[] parameters, Boolean isRequest)
    at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.DeserializeBody(XmlDictionaryReader reader, MessageVersion version, String action, MessageDescription messageDescription, Object[] parameters, Boolean isRequest)
    at System.ServiceModel.Dispatcher.OperationFormatter.DeserializeBodyContents(Message message, Object[] parameters, Boolean isRequest)
    at System.ServiceModel.Dispatcher.OperationFormatter.DeserializeRequest(Message message, Object[] parameters)
    at System.ServiceModel.Dispatcher.DispatchOperationRuntime.DeserializeInputs(MessageRpc&amp; rpc)
    at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc&amp; rpc)
    at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc&amp; rpc)
    at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc&amp; rpc)
    at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage3(MessageRpc&amp; rpc)
    at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage2(MessageRpc&amp; rpc)
    at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage1(MessageRpc&amp; rpc)
    at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)</StackTrace><Type>System.MemberAccessException</Type>

    Cannot create an abstract class.
    at org.apache.axis.message.SOAPFaultBuilder.createFault(SOAPFaultBuilder.java:222)
    at org.apache.axis.message.SOAPFaultBuilder.endElement(SOAPFaultBuilder.java:129)
    at org.apache.axis.encoding.DeserializationContext.endElement(DeserializationContext.java:1087)
    at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source)
    at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanEndElement(Unknown Source)
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
    at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
    at javax.xml.parsers.SAXParser.parse(SAXParser.java:375)
    at org.apache.axis.encoding.DeserializationContext.parse(DeserializationContext.java:227)
    at org.apache.axis.SOAPPart.getAsSOAPEnvelope(SOAPPart.java:696)
    at org.apache.axis.Message.getSOAPEnvelope(Message.java:435)
    at org.apache.axis.handlers.soap.MustUnderstandChecker.invoke(MustUnderstandChecker.java:62)
    at org.apache.axis.client.AxisClient.invoke(AxisClient.java:206)
    at org.apache.axis.client.Call.invokeEngine(Call.java:2784)
    at org.apache.axis.client.Call.invoke(Call.java:2767)
    at org.apache.axis.client.Call.invoke(Call.java:2443)
    at org.apache.axis.client.Call.invoke(Call.java:2366)
    at org.apache.axis.client.Call.invoke(Call.java:1812)
    at com.microsoft.adcenter.api.advertiser.v5.BasicHttpBinding_IReportingServiceStub.queueReport(BasicHttpBinding_IReportingServiceStub.java:810)
    at com.roving.search.campaign.dto.MSNSearchEngineCampaign.process(MSNSearchEngineCampaign.java:199)
    at com.roving.search.campaign.client.CampaignDataDriver.main(CampaignDataDriver.java:27)

    Friday, March 6, 2009 7:43 PM

Answers

  • Hi,

    It sounds like you were able to resolve this issue with the assistance from adSupport.

    Jeff Dillon, API Support
    Tuesday, March 10, 2009 12:49 AM