<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<Request xmlns="https://example.com"> <!-- We have xmlns here which is a good thing -->
<filter>
<SomeParameter>SomeValue</SomeParameter> <!-- Note the lack of xmlns="TestNamespace" Here -->
<SomeNestedParameter> <!-- And Here -->
<SomeInnerParameter>InnerValue</SomeInnerParameter>
</SomeNestedParameter>
</filter>
</Request>
</soap:Body>
</soap:Envelope>
The generated code looks like
type Request struct {
XMLName xml.Name `xml:"https://example.com Request"`
// I believe this parameter is used to add
// xmlns="https://example.com"
// to the request which is the same as zeep response
Filter *Filter `xml:"filter,omitempty" json:"filter,omitempty"`
}
type Response struct {
XMLName xml.Name `xml:"https://example.com Response"`
Message *string `xml:"Message,omitempty" json:"Message,omitempty"`
}
type Filter struct {
SomeParameter *string `xml:"SomeParameter,omitempty" json:"SomeParameter,omitempty"`
// (see challenge 1)
SomeNestedParameter *NestedType `xml:"SomeNestedParameter,omitempty" json:"SomeNestedParameter,omitempty"`
}
type NestedType struct {
// Here we also need something like
// XMLName xml.Name `xml:"TestNamespace SomeNestedParameter"`
// but it is not generated (see challenge 2)
SomeInnerParameter *string `xml:"SomeInnerParameter,omitempty" json:"SomeInnerParameter,omitempty"`
}
Challenges
The method used to add xmlns attribute does not work for a primitive (non-struct) types. But there is this workaround:
type Filter struct {
SomeParameter *SomeParameter `xml:"SomeParameter,omitempty" json:"SomeParameter,omitempty"`
// (see challenge 1)
SomeNestedParameter *NestedType `xml:"SomeNestedParameter,omitempty" json:"SomeNestedParameter,omitempty"`
}
type SomeParameter struct {
XMLName xml.Name xml:"TestNamespace SomeParameter"
Value string `xml:",chardata"` // <- Note here we make it to become the root value of the containing node
}
2. The second challenge is that we need to include the name of this type in the parent parameter inside the type definition which is impossible since these struct types may be reused in multiple messages with different names.
Assume we have the following wsdl:
Using zeep in python I can generate a valid request:
The result is
But using gowsdl I cannot.
With the following we can see the generated xml
Which is
The generated code looks like
Challenges
The method used to add
xmlns
attribute does not work for a primitive (non-struct) types. But there is this workaround:type SomeParameter struct { XMLName xml.Name
xml:"TestNamespace SomeParameter"
}