gowsdl icon indicating copy to clipboard operation
gowsdl copied to clipboard

How to remove tag Headers in <soap:Header>

Open bolatik opened this issue 3 years ago • 2 comments

<soap:Envelope> <soap:Header> <Headers><userId>1111111111</userId></Headers> </soap:Header> <soap:Body><test></test></soap:Body> </soap:Envelope>

Hello! how to remove the <Headers> tag from soap:Header? I want to make such a request <soap:Envelope> <soap:Header> <userId>1111111111</userId> </soap:Header> <soap:Body><test></test></soap:Body> </soap:Envelope>

bolatik avatar Aug 14 '21 14:08 bolatik

You can try using version 0.4.0. I have the same problem that the implementation has changed regarding headers from v0.4.0 -> v0.5.0. For me it works in v0.4.0 :)

mahe54 avatar Sep 21 '21 09:09 mahe54

From the encoding/xml documentation https://pkg.go.dev/encoding/xml#Marshal

a field with tag ",chardata" is written as character data, not as an XML element. ... an anonymous struct field is handled as if the fields of its value were part of the outer struct.

Using an anonymous struct field and having a tag xml:",chardata" like below should marshal into the desired XML

userId := struct {
  XMLName xml.Name
  UserId  string `xml:",chardata"`
} {
  XMLName: xml.Name{Local: "UserId"},
  UserId:  "1111111111"
}

soapClient.SetHeaders(userId)

Hope this helps :-)

JonLally avatar Jul 22 '22 13:07 JonLally