🦉SOAP package for Go

Overview

Go Soap Build Status GoDoc Go Report Card Coverage Status patreon

package to help with SOAP integrations (client)

Install

go get github.com/tiaguinho/gosoap

Examples

Basic use

package main

import (
	"encoding/xml"
	"log"
	"net/http"
	"time"

	"github.com/tiaguinho/gosoap"
)

// GetIPLocationResponse will hold the Soap response
type GetIPLocationResponse struct {
	GetIPLocationResult string `xml:"GetIpLocationResult"`
}

// GetIPLocationResult will
type GetIPLocationResult struct {
	XMLName xml.Name `xml:"GeoIP"`
	Country string   `xml:"Country"`
	State   string   `xml:"State"`
}

var (
	r GetIPLocationResponse
)

func main() {
	httpClient := &http.Client{
		Timeout: 1500 * time.Millisecond,
	}
	soap, err := gosoap.SoapClient("http://wsgeoip.lavasoft.com/ipservice.asmx?WSDL", httpClient)
	if err != nil {
		log.Fatalf("SoapClient error: %s", err)
	}
	
	// Use gosoap.ArrayParams to support fixed position params
	params := gosoap.Params{
		"sIp": "8.8.8.8",
	}

	res, err := soap.Call("GetIpLocation", params)
	if err != nil {
		log.Fatalf("Call error: %s", err)
	}

	res.Unmarshal(&r)

	// GetIpLocationResult will be a string. We need to parse it to XML
	result := GetIPLocationResult{}
	err = xml.Unmarshal([]byte(r.GetIPLocationResult), &result)
	if err != nil {
		log.Fatalf("xml.Unmarshal error: %s", err)
	}

	if result.Country != "US" {
		log.Fatalf("error: %+v", r)
	}

	log.Println("Country: ", result.Country)
	log.Println("State: ", result.State)
}

Set Custom Envelope Attributes

package main

import (
	"encoding/xml"
	"log"
	"net/http"
	"time"

	"github.com/tiaguinho/gosoap"
)

// GetIPLocationResponse will hold the Soap response
type GetIPLocationResponse struct {
	GetIPLocationResult string `xml:"GetIpLocationResult"`
}

// GetIPLocationResult will
type GetIPLocationResult struct {
	XMLName xml.Name `xml:"GeoIP"`
	Country string   `xml:"Country"`
	State   string   `xml:"State"`
}

var (
	r GetIPLocationResponse
)

func main() {
	httpClient := &http.Client{
		Timeout: 1500 * time.Millisecond,
	}
	// set custom envelope
    gosoap.SetCustomEnvelope("soapenv", map[string]string{
		"xmlns:soapenv": "http://schemas.xmlsoap.org/soap/envelope/",
		"xmlns:tem": "http://tempuri.org/",
    })

	soap, err := gosoap.SoapClient("http://wsgeoip.lavasoft.com/ipservice.asmx?WSDL", httpClient)
	if err != nil {
		log.Fatalf("SoapClient error: %s", err)
	}
	
	// Use gosoap.ArrayParams to support fixed position params
	params := gosoap.Params{
		"sIp": "8.8.8.8",
	}

	res, err := soap.Call("GetIpLocation", params)
	if err != nil {
		log.Fatalf("Call error: %s", err)
	}

	res.Unmarshal(&r)

	// GetIpLocationResult will be a string. We need to parse it to XML
	result := GetIPLocationResult{}
	err = xml.Unmarshal([]byte(r.GetIPLocationResult), &result)
	if err != nil {
		log.Fatalf("xml.Unmarshal error: %s", err)
	}

	if result.Country != "US" {
		log.Fatalf("error: %+v", r)
	}

	log.Println("Country: ", result.Country)
	log.Println("State: ", result.State)
}
Issues
  • Which version should we use, master vs 1.2.0?

    Which version should we use, master vs 1.2.0?

    Which version should we use, master vs 1.2.0?

    And whether the README example works with the v1.2.0 (that by default got grabbed?)... I think it requires modifications...

    In other words, is it safe to do go get github.com/tiaguinho/[email protected]?

    opened by mhewedy 7
  • Allow overriding http.Client

    Allow overriding http.Client

    adding HttpClient public property to Client, so that it can be overridden with Proxy support, custom headers/useragent & GoVCR for testing & http request playback

    https://github.com/seborama/govcr

    opened by AnalogJ 4
  • Alter Params to support nested requests

    Alter Params to support nested requests

    In my case, i have to consume a soap webservice with a nested request structure:

    <request> <customer> <customerId>123</customerId> </customer> </request>

    Since Params is from type map[string]string, it is impossible to model this kind of request. Is there a possibility to change the type of Params to map[string]interface{} ?

    enhancement 
    opened by LegendOfGIT 4
  • method or namespace is empty

    method or namespace is empty

    Hello ,How to understant Call func param method?What the reason about the error:"method or namespace is empty",When I set method and namespace. Hope to receive your reply recently!Best wishes!

    waiting for response needs investigation 
    opened by HuangShiQian 3
  • HTTP client can be configurate outside the SOAP module.

    HTTP client can be configurate outside the SOAP module.

    Using an external HTTP Client allows the users to have more control over how he communicates with the service.

    For example, adding certificates to the transport configuration.

    httpClient := &http.Client{
      Transport: &http.Transport{
        TLSClientConfig: &tls.Config{
          InsecureSkipVerify: true,
        },
      },
    }
    
    soapClient := gosoap.SoapClient(url, httpClient)
    

    And any kind of configuration for the HTTP Client will apply even though when the library is getting the definitions.

    pr: ready for master 
    opened by highercomve 3
  • Credentials adding for the endpoint

    Credentials adding for the endpoint

    Hello

    Many thanks for your code, but i have an issue with my use case. It's possible to add credentials for SOAP endpoint with gosoap.

    I have try with this option and the soap have an error like output:

    func main() { soap, err := gosoap.SoapClient("https://enpoint_url") if err != nil { fmt.Errorf("error not expected: %s", err) } soap.HeaderParams = gosoap.Params{ "Authorization": "Basic" + basicAuth("user", "password"), }

    opened by avaussant 3
  • Feature/composite properties and authentication

    Feature/composite properties and authentication

    This is further work I did on top of https://github.com/tiaguinho/gosoap/pull/4

    This does:

    1. Does everything the other PR does
    2. Successfully execute all test
    3. Support []map[string]interface{}
    4. More "pluggable"
    opened by Fale 3
  • Verbose error message if WSDL request fails with status code < 200 or > 400

    Verbose error message if WSDL request fails with status code < 200 or > 400

    Hi! It is useful when you see a full error message rather then just a payload. I suggest just print bad response body. Or maybe do a configurable logging for user. What do you think?

    opened by requiemofthesouls 2
  • Throw an error if WSDL request fails with status code < 200 or > 400

    Throw an error if WSDL request fails with status code < 200 or > 400

    Throws an error in doRequest() if remote server answers with one of the "unsuccessful" codes: everything less than 200 or bigger than 400.

    Fixes #66

    opened by Ekizare 2
  • Addresses issue - [Differentiate fault and response unmarshal error]

    Addresses issue - [Differentiate fault and response unmarshal error]

    Issue link: https://github.com/tiaguinho/gosoap/issues/63

    What does this PR offer?

    Now, we can differentiate the fault error from other errors we get from *Response.Unmarshal(). The sample code is given below.

            var sampleResponse SampleResponse
    	err = response.Unmarshal(&sampleResponse)
    	if err != nil {
    		if gosoap.IsFault(err) {
    			return "", errors.Wrap(err, "error as fault occurred")  // Or, do something instead of returning err
    		}
    
    		return "", errors.Wrap(err, "error unmarshalling sample response")
    	}
    

    All the unit tests passed.

    opened by AjithPanneerselvam 2
  • Create SoapClient with a configured HttpClient

    Create SoapClient with a configured HttpClient

    Hi,

    I'm trying to construct a SoapClient with a configured HttpClient so I can skip certificate verifications. Something like this:

    package mypackage
    
    import (
    	"crypto/tls"
    	"log"
    	"net/http"
    
    	soap "github.com/tiaguinho/gosoap"
    )
    
    // NewClient creates a SOAP client.
    func NewClient(wsdlUrl string) (*soap.Client, error) {
    	transport := &http.Transport{
    		TLSClientConfig: &tls.Config{
    			InsecureSkipVerify: true,
    		},
    	}
    
    	httpClient := &http.Client{Transport: transport}
    
    	client ,err := soap.SoapClient(wsdlUrl) // <-- Fails here
    	if err != nil {
    		return nil, err
    	}
    
    	client.HttpClient = httpClient
    
    	return client, nil
    }
    

    However, it is not working since it will fail even when it tries to get the wsdl data! I just wonder if there is any workaround for this issue or if I'm doing something wrong? If not, would be really appreciated if we could have it as an enhancement for this package.

    Thanks in advance. :)

    opened by ashkanF 2
  • Overrided Soap Fault Exception

    Overrided Soap Fault Exception

    I was receiving SOAP Fault Exception with http status code 500 with error message but the error was override by code, if the http status code != 200 or http status code >= 400, with *gosoap response is nil and new error. So the error message not showing properly to the client (not showing the 'original response' from server)

    opened by guhkun13 0
  • The latest code does not create a version

    The latest code does not create a version

    https://github.com/tiaguinho/gosoap/blob/3dabb23ba747470e9f3fe5103d9f5542272612a4/soap.go#L87

    Hello, the latest code has not created a version, you added the function of improve xml encoding in the commit on July 5, 2021, (201f9637b0eb3ab95ff4b9d0dc2f96f22495ff4b).But as of now, you have not released a new version, and the latest version is still at v1.4.4 on November 23, 2020, so when I use this function, I will be prompted for the structure of SliceParams.

    Thinks.

    opened by rose-tmp 0
  • Automatic xml encoding for structs

    Automatic xml encoding for structs

    This leaves the struct handling alone in recursiveEncode, which is designed to deal with individual xml.Tokens.

    Instead, we just use xml.Encode for top-level structs, and leave the formatting up to the struct tags, which allow for plenty of control

    opened by pmh1wheel 0
  • Body content

    Body content

    Currently, gosoap uses the operation name as the only body part of the message. But the names (tags) of body parts may not be the same as the names of the operations. Are you planning to implement retrieving of body part names (binding -> port type -> operation -> input -> message -> part -> element) for use when encoding?

    opened by PaPashka 0
Releases(v1.4.4)
Owner
Tiago Temporin
Married. SRE @acesso-io. Go, Python, Angular, PHP, Linux, NoSQL.
Tiago Temporin
Package arp implements the ARP protocol, as described in RFC 826. MIT Licensed.

arp Package arp implements the ARP protocol, as described in RFC 826. MIT Licensed. Portions of this code are taken from the Go standard library. The

Matt Layher 287 Jun 22, 2022
Package dhcp6 implements a DHCPv6 server, as described in RFC 3315. MIT Licensed.

dhcp6 Package dhcp6 implements a DHCPv6 server, as described in IETF RFC 3315. MIT Licensed. At this time, the API is not stable, and may change over

Matt Layher 74 May 8, 2022
A Go package for sending and receiving ethernet frames. Currently supporting Linux, Freebsd, and OS X.

ether ether is a go package for sending and receiving ethernet frames. Currently supported platform: BPF based OS X FreeBSD AF_PACKET based Linux Docu

Song Gao 77 Jun 20, 2022
Package ethernet implements marshaling and unmarshaling of IEEE 802.3 Ethernet II frames and IEEE 802.1Q VLAN tags. MIT Licensed.

ethernet Package ethernet implements marshaling and unmarshaling of IEEE 802.3 Ethernet II frames and IEEE 802.1Q VLAN tags. MIT Licensed. For more in

Matt Layher 240 Mar 12, 2022
Fast HTTP package for Go. Tuned for high performance. Zero memory allocations in hot paths. Up to 10x faster than net/http

fasthttp Fast HTTP implementation for Go. Currently fasthttp is successfully used by VertaMedia in a production serving up to 200K rps from more than

Aliaksandr Valialkin 17.9k Jun 23, 2022
FTP client package for Go

goftp A FTP client package for Go Install go get -u github.com/jlaffaye/ftp Documentation https://pkg.go.dev/github.com/jlaffaye/ftp?tab=doc Example

Julien Laffaye 947 Jun 20, 2022
golibwireshark - Package use libwireshark library to decode pcap file and analyse dissection data.

golibwireshark Package golibwireshark use libwireshark library to decode pcap file and analyse dissection data. This package can only be used in OS li

Xiaoguang Wang 24 Mar 2, 2022
A download manager package for Go

grab Downloading the internet, one goroutine at a time! $ go get github.com/cavaliercoder/grab Grab is a Go package for downloading files from the in

Ryan Armstrong 1.1k Jun 21, 2022
Package raw enables reading and writing data at the device driver level for a network interface. MIT Licensed.

raw Package raw enables reading and writing data at the device driver level for a network interface. MIT Licensed. For more information about using ra

Matt Layher 421 Jun 15, 2022
SFTP support for the go.crypto/ssh package

sftp The sftp package provides support for file system operations on remote ssh servers using the SFTP subsystem. It also implements an SFTP server fo

null 1.2k Jun 21, 2022
A SOCKS (SOCKS4, SOCKS4A and SOCKS5) Proxy Package for Go

SOCKS SOCKS is a SOCKS4, SOCKS4A and SOCKS5 proxy package for Go. Quick Start Get the package go get -u "h12.io/socks" Import the package import "h12

Hǎi-Liàng 418 Jun 21, 2022
Package for writing Nagios/Icinga/et cetera plugins in Go (golang)

nagiosplugin Package for writing Nagios/Icinga/et cetera plugins in Go (golang). Documentation See http://godoc.org/github.com/olorin/nagiosplugin. Us

Sharif Olorin 69 Apr 4, 2022
Examples using the stomp package from git://github.com/gmallard/stompngo.git

stompngo_examples - A collection of examples for package stompngo Features Full demonstration of support for STOMP protocols: Protocol Level 1.0 Proto

Guy M. Allard 16 Jan 22, 2021
A STOMP Client package for go developers, supporting all STOMP specification levels.

stompngo - A STOMP 1.0, 1.1 and 1.2 Client Package Features Full support of STOMP protocols: Protocol Level 1.0 Protocol Level 1.1 Protocol Level 1.2

Guy M. Allard 138 Mar 7, 2022
Inspired by go-socks5,This package provides full functionality of socks5 protocol.

The protocol described here is designed to provide a framework for client-server applications in both the TCP and UDP domains to conveniently and securely use the services of a network firewall.

Zhangliu 67 Jun 21, 2022
Package socket provides a low-level network connection type which integrates with Go's runtime network poller to provide asynchronous I/O and deadline support. MIT Licensed.

socket Package socket provides a low-level network connection type which integrates with Go's runtime network poller to provide asynchronous I/O and d

Matt Layher 41 May 9, 2022
Full-featured BitTorrent client package and utilities

torrent This repository implements BitTorrent-related packages and command-line utilities in Go. The emphasis is on use as a library from other projec

Matt Joiner 4.4k Jun 20, 2022
Package httpretty prints the HTTP requests you make with Go pretty on your terminal.

httpretty Package httpretty prints the HTTP requests of your Go programs pretty on your terminal screen. It is mostly inspired in curl's --verbose mod

Henrique Vicente 257 Jun 15, 2022