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
- Fixes issues with keywords and casing
- Fixes truncate problem on binding regeneration
  • Loading branch information
kernle32dll committed Dec 28, 2017
1 parent 23f46cc commit fab41d1
Show file tree
Hide file tree
Showing 16 changed files with 925 additions and 209 deletions.
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func main() {
case "", "-":
w = os.Stdout
default:
f, err := os.OpenFile(opts.Dst, os.O_CREATE|os.O_WRONLY, 0644)
f, err := os.OpenFile(opts.Dst, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0644)
if err != nil {
log.Fatal(err)
}
Expand Down
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 fab41d1

Please sign in to comment.