• Stars
    star
    449
  • Rank 97,328 (Top 2 %)
  • Language
    Go
  • License
    Other
  • Created over 8 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Command line tool to generate Go code from WSDL for SOAP XML services

wsdl2go

Build Status Go Report Card GoDoc

wsdl2go is a command line tool to generate Go code from WSDL.

Download:

go get github.com/fiorix/wsdl2go

Usage

tl;dr

wsdl2go < file.wsdl > hello.go

wsdl2go is a code generator that consumes WSDL from stdin (or file, or URL) and produces Go on stdout. The generated code contains services and methods described in the WSDL input, in a single output file. It is your responsibility to make it a package, in the sense that you put it in a directory that makes sense for you, and import it in your code later. Note that the generated code depends on the "soap" package that is part of this project.

WSDL inputs that contain import tags (includes) pointing to other WSDL resources (other files or URLs) may be a source of trouble. The default behavior of wsdl2go is to try and load them, recursively. However, wsdl2go does not support authentication for remote HTTP resources, and cannot fetch resources from HTTPS servers with insecure TLS certificates. In those cases, you have to download the WSDL files yourself using curl or whatever, and process them locally. You might have to tweak their import paths.

Once the code is generated, wsd2go runs gofmt on it. You must have gofmt in your $PATH, or $GOROOT/bin, or you'll get an error.

Using the generated code

Here's how to use the generated code: let's say you have a WSDL that defines the "example" service. You generate the code and make it the "example" package somewhere in your $GOPATH. This service provides an Echo method that takes an EchoRequest and returns an EchoReply.

The process is this:

  • Import the generated code
  • Create a soap.Client (and here you can configure SOAP authentication, for example)
  • Instantiate the service using your soap.Client
  • Call the service methods

Example:

import (
	"/path/to/generated/example"

	"github.com/fiorix/wsdl2go/soap"
)

func main() {
	cli := soap.Client{
		URL: "http://server",
		Namespace: example.Namespace,
	}
	soapService := example.NewEchoService(&cli)
	echoReply, err := soapService.Echo(&example.EchoRequest{Data: "hello world"})
	...
}

The soap.Client supports two forms of authentication:

  • Setting the "Pre" hook to a function that is run on all outbound HTTP requests, which can set HTTP headers and Basic Auth
  • Setting the Header attribute to an AuthHeader, to have it as a SOAP header (with username and password) in every request

Note that only the Document style of SOAP is supported. The RPC style is currently not supported.

Status

Works for my needs, been tested with a few SOAP enterprise systems. Not fully compliant to WSDL or SOAP specs.

Because of some limitations of XML namespaces in Go, there's only so much one can do to make things like SOAP work properly. Although, the code generated by wsdl2go might be sufficient for most systems.

Types supported:

  • byte
  • int
  • long (int64)
  • float (float64)
  • double (float64)
  • boolean (bool)
  • string
  • hexBinary ([]byte)
  • base64Binary ([]byte)
  • date
  • time
  • dateTime
  • simpleType (w/ enum and validation)
  • complexType (struct)
  • complexContent (slices, embedded structs)
  • token (as string)
  • any (slice of empty interfaces)
  • anyURI (string)
  • QName (string)
  • union (empty interface w/ comments)
  • nonNegativeInteger (uint)
  • faults
  • decimal
  • g{Day,Month,Year}...
  • NOTATION

Date types are currently defined as strings, need to implement XML Marshaler and Unmarshaler interfaces. The binary ones (hex and base64) are also lacking marshal/unmarshal.

For simple types that have restrictions defined, such as an enumerated list of possible values, we generate the validation function using reflect to compare values. This and the entire API might change anytime, be warned.

More Repositories

1

freegeoip

IP geolocation web server
Go
4,931
star
2

go-diameter

Diameter stack and Base Protocol (RFC 6733) for the Go programming language
Go
244
star
3

go-smpp

SMPP 3.4 Protocol for the Go programming language
Go
218
star
4

protoc-gen-cobra

Cobra command line tool generator for gRPC clients
Go
189
star
5

go-daemon

Utility to "daemonize" Go programs
C
174
star
6

go-eventsocket

FreeSWITCH Event Socket library for the Go programming language.
Go
125
star
7

cat-o-licious

Cat game written in Go
Go
104
star
8

eventsocket

Twisted protocol for the FreeSWITCH's Event Socket
Python
54
star
9

go-web

Utilities for http servers written in Go
Go
52
star
10

sms-api-server

HTTP API to send SMS via SMPP
Go
47
star
11

go-redis

Redis client library for Go
Go
45
star
12

txtraceroute

An asynchronous, pure python, traceroute with geolocation information
Python
44
star
13

twisted-twitter-stream

Twitter Stream API for Twisted
Python
43
star
14

jsonschema2go

Code generator for JSON schema
Go
38
star
15

ffmpeg-arm

Docker image with ffmpeg for ARM (Raspberry Pi)
37
star
16

nitgen-bsp

Python extension for Nitgen fingerprint recognition devices
C
22
star
17

mustash

recognize people's face and put a mustache on it
Python
15
star
18

defacer

meow
Go
12
star
19

go-swagger-ui

Go HTTP handler for serving swagger-ui
Go
10
star
20

niosted

Experimental reactor on top of Java NIO
Python
8
star
21

gocp

Go Concurrency Primitives
Go
7
star
22

dotfiles

my set of configuration files
Shell
5
star
23

go-talks

A collection of my Go talks
Go
5
star
24

txdbapi

Experimental ORM for Twisted based on Twistar
Python
4
star
25

pyqrcode

QRcode encoder and decoder for python
Java
4
star
26

go-listener

TCP listener on roids
Go
3
star
27

crosstool-ng-arm

Docker image with crosstool-ng for ARM (Raspberry Pi)
Shell
3
star
28

talkinator

a talking akinator
Python
3
star
29

pyascii85

Ascii85 encoder and decoder for python
C
3
star
30

linvpn

Secure socket layer for pppd (legacy)
C
2
star
31

b3-geoip-plugin

IP Geolocation plugin for the Big Brother Bot
Python
2
star
32

fiorix.github.com

HTML
2
star
33

pbserver

pbcopy and pbpaste over the web
Python
1
star