I am using gowsdl
to consume a SOAP
request in Go. I got WSDL
and generated the code using that. In the auto-generated code, it generated stub and some code snippets are mentioned below.
I have to make a SOAP
call and have to pass GetAllPersons struct
as an input to the service. Please help me how do we do that? I have the request xml
but dont know how to update that in GetAllPersons struct
?
persons, err := service.GetAllPersons(request)
type GetAllPersons struct {
XMLName xml.Name `xml:"http://service.jaxws.journaldev.com getAllPersons"`
}
And as per Go specification, a variable is declared using the sybtax VariableName Type
. What is the 3rd value xml:"http://service.jaxws.journaldev.com getAllPersons"
in above struct
?
Below is the code that I figured out to get things done with the code generated by gowsdl
.
main(){
basicauth := personService.BasicAuth{"",""}
service := personService.NewPersonServiceImpl("", false, &basicauth)
persons, err := service.GetAllPersons(&personService.GetAllPersons{})
if err != nil {
panic(err)
}
fmt.Println(persons)
fmt.Printf("Alive?: %t
", persons.GetAllPersonsReturn[0].Name)
fmt.Printf("Alive?: %t
", persons.GetAllPersonsReturn[1].Name)
fmt.Printf("Alive?: %t
", persons.GetAllPersonsReturn[0].Id)
fmt.Printf("Alive?: %t
", persons.GetAllPersonsReturn[1].Id)
fmt.Printf("Alive?: %t
", persons.GetAllPersonsReturn[0].Age)
fmt.Printf("Alive?: %t
", persons.GetAllPersonsReturn[1].Age)
fmt.Printf(persons.GetAllPersonsReturn[0].Name)
request := &personService.AddPerson{P: &personService.Person{Age: 24, Name: "Govinda", Id: 55555555}}
trial, err := service.AddPerson(request)
if err != nil {
panic(err)
}
}
For the 2nd question, thanks to Volker for mentioning the answer in comments. These strings after the type are called tags (see golang.org/ref/spec#Struct_types) and are used typically during (un)marshalling from serialisation formats like xml