hooklift / gowsdl

WSDL2Go code generation as well as its SOAP proxy
Mozilla Public License 2.0
1.16k stars 393 forks source link

Errors with EU VAT Validation service #30

Closed trapias closed 5 years ago

trapias commented 9 years ago

Hello, I generated a service to access the EU VIES web service (EU VAT Validation service) from the wsdl at http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl: service appears to be correctly generated, but when I try to use it I get the error:

expected element type <Envelope> but have <definitions>

The function with which I use the generated service is very simple and should be ok:

func VerifyVAT(vat string, countrycode string) error {
    var data vies.CheckVat
    data.VatNumber = vat
    data.CountryCode = countrycode

    svc := vies.NewCheckVatPortType("http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl", false)
    resp, err := svc.CheckVat(&data)
    if err != nil {
        fmt.Printf("Error: %v\n", err)
    }
    fmt.Printf("RESULT: %v", resp)

    return nil
}

Am I missing something, or is it the generator failing with this wsdl?

trapias commented 9 years ago

Argh, I was giving the wrong endpoint, it should be:

svc := vies.NewCheckVatPortType("http://ec.europa.eu/taxation_customs/vies/services/checkVatService", false)

But now I get another error:

Unexpected wrapper element {urn:ec.europa.eu:taxud:vies:services:checkVat}checkVat found.   Expected {urn:ec.europa.eu:taxud:vies:services:checkVat:types}checkVat.

Is this a fault of mine?

trapias commented 9 years ago

Not wonderful, but I managed to get my service working by manually modifying a local copy of the WSDL (targetNamespace and impl, and converted dates from time.Time to string).

I anyway would like to understand if there was a better way to solve ;-)

c4milo commented 9 years ago

@trapias, I'm sorry you had problems, can you please paste a diff of the changes you did?

trapias commented 9 years ago

@c4milo looks like there's something wrong in the WSDL, I'm trying to ask the support service. Anyway here's what I modified:

Original WSDL:

<wsdl:definitions targetNamespace="urn:ec.europa.eu:taxud:vies:services:checkVat" xmlns:tns1="urn:ec.europa.eu:taxud:vies:services:checkVat:types" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:impl="urn:ec.europa.eu:taxud:vies:services:checkVat" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/">

Modified WSDL:

<wsdl:definitions targetNamespace="urn:ec.europa.eu:taxud:vies:services:checkVat:types" xmlns:tns1="urn:ec.europa.eu:taxud:vies:services:checkVat:types" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:impl="urn:ec.europa.eu:taxud:vies:services:checkVat:types" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/">

After regenerating my service class with gowsdl I also had to change a time.Time field to a string because of a parsing error. Change is:

Original:

RequestDate time.Time `xml:"requestDate,omitempty"`

Modified:

RequestDate string `xml:"requestDate,omitempty"`

both in CheckVatResponse and CheckVatApproxResponse structs. BTW the latter struct is not properly filled-in by calling the CheckVatApprox() method, but this is of course due to the VIES service itself. Will comment here if I ever get any answer from them!

Thank you, al.

c4milo commented 9 years ago

@trapias Can you please fill out another issue with the parsing errors when using time.Time? I would like to look into that later. Thanks for the detailed information!

trapias commented 9 years ago

@c4milo see issue #31 - looks like it's a nasty datetime value given by the VIES service!

    RequestDate:2015-08-05+02:00