I have an XML file that has a bunch of types/functions that look like this:
<wsdl:definitions targetNamespace="Namespace">
<wsdl:types>
<xs:schema targetNamespace="Namespace">
<xs:complexType name="ArrayOfString">
<xs:sequence>
<xs:element name="stringItem" type="xs:string" minOccurs="0" maxOccurs="unbounded" nillable="false"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="Tag">
<xs:sequence>
<xs:element name="type" type="xs:string" minOccurs="0" maxOccurs="1" nillable="false"/>
<xs:element name="values" type="tns:ArrayOfString" minOccurs="0" maxOccurs="1" nillable="false"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="ArrayOfTag">
<xs:sequence>
<xs:element name="tag" type="tns:Tag" minOccurs="0" maxOccurs="unbounded" nillable="false"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="ParamsGetTags">
<xs:sequence>
<xs:element name="tagList" type="tns:ArrayOfTag" minOccurs="0" maxOccurs="1" nillable="false"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="ResultGetTags">
<xs:sequence>
<xs:element name="tagList" type="tns:ArrayOfTag" minOccurs="1" maxOccurs="1" nillable="false"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="SuccessGetTags">
<xs:sequence>
<xs:element name="result" type="tns:ResultGetTags" minOccurs="1" maxOccurs="1"/>
</xs:sequence>
</xs:complexType>
<xs:element name="paramsGetTags" type="tns:ParamsGetTags"/>
<xs:element name="successGetTags" type="tns:SuccessGetTags"/>
</xs:schema>
</wsdl:types>
<wsdl:message name="GetTagsRequest">
<wsdl:part name="paramsGetTags" element="tns:paramsGetTags"/>
</wsdl:message>
<wsdl:message name="GetTagsResponse">
<wsdl:part name="successGetTags" element="tns:successGetTags"/>
</wsdl:message>
<wsdl:portType name="NPort">
<wsdl:operation name="getTags">
<wsdl:documentation>Get Tags
</wsdl:documentation>
<wsdl:input message="tns:GetTagsRequest"/>
<wsdl:output message="tns:GetTagsResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="NApiSoapBinding" type="tns:NPort">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="getTags">
<soap:operation soapAction="example.com/N/getTags" />
<wsdl:input>
<soap:header use="literal" part="authentication" message="tns:AuthenticationHeader" />
<soap:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
</wsdl:definitions>
I've included all the definitions (e.g. of ArrayOfTags) for completeness, and since it allows the example above to be complete/testable.
It wasn't working for me, and when I looked more closely, I was eventually able to uncovere the problem.
There are two issues:
The first is that there are too many type annotations all over the place, so I end up with structs that won't encode.
Things like:
type ArrayOfTag struct {
XMLName xml.Name `xml:"http://url ArrayOfTag"`
Tag []*Tag `xml:"tag,omitempty"`
}
type ParamsGetTags struct {
XMLName xml.Name `xml:"http://url ParamsGetTags"`
TagList *ArrayOfTag `xml:"tagList,omitempty"`
}
Result in errors of the form
err xml: name "tagList" in tag of soap.ParamsGetTags.TagList conflicts with name "ArrayOfTag" in *soap.ArrayOfTag.XMLName
These are all over the place, and require removing copious xmlNames in order to get my code to run.
The second issue is that <xs:element name="paramsGetTags" type="tns:ParamsGetTags"/>
should override the "name" on the complex type <xs:complexType name="ParamsGetTags">
. The generated struct is (as above)
type ParamsGetTags struct {
XMLName xml.Name `xml:"http://url ParamsGetTags"`
TagList *ArrayOfTag `xml:"tagList,omitempty"`
}
but it fails when the element name is ParamsGetTags
. If I change it to paramsGetTags
, it works correctly (assuming I've fixed the first issue as well).
Is there an easy fix you recommend for these? I can dig into some of the code generation, but nothing jumped at me as an easy way to look up if there's a simple element with that type, and I didn't want to build out a hacky solution if there was something you felt was more appropriate.
Let me know what you think.
I'm really looking forward to using this library to make my dealing with SOAP in Go much more bearable. I'm so close I can taste it, I just have to get over the finish line. :)
Thanks!