In this task, the goal is to create a SOAP client which accesses functions defined at http://example.com/soap/wsdl, and calls the functions soapFunc( ) and anotherSoapFunc( ).

This task has been flagged for clarification. Code on this page in its current state may be flagged incorrect once this task has been clarified. See this page's Talk page for discussion.


package main
 
import (
    "fmt"
    "github.com/tiaguinho/gosoap"
    "log"
)
 
type CheckVatResponse struct {
    CountryCode string `xml:"countryCode"`
    VatNumber   string `xml:"vatNumber"`
    RequestDate string `xml:"requestDate"`
    Valid       string `xml:"valid"`
    Name        string `xml:"name"`
    Address     string `xml:"address"`
}
 
var (
    rv CheckVatResponse
)
 
func check(err error) {
    if err != nil {
        log.Fatal(err)
    }
}
 
func main() {
    // create SOAP client
    soap, err := gosoap.SoapClient("http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl")
 
    // map parameter names to values
    params := gosoap.Params{
        "vatNumber":   "6388047V",
        "countryCode": "IE",
    }
 
    // call 'checkVat' function
    err = soap.Call("checkVat", params)
    check(err)
 
    // unmarshal response to 'rv'
    err = soap.Unmarshal(&rv)
    check(err)
 
    // print response
    fmt.Println("Country Code  : ", rv.CountryCode)
    fmt.Println("Vat Number    : ", rv.VatNumber)
    fmt.Println("Request Date  : ", rv.RequestDate)
    fmt.Println("Valid         : ", rv.Valid)
    fmt.Println("Name          : ", rv.Name)
    fmt.Println("Address       : ", rv.Address)
}