Skip to content

Commit

Permalink
Extend encoder capabilities for basic rpc support
Browse files Browse the repository at this point in the history
This fixes some issues with wsdl2go. Namely this does the following:
- Allows zero-parameter functions
- Allows functions with more than one parameter to work
- Allow correct sending of RPC style requests
  • Loading branch information
kernle32dll committed Dec 27, 2017
1 parent 23f46cc commit 4a7bcbb
Show file tree
Hide file tree
Showing 10 changed files with 618 additions and 182 deletions.
24 changes: 15 additions & 9 deletions soap/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type AuthHeader struct {
type Client struct {
URL string // URL of the server
Namespace string // SOAP Namespace
ThisNamespace string // SOAP This-Namespace (tns)
ExcludeActionNamespace bool // Include Namespace to SOAP Action header
Envelope string // Optional SOAP Envelope
Header Header // Optional SOAP Header
Expand Down Expand Up @@ -93,9 +94,10 @@ func doRoundTrip(c *Client, setHeaders func(*http.Request), in, out Message) err
req := &Envelope{
EnvelopeAttr: c.Envelope,
NSAttr: c.Namespace,
TNSAttr: c.ThisNamespace,
XSIAttr: XSINamespace,
Header: c.Header,
Body: Body{Message: in},
Body: in,
}

if req.EnvelopeAttr == "" {
Expand All @@ -104,6 +106,9 @@ func doRoundTrip(c *Client, setHeaders func(*http.Request), in, out Message) err
if req.NSAttr == "" {
req.NSAttr = c.URL
}
if req.TNSAttr == "" {
req.TNSAttr = req.NSAttr
}
var b bytes.Buffer
err := xml.NewEncoder(&b).Encode(req)
if err != nil {
Expand Down Expand Up @@ -136,7 +141,13 @@ func doRoundTrip(c *Client, setHeaders func(*http.Request), in, out Message) err
Msg: string(body),
}
}
return xml.NewDecoder(resp.Body).Decode(out)

marshalStructure := struct {
XMLName xml.Name `xml:"Envelope"`
Body Message
}{Body: out}

return xml.NewDecoder(resp.Body).Decode(&marshalStructure)
}

// RoundTrip implements the RoundTripper interface.
Expand Down Expand Up @@ -209,13 +220,8 @@ type Envelope struct {
XMLName xml.Name `xml:"SOAP-ENV:Envelope"`
EnvelopeAttr string `xml:"xmlns:SOAP-ENV,attr"`
NSAttr string `xml:"xmlns:ns,attr"`
TNSAttr string `xml:"xmlns:tns,attr"`
XSIAttr string `xml:"xmlns:xsi,attr,omitempty"`
Header Message `xml:"SOAP-ENV:Header"`
Body Body
}

// Body is the body of a SOAP envelope.
type Body struct {
XMLName xml.Name `xml:"SOAP-ENV:Body"`
Message Message
Body Message `xml:"SOAP-ENV:Body"`
}
15 changes: 11 additions & 4 deletions wsdl/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,17 @@ type IO struct {

// Binding describes SOAP to WSDL binding.
type Binding struct {
XMLName xml.Name `xml:"binding"`
Name string `xml:"name,attr"`
Type string `xml:"type,attr"`
Operations []*BindingOperation `xml:"operation"`
XMLName xml.Name `xml:"binding"`
Name string `xml:"name,attr"`
Type string `xml:"type,attr"`
BindingType *BindingType `xml:"binding"`
Operations []*BindingOperation `xml:"operation"`
}

// BindingType contains additional meta data on how to implement the binding.
type BindingType struct {
Style string `xml:"style,attr"`
Transport string `xml:"transport,attr"`
}

// BindingOperation describes the requirement for binding SOAP to WSDL
Expand Down
Loading

0 comments on commit 4a7bcbb

Please sign in to comment.