Monday, December 9, 2013

Use the WSDL2Java to build Bing Ads API proxy library

I worked out a Windows batch script to generate and build the Bing Ads API client library conveniently, please check it out.

For Bing Ads API V8:

wsdl2java-v8.bat
@echo off
echo Notes:
echo Download and unzip axis-bin-1_4.zip, put this wsdl2java.bat to axis-1_4\lib and run it.
echo A jar file adcenter-v8.jar would be generated if all good, please use it in your app.
echo mail.jar and activiation.jar are optional, not required here.

echo -----------------------
echo Converting Ad Intelligence Service...
java -cp .;* org.apache.axis.wsdl.WSDL2Java -a https://adcenterapi.microsoft.com/Api/Advertiser/v8/CampaignManagement/AdIntelligenceService.svc?wsdl

echo Converting Bulk Service...
java -cp .;* org.apache.axis.wsdl.WSDL2Java -a https://adcenterapi.microsoft.com/Api/Advertiser/v8/CampaignManagement/BulkService.svc?wsdl 

echo Converting Campaign Management Service...
java -cp .;* org.apache.axis.wsdl.WSDL2Java -a https://adcenterapi.microsoft.com/Api/Advertiser/v8/CampaignManagement/CampaignManagementService.svc?wsdl

echo Converting Customer Billing Service...
java -cp .;* org.apache.axis.wsdl.WSDL2Java -a https://sharedservices.adcenterapi.microsoft.com/Api/Billing/v8/CustomerBillingService.svc?wsdl 

echo Converting Customer Management...
java -cp .;* org.apache.axis.wsdl.WSDL2Java -a https://sharedservices.adcenterapi.microsoft.com/Api/CustomerManagement/v8/CustomerManagementService.svc?wsdl

echo Converting Notification Service...
java -cp .;* org.apache.axis.wsdl.WSDL2Java -a https://sharedservices.adcenterapi.microsoft.com/Api/Notification/v8/NotificationService.svc?wsdl

echo Converting Optimizer Service...
java -cp .;* org.apache.axis.wsdl.WSDL2Java -a https://adcenterapi.microsoft.com/Api/Advertiser/v8/Optimizer/OptimizerService.svc?wsdl 

echo Converting Reporting Service...
java -cp .;* org.apache.axis.wsdl.WSDL2Java -a https://adcenterapi.microsoft.com/Api/Advertiser/v8/Reporting/ReportingService.svc?wsdl

echo Compiling java source code...
javac -cp .;* -encoding UTF-8 com/microsoft/adapi/*.java
javac -cp .;* -encoding UTF-8 com/microsoft/adcenter/v8/*.java
javac -cp .;* -encoding UTF-8 com/microsoft/adcenter/api/customerbilling/*.java
javac -cp .;* -encoding UTF-8 com/microsoft/adcenter/api/customermanagement/Entities/*.java
javac -cp .;* -encoding UTF-8 com/microsoft/adcenter/api/customermanagement/Exception/*.java
javac -cp .;* -encoding UTF-8 com/microsoft/adcenter/api/customermanagement/*.java
javac -cp .;* -encoding UTF-8 com/microsoft/adcenter/api/notifications/Entities/*.java
javac -cp .;* -encoding UTF-8 com/microsoft/adcenter/api/notifications/*.java
javac -cp .;* -encoding UTF-8 org/datacontract/schemas/_2004/_07/Microsoft_AdCenter_Advertiser_CampaignManagement_Api_DataContracts/*.java
javac -cp .;* -encoding UTF-8 org/datacontract/schemas/_2004/_07/Microsoft_AdCenter_Advertiser_Optimizer_Api_DataContracts/*.java
javac -cp .;* -encoding UTF-8 org/datacontract/schemas/_2004/_07/Microsoft_AdCenter_Advertiser_Optimizer_Api_DataContracts_Entities/*.java
javac -cp .;* -encoding UTF-8 org/datacontract/schemas/_2004/_07/Microsoft_AdCenter_Shared_Api/*.java

echo Creating jar file adcenter-v8.jar...
jar cf adcenter-v8.jar com/microsoft/* org/datacontract/*

echo WSDL2Java V8 Converting completed!

echo Use following command to add to your maven repository
echo mvn install:install-file -Dfile=adcenter-v8.jar -DgroupId=com.microsoft -DartifactId=adcenter -Dversion=v8 -Dpackaging=jar
For Bing Ads API V9, We need 2 steps as we have to fix something before compiling:

wsdl2java-v9-step1.bat
@echo off
echo Running The Step 1......
echo Notes:
echo Download and unzip axis-bin-1_4.zip, put this wsdl2java.bat to axis-1_4\lib and run it.
echo A jar file bingads-v9.jar would be generated if all good, please use it in your app.
echo mail.jar and activiation.jar are optional, not required here.

echo -----------------------
echo Converting Ad Intelligence Service...
java -cp .;* org.apache.axis.wsdl.WSDL2Java -a https://api.bingads.microsoft.com/Api/Advertiser/AdIntelligence/v9/AdIntelligenceService.svc?wsdl

echo Converting Bulk Service...
java -cp .;* org.apache.axis.wsdl.WSDL2Java -a https://api.bingads.microsoft.com/Api/Advertiser/CampaignManagement/v9/BulkService.svc?wsdl 

echo Converting Campaign Management Service...
java -cp .;* org.apache.axis.wsdl.WSDL2Java -a https://api.bingads.microsoft.com/Api/Advertiser/CampaignManagement/v9/CampaignManagementService.svc?wsdl

echo Converting Customer Billing Service...
java -cp .;* org.apache.axis.wsdl.WSDL2Java -a https://clientcenter.api.bingads.microsoft.com/Api/Billing/v9/CustomerBillingService.svc?wsdl 

echo Converting Customer Management...
java -cp .;* org.apache.axis.wsdl.WSDL2Java -a https://clientcenter.api.bingads.microsoft.com/Api/CustomerManagement/v9/CustomerManagementService.svc?wsdl

echo Converting Optimizer Service...
java -cp .;* org.apache.axis.wsdl.WSDL2Java -a https://api.bingads.microsoft.com/Api/Advertiser/Optimizer/v9/OptimizerService.svc?wsdl 

echo Converting Reporting Service...
java -cp .;* org.apache.axis.wsdl.WSDL2Java -a https://api.bingads.microsoft.com/Api/Advertiser/Reporting/v9/ReportingService.svc?wsdl

echo Please change long[] to Long[] within the following java files to fix the ArrayOfNullableOflong issue, then run The Step 2:
echo 1. AddAdsResponse.java
echo 2. AddKeywordsResponse.java

wsdl2java-v9-step2.bat
@echo off
echo Running The Step 2......

echo Compiling java source code...
javac -cp .;* -encoding UTF-8 com/microsoft/adapi/*.java
javac -cp .;* -encoding UTF-8 com/microsoft/bingads/AdIntelligence/v9/*.java
javac -cp .;* -encoding UTF-8 com/microsoft/bingads/Billing/v9/*.java
javac -cp .;* -encoding UTF-8 com/microsoft/bingads/CampaignManagement/v9/*.java
javac -cp .;* -encoding UTF-8 com/microsoft/bingads/Customer/v9/*.java
javac -cp .;* -encoding UTF-8 com/microsoft/bingads/Customer/v9/Entities/*.java
javac -cp .;* -encoding UTF-8 com/microsoft/bingads/Customer/v9/Exception/*.java
javac -cp .;* -encoding UTF-8 com/microsoft/bingads/Optimizer/v9/*.java
javac -cp .;* -encoding UTF-8 com/microsoft/bingads/Reporting/v9/*.java
javac -cp .;* -encoding UTF-8 org/datacontract/schemas/_2004/_07/Microsoft_BingAds_Advertiser_CampaignManagement_Api_DataContracts/*.java
javac -cp .;* -encoding UTF-8 org/datacontract/schemas/_2004/_07/Microsoft_BingAds_Advertiser_Optimizer_Api_DataContracts/*.java
javac -cp .;* -encoding UTF-8 org/datacontract/schemas/_2004/_07/Microsoft_BingAds_Advertiser_Optimizer_Api_DataContracts_Entities/*.java
javac -cp .;* -encoding UTF-8 org/datacontract/schemas/_2004/_07/System_Collections_Generic/*.java

echo Creating jar file bingads-v9.jar...
jar cf bingads-v9.jar com/microsoft/* org/datacontract/*

echo WSDL2Java BingAds API V9 Converting completed!

echo Use following command to add to the maven repository
echo mvn install:install-file -Dfile=bingads-v9.jar -DgroupId=com.microsoft -DartifactId=bingads -Dversion=v9 -Dpackaging=jar