rad8-splashscreen

RAD Communicating with an External WebService

We will try to incorporate and use VIES Check-VAT WebService within RAD/Eclipse.

  • Download the .WSDL from here
  • Right click on the “WebSphereCommereServerExtensionsData” folder and select New > Folder. I have named it “WebService”.
    Image1
  • Now copy the downloaded WebService into this folder.
  • Now right click on the “checkVATService.wsdl” file and select: Web Services > Generate Client.
    Image2
  • Click on “Next” to proceed.
    Image3
  • Provide a name for the target package and click “Finish”.
    Image4
  • Once the client is generated, the files we can play around with are displayed as below:
    Image5
  • Now incorporate the following code in any command to make the WebService call.
public String checkVatAppox(String strFullVatNumber) {
    String strIsValid = "false";
    String strReferenceReq = "";
    try {
        CheckVatPortProxy proxy = new CheckVatPortProxy();
        CheckVatApprox vatParameters = new CheckVatApprox();
        CheckVatApproxResponse responseData = new CheckVatApproxResponse();

        // Removing blank spaces
        strFullVatNumber = strFullVatNumber.replaceAll(" ", "");
        Holder<String> hCountryCode = new Holder(strFullVatNumber.substring(0, 2));
        Holder<String> hVatNumber = new Holder(strFullVatNumber.substring(2, strFullVatNumber.length()));
        Holder<String> hTraderName = new Holder();
        Holder<String> hTraderCompanyType = new Holder();
        Holder<String> hTraderStreet = new Holder();
        Holder<String> hTraderPostcode = new Holder();
        Holder<String> hTraderCity = new Holder();
        String strRequesterCountryCode = "GB";
        String strRequesterVatNumber = "155442220";
        Holder<XMLGregorianCalendar> hRequestDate = new Holder();
        Holder<Boolean> hValid = new Holder();
        Holder<String> hTraderAddress = new Holder();
        Holder<String> hTraderNameMatch = new Holder();
        Holder<String> hTraderCompanyTypeMatch = new Holder();
        Holder<String> hTraderStreetMatch = new Holder();
        Holder<String> hTraderPostcodeMatch = new Holder();
        Holder<String> hTraderCityMatch = new Holder();
        Holder<String> hRequestIdentifier = new Holder();

        proxy.checkVatApprox(hCountryCode, hVatNumber, hTraderName, hTraderCompanyType, 
                             hTraderStreet, hTraderPostcode, hTraderCity, 
                             strRequesterCountryCode, strRequesterVatNumber, hRequestDate, 
                             hValid, hTraderAddress, hTraderNameMatch, hTraderCompanyTypeMatch, 
                             hTraderStreetMatch, hTraderPostcodeMatch, hTraderCityMatch, 
                             hRequestIdentifier);

        LOGGER.info("VAT: " + hCountryCode.value + " - " + hVatNumber.value + " - " + hValid.value + 
                          " - " + hRequestDate.value + " - " + hRequestIdentifier.value);                        
        strIsValid = hValid.value.toString();
        strReferenceReq = hRequestIdentifier.value;
    } catch (Exception e) {
        strIsValid = "Offline";
        LOGGER.info("Cannot validate VAT right now as the server is busy...");
    }
    return strIsValid + "<>" + strReferenceReq;
}


There are no comments

Add yours

This site uses Akismet to reduce spam. Learn how your comment data is processed.