Coder Social home page Coder Social logo

wsdl2go's Introduction

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:

  • 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.

wsdl2go's People

Contributors

adriantam avatar arkadiam avatar bstein-clever avatar fank avatar fiorix avatar joyrex2001 avatar kernle32dll avatar mtricht avatar npenkov avatar programyazar avatar thezeroslave avatar turboezh avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.