RAD Communicating with an External WebService

As we delve into the world of web services, discover how to seamlessly integrate the VIES Check-VAT WebService into your RAD/Eclipse environment, unlocking a world of streamlined VAT verification and validation. With a few simple steps, you can harness the power of this external web service to elevate your development capabilities. By following this straightforward guide, you'll be well on your way to mastering the art of web service integration and revolutionizing your workflow.

Akhil Pathania · 15 October 2013 · 2 min read · 13 views
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;
}
Share X WhatsApp
Leave a Comment

Moderated — may take a moment to appear.

You Might Also Like