Hacking a SOAP call - Checking a EU VAT number

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Hacking a SOAP call - Checking a EU VAT number

Sven Van Caekenberghe-2
We have no SOAP implementation in Pharo (yet). But that does not mean we cannot do simple SOAP calls. Here is a practical example: checking the validity of a EU VAT number.

This is a public service offered by the EU through a SOAP API. The WSDL can be found here: http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl

From this we know that the endpoint is http://ec.europa.eu/taxation_customs/vies/services/checkVatService

When you paste the WSDL URL in http://wsdlbrowser.com you can explore the API (this site parses the WSDL to reveal its contents). The call that we need is called 'checkVat'. We can copy the call template and POST it to the endpoint, manually. If we load the XML Parser, we can interpret the result.

Here is the complete code:

| xml result |
xml := ZnEntity
        with: (
'<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:ec.europa.eu:taxud:vies:services:checkVat:types">
  <SOAP-ENV:Body>
    <ns1:checkVat>
      <ns1:countryCode>{1}</ns1:countryCode>
      <ns1:vatNumber>{2}</ns1:vatNumber>
    </ns1:checkVat>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>' format: #('LU' '20165772'))
        type: ZnMimeType applicationXml.
result := ZnClient new
        url: 'http://ec.europa.eu/taxation_customs/vies/services/checkVatService'; 
        entity: xml;
        contentReader: [ :entity | XMLDOMParser parse: entity contents ];
        post.
((result allElementsNamed: 'checkVatResponse') first
        elementsCollect: [ :each | each name -> each contentString ]) asDictionary.

=>

a Dictionary(
  'address'->'31, RUE STE ZITHE L-2763  LUXEMBOURG'
  'countryCode'->'LU'
  'name'->'ITUNES S.A R.L.'
  'requestDate'->'2015-03-03+01:00'
  'valid'->'true'
  'vatNumber'->'20165772' )

Of course, this will only work with simple SOAP interfaces.

Sven

--
Sven Van Caekenberghe
Proudly supporting Pharo
http://pharo.org
http://association.pharo.org
http://consortium.pharo.org





Reply | Threaded
Open this post in threaded view
|

Re: Hacking a SOAP call - Checking a EU VAT number

NorbertHartl
Sven,

that use case was one reason to implement mustache. I use it to generate SOAP calls from templates. As Mustache can have nested objects in processing you could even have more complex SOAP calls. Although complex/nested SOAP calls are far from being a good idea.

Norbert


> Am 03.03.2015 um 00:12 schrieb Sven Van Caekenberghe <[hidden email]>:
>
> We have no SOAP implementation in Pharo (yet). But that does not mean we cannot do simple SOAP calls. Here is a practical example: checking the validity of a EU VAT number.
>
> This is a public service offered by the EU through a SOAP API. The WSDL can be found here: http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl
>
> From this we know that the endpoint is http://ec.europa.eu/taxation_customs/vies/services/checkVatService
>
> When you paste the WSDL URL in http://wsdlbrowser.com you can explore the API (this site parses the WSDL to reveal its contents). The call that we need is called 'checkVat'. We can copy the call template and POST it to the endpoint, manually. If we load the XML Parser, we can interpret the result.
>
> Here is the complete code:
>
> | xml result |
> xml := ZnEntity
>    with: (
> '<?xml version="1.0" encoding="UTF-8"?>
> <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:ec.europa.eu:taxud:vies:services:checkVat:types">
>  <SOAP-ENV:Body>
>    <ns1:checkVat>
>      <ns1:countryCode>{1}</ns1:countryCode>
>      <ns1:vatNumber>{2}</ns1:vatNumber>
>    </ns1:checkVat>
>  </SOAP-ENV:Body>
> </SOAP-ENV:Envelope>' format: #('LU' '20165772'))
>    type: ZnMimeType applicationXml.
> result := ZnClient new
>    url: 'http://ec.europa.eu/taxation_customs/vies/services/checkVatService'; 
>    entity: xml;
>    contentReader: [ :entity | XMLDOMParser parse: entity contents ];
>    post.
> ((result allElementsNamed: 'checkVatResponse') first
>    elementsCollect: [ :each | each name -> each contentString ]) asDictionary.
>
> =>
>
> a Dictionary(
>  'address'->'31, RUE STE ZITHE L-2763  LUXEMBOURG'
>  'countryCode'->'LU'
>  'name'->'ITUNES S.A R.L.'
>  'requestDate'->'2015-03-03+01:00'
>  'valid'->'true'
>  'vatNumber'->'20165772' )
>
> Of course, this will only work with simple SOAP interfaces.
>
> Sven
>
> --
> Sven Van Caekenberghe
> Proudly supporting Pharo
> http://pharo.org
> http://association.pharo.org
> http://consortium.pharo.org
>
>
>
>
>