Giter VIP home page Giter VIP logo

gosoap's Introduction

Go Soap Build Status GoDoc Go Report Card Coverage Status patreon Known Vulnerabilities

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)
}

Set Header params

	soap.HeaderParams = gosoap.SliceParams{
		xml.StartElement{
			Name: xml.Name{
				Space: "auth",
				Local: "Login",
			},
		},
		"user",
		xml.EndElement{
			Name: xml.Name{
				Space: "auth",
				Local: "Login",
			},
		},
		xml.StartElement{
			Name: xml.Name{
				Space: "auth",
				Local: "Password",
			},
		},
		"P@ssw0rd",
		xml.EndElement{
			Name: xml.Name{
				Space: "auth",
				Local: "Password",
			},
		},
	}

gosoap's People

Contributors

ajithpanneerselvam avatar analogj avatar cj-jackson avatar docxplusgmoon avatar dwagin avatar ejosvp avatar ekizare avatar eloyekunle avatar fale avatar geseq avatar giautm avatar highercomve avatar ivan-californias avatar jeffkayser2 avatar mhewedy avatar nij4t avatar r6q avatar requiemofthesouls avatar steven-aka-steven avatar tiaguinho avatar twz915 avatar xhit avatar xuhaojun avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gosoap's Issues

Change endpoint

Hi,

is there a way to use a different service endpoint than the one defined in the WSDL?

Cheers,

Peter

Custom encoder vs standard library

Hi @tiaguinho !

Great work on the library! Just wanted to ask why did you decide to write a custom encoder as opposed to using the standard to marshal Params (recursiveEncode)?

Thanks!

Request with TLS1.2 - tls: handshake failure

How can I check if I am requesting with which TLS version?
Requirement of SOAP API is to connect with TLS1.2. How should I add that config while calling method?

Code:

soap, err := gosoap.SoapClient(WSDL_URL)
err = soap.Call("__getFunctions", gosoap.Params{})

Error I am getting is:

remote error: tls: handshake failure

Expected element type <Envelope> but have <html>

I'm trying to connect to this sample soap API server (https://www.w3schools.com/xml/tempconvert.asmx) but the soap.Call method always results in this error "expected element type <Envelope> but have <html>"

Following is my code snippet,

httpClient := &http.Client{
		Timeout: 1500 * time.Millisecond,
	}

	soap, err := gosoap.SoapClient("https://www.w3schools.com/xml/tempconvert.asmx?wsdl", httpClient)
	if err != nil {
		fmt.Println("error occurred: ", err)
		return
	}

	params := gosoap.Params{
		"Celsius": 500,
	}

	res, err := soap.Call("CelsiusToFahrenheit", params)
	if err != nil {
		fmt.Println("error occurred while fetching response: ", err)
		return
	}

Can anyone help?

Cannot show the result

http://www.dneonline.com/calculator.asmx?WSDL
The example WSDL is find an internet,
Here is my code

when I try to run the code

always receive ERRO[0000] {{0}}

I want to know is the file cannot read the WSDL file or something wrong?

Thanks

package main

import (
	"github.com/tiaguinho/gosoap"
	"fmt"
	"github.com/sirupsen/logrus"
)

type GetAddResult struct {
	AddResult int
}

type GetAddResponse struct {
	GetAddRs GetAddResult
}


var (
	r GetAddResponse
)

func main() {
	soap, err := gosoap.SoapClient("http://www.dneonline.com/calculator.asmx?WSDL")
	if err != nil {
		logrus.Error("err")
		fmt.Errorf("error not expected: %s", err)
	}

	params := gosoap.Params{
		"intA": "1",
		"intB": "1",
	}

	fmt.Print(soap)

	err = soap.Call("Add", params)
	if err != nil {
		logrus.Error("err1")
		fmt.Errorf("error in soap call: %s", err)
		return;
	}

fmt.Print(soap.Unmarshal(&r))

	soap.Unmarshal(&r)
	fmt.Print("\n\n")
	if r.GetAddRs.AddResult != 2 {
		logrus.Error(r)
		// fmt.Errorf("error: %+v", r)
	} else {
		logrus.Info("else")
	}
}

Allow arbitary object tagged with xml to be passed

I think one of the core features your abstraction is hiding it is to allow random xml object to be passed.

What i mean that the Params map is not.covering cases like xml attributes and xml name spacing which in many cases is heavily used.

My suggestion either to allow accepting byte array or interface types and then marchal it into xml.

It's not working when TargetNamespace is empty

The latest code does not create a version

gosoap/soap.go

Line 87 in 3dabb23

HeaderParams SoapParams

Hello, the latest code has not created a version, you added the function of improve xml encoding in the commit on July 5, 2021, (201f963).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.

[soap:Server]: Server was unable to process request.

when I try to Unmarshal the result
it will display the error?
I want to know what happen in my program?
thanks

ERRO[0000] [soap:Server]: Server was unable to process request. ---> Cannot insert the value NULL into column 'OperatorsName', table 'payme.dbo.SystemLogs'; column does not allow nulls. INSERT fails.
The statement has been terminated. 
type GetFundResult struct {
	GetFundResult int
}

var (
	r1 GetFundResult
)

	err1 := soap.Unmarshal(&r1)
	if err1 != nil {
		logrus.Error(err1)
	}
	logrus.Info(r1)

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/gosoap@master?

Update the README example with working version

Hi there. The README example it's not working. It seems like webservicex changed their endpoints.

I tried to create a PR with an similar and working example for the README, but I got no permission for that, so here it goes, if you are interested:

package main

import (
	"encoding/xml"
	"log"

	"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() {
	soap, err := gosoap.SoapClient("http://wsgeoip.lavasoft.com/ipservice.asmx?WSDL")
	if err != nil {
		log.Fatalf("SoapClient error: %s", err)
	}

	params := gosoap.Params{
		"sIp": "8.8.8.8",
	}

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

	soap.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)
}

Error when testing

Hello, I'm trying to perform a test with soap but I do not get data.
My code:

package main

import (
	"log"

	"github.com/tiaguinho/gosoap"
)

type LoginResponse struct {
	LoginResult LoginResult
}

type LoginResult struct {
	sid string
}

var (
	r LoginResponse
)

func main() {

	soap, err := gosoap.SoapClient("https://demo.ilias.de/webservice/soap/server.php?wsdl")
	if err != nil {
		log.Fatal("error not expected: ", err)
	}

	params := gosoap.Params{
		"client":   "asd",
		"username": "asd",
		"password": "asd",
	}

	err = soap.Call("login", params)

	if err != nil {
		log.Fatal("error in soap call: ", err)

	}

	soap.Unmarshal(&r)
	//fmt.Printf("error: %+v", r.LoginResult.sid)
	if r.LoginResult.sid != "USA" {
		log.Fatal("error: ", r)
	}

}

My Error:

2018/09/07 16:48:38 error in soap call: expected element type <Envelope> but have <br>
exit status 1

Control the Accept header

I'm using an old, probably misconfigured, SOAP service running on PHP.

Currently, the call fails due to a 406 error. I identified (reproducing with curl) that the problem is the Accept header.

When defaulted to "/" by curl, it works. But gosoap enforces it to "text/xml" and in this case it fails.

Is it possible to evolve gosoap to offer a control over this header?
I can do the change and propose a PR if you agree.

Strange Encoding Issue with namespace

Hey there,

thanks for writing this lib. Its the one that works best for me so far :)

However, I'm hitting a strange issue. I'll try to get that lib working with that wsdl:
http://api.neocron-game.com:8100/SessionManagement?wsdl

If I do a call to that WCF endpoint, I get that error from the endpoint:

OperationFormatter encountered an invalid Message body. Expected to find node type 'Element' with name 'Login' and namespace 'http://tempuri.org/'. Found node type 'Element' with name 'Login' and namespace 'http://tempuri.org/Imports'

I was able to trace that error down to the use of c.Definitions.Types[0].XsdSchema[0].TargetNamespace in https://github.com/tiaguinho/gosoap/blob/master/encode.go

If I overwrite it like that in my code

soap, err := gosoap.SoapClient("http://api.neocron-game.com:8100/SessionManagement?wsdl")
	if err != nil {
		fmt.Errorf("error not expected: %s", err)
	}

	params := gosoap.Params{
		"user":     "someUser",
		"password": "somePassword",
	}

	soap.Definitions.Types[0].XsdSchema[0].TargetNamespace = "http://tempuri.org/"

I can get it to work. Sadly, I dont know enough about SOAP / WCF, so do I hit a bug or is something wrong with the endpoint? If its a bug, I'd be happy to help out if someone can point me into the right dirrection.

Thanks :)

soap.Call("methodname", params) return is error?

this is my return :
{ "code": 200, "data": { "Body": "PHNvYXA6RmF1bHQ+PGZhdWx0Y29kZT5zb2FwOkNsaWVudDwvZmF1bHRjb2RlPjxmYXVsdHN0cmluZz5TeXN0ZW0uV2ViLlNlcnZpY2VzLlByb3RvY29scy5Tb2FwRXhjZXB0aW9uOiBTZXJ2ZXIgZGlkIG5vdCByZWNvZ25pemUgdGhlIHZhbHVlIG9mIEhUVFAgSGVhZGVyIFNPQVBBY3Rpb246IC4NCiAgIGF0IFN5c3RlbS5XZWIuU2VydmljZXMuUHJvdG9jb2xzLlNvYXAxMVNlcnZlclByb3RvY29sSGVscGVyLlJvdXRlUmVxdWVzdCgpDQogICBhdCBTeXN0ZW0uV2ViLlNlcnZpY2VzLlByb3RvY29scy5Tb2FwU2VydmVyUHJvdG9jb2wuSW5pdGlhbGl6ZSgpDQogICBhdCBTeXN0ZW0uV2ViLlNlcnZpY2VzLlByb3RvY29scy5TZXJ2ZXJQcm90b2NvbEZhY3RvcnkuQ3JlYXRlKFR5cGUgdHlwZSwgSHR0cENvbnRleHQgY29udGV4dCwgSHR0cFJlcXVlc3QgcmVxdWVzdCwgSHR0cFJlc3BvbnNlIHJlc3BvbnNlLCBCb29sZWFuJmFtcDsgYWJvcnRQcm9jZXNzaW5nKTwvZmF1bHRzdHJpbmc+PGRldGFpbCAvPjwvc29hcDpGYXVsdD4=", "Header": null, "Payload": "PHNvYXBlbnY6RW52ZWxvcGUgeG1sbnM6dGVtPSJodHRwOi8vdGVtcHVyaS5vcmcvIiB4bWxuczpzb2FwZW52PSJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy9zb2FwL2VudmVsb3BlLyI+CiAgICA8c29hcGVudjpCb2R5PgogICAgICAgIDxHZXRTSEJTUVJlc3VsdCB4bWxucz0iaHR0cDovL2xhdmFzb2Z0LmNvbS8iPgogICAgICAgICAgICA8c3Q+MjAwMC0wMS0wMTwvc3Q+CiAgICAgICAgICAgIDxldD4yMDIwLTA4LTI1PC9ldD4KICAgICAgICAgICAgPG5hbWU+eHo8L25hbWU+CiAgICAgICAgICAgIDxwd2Q+RTEwQURDMzk0OUJBNTlBQkJFNTZFMDU3RjIwRjg4M0U8L3B3ZD4KICAgICAgICAgICAgPHBhZ2VJbmRleD48L3BhZ2VJbmRleD4KICAgICAgICAgICAgPHBhZ2VTaXplPjwvcGFnZVNpemU+CiAgICAgICAgPC9HZXRTSEJTUVJlc3VsdD4KICAgIDwvc29hcGVudjpCb2R5Pgo8L3NvYXBlbnY6RW52ZWxvcGU+" }, "msg": "ok" }

is this retun data right?

URL does not work

hi

issue with url. Wsdl is downloaded from url but request is then not send to URL, after doing soap.Call.
I traced with wireshark and nothing is send.

tnx

`func main() {
soap, err := gosoap.SoapClient("http://172.31.1.52/wsdl/pbx900.wsdl")
if err != nil {
fmt.Errorf("error not expected: %s", err)
}

soap.URL = "http://172.31.1.52/PBX0/user.soap"
params := gosoap.Params{
	"user":   "test",
	"appl":   "test",
	"v":      true,
	"v501":   true,
	"v700":   true,
	"v800":   true,
	"vx1000": true,
}

err = soap.Call("Initialize", params)

if err != nil {
	fmt.Errorf("error in soap call: %s", err)
}

var r interface{}
soap.Unmarshal(&r)
fmt.Println(r)

}
`

Unable to find a c.Definitions.Services[0].Ports[0].SoapAddresses[0].Location

Thanks for this lib. I am getting the following error. Please help me.
Code:
soap, err := gosoap.SoapClient(https://svn.apache.org/repos/asf/airavata/sandbox/xbaya-web/test/Calculator.wsdl)
if err != nil {
fmt.Println("error not expected: %s", err)
}
fmt.Println("response :", soap)
err = soap.Call("NaradaApiService", gosoap.Params{})
if err != nil {
fmt.Errorf("error in soap call: %s", err)
}
Error :
goroutine 1 [running]:
github.com/tiaguinho/gosoap.(*Client).Call(0xc4204441c0, 0x6cceca, 0x10, 0xc420468510, 0x0, 0x0)
/home/vivek/go/src/github.com/tiaguinho/gosoap/soap.go:90 +0x5e6

Create tag or release

create a release or add a tag on the repo for convenience of pinning the version when used as a dependency

Unable to prepare a soap request which require Authheader

Please Help me setup below SOAP request xml which contains AuthHeader also.

        <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
           xmlns:out="http://Demo.Manufacturing.Webservices/Outbound/">
                   <soapenv:Header>
                       <out:AuthHeader>
	                       <out:UserName>admin</out:UserName>
	                     <out:Password>7338b6c1702d</out:Password>
                          </out:AuthHeader>
                      </soapenv:Header>
                      <soapenv:Body>
                            <out:GetOrder>
         	                <out:bu>1</out:bu>
	                        <out:order>5582</out:order>
                          </out:GetOrder>
                     </soapenv:Body>
           </soapenv:Envelope>

Service used in test no longer available

One of the SOAP services currently used in soap_test.go https://domains.livedns.co.il/API/DomainsAPI.asmx?WSDL is no longer available.
As a result, the WSDL definitions are not built and the test cases do not pass.

NOTE: This is actually different from the reason Travis tests aren't passing as I can see from the Travis logs. I've reproduced Travis' issue locally and still looking into that one. Basically, to reproduce it, you'll run into this one first.

Run example test

Hi, I'm trying to run the readme sample. I'm having trouble on two lines.

Problem1: multiple-value soap.Call() in single-value contextgo
Line 36
err = soap.Call("GetIpLocation", params) if err != nil { log.Fatalf("Call error: %s", err) }

Problem2: soap.Unmarshal undefined (type *gosoap.Client has no field or method Unmarshal)go
Line 41
soap.Unmarshal(&r)

Can anybody help me?

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)

Insert a Header value that won't be urlencoded

Where I am we are using SAML. One of the requirements is that I be able to put a "wsse:Security" header in place containing a SAMLToken

I currently can't do this currently When I add a HeaderParam the value always ends up being urlencoded

Is there a way to add a HeaderParam that isn't url encoded in the soap request?

Am I missing something, or is this just a missing feature.

Thanks for any help.

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?

Question: Does Gosoap support header security?

Hello!

I'm currently working on a project where I need to authenticate with a Security Header. The headers must contain a BineryToken, Timestamp and a signature which must be calculated for a .p12 certificate. Does gosoap support this?

XML syntax error on line 61: element <p> closed by </ul>

i have this error XML syntax error on line 61: element

closed by when executing soap.Call

my code is

soap, err := gosoap.SoapClient("http://gps.axionlog.com/gps.asmx", nil)
if err != nil {
fmt.Errorf("Axionlog:error not expected: %s", err)
return err
}

inputGPSParams := gosoap.Params{
	"vName":                   patente,
	"vPass":                   password,
	"vPatente":                patente,
	"vGPS_DateTime":           gpsdatetime,
	"vLatitud":                latitud,
	"vLongitud":               longitud,
	"vVelocidad":			   velocidaddelvehiculo,
	"vTemp_Congelado":         tempcongelado,
	"vTemp_Refrigerado":       temprefrigerado,
	"vAntena":                 antena,
	"vLocation_Name":          locationname,
	"vDireccion":              direccion,
	"vAnalog3":                analog3,
	"vAnalog4":                analog4,
	"vAnalog5":                analog5,
	"vAnalog6":                analog6,
}


res, err := soap.Call("InputGps",inputGPSParams)
   if err != nil {
	fmt.Errorf("Axionlog:error call: %s", err)
	return err
}

I do not know if I am using the library wrong, I did not have any problem before but reinstalled the library and I started having this error

doRequest lost all response cookies

doRequest method are lost all Response cookies. It doesn’t matter whether the http.DefaultClient is used or my own. I can't use your package because my client must supports authentication through cookies and if cookies are lost at this stage, then trying to inject a cookiejar does not make sense. 😕

method or namespace is empty

hello, i am aware that there are other issues similar to this title but i just didn't find any answer in the comments, so i would appreciate it if anyone could help, i need to make a request to this wsdl but i keep getting the error "method or namespace is empty, well , i am passing the method name as first argument to the Call method so i guess it is the namespace ? how can i specify it ? thanks

composite header params

Hello

I need to send a complex header param:

<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xmlns:xsd="http://www.w3.org/2001/XMLSchema"
               xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Header>
        <A xmlns="http://foo.org">
            <B>
                <D>foo</D>
                <E>bar</E>
            </B>
        </A>
    </soap:Header>
    <soap:Body>
        <A xmlns="http://bar.org">
            <B>foo</B>
            <C>bar</C>
        </A>
    </soap:Body>
</soap:Envelope>

I think #4 is related to this

can this be done by changing headerParams from map[string]string to map[string]interface{}, and some other changes in the encoder?
https://github.com/tiaguinho/gosoap/blob/master/soap.go#L19-L22
https://github.com/tiaguinho/gosoap/blob/master/encode.go#L40

method or namespace is empty

Hello there.
I also faced this error. and here is my wsdl:

<wsdl:definitions xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://impl.v1.ws.api.service.google.com/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:ns2="http://schemas.xmlsoap.org/soap/http" xmlns:ns1="http://v1.ws.api.service.google.com/" name="WsItfTask" targetNamespace="http://impl.v1.ws.api.service.google.com/">
<wsdl:import location="http://111.111.111.111:8088/ws/v1?wsdl=WsItfTask.wsdl" namespace="http://v1.ws.api.service.google.com/">
</wsdl:import>
<wsdl:binding name="WsItfTaskSoapBinding" type="ns1:WsItfTask">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="getSentResultCall">
<soap:operation soapAction="" style="document"/>
<wsdl:input name="getSentResultCall">
<soap:header message="ns1:getSentResultCall" part="token" use="literal">
</soap:header>
<soap:body parts="parameters" use="literal"/>
</wsdl:input>
<wsdl:output name="getSentResultCallResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="getSubmitResult">
<soap:operation soapAction="" style="document"/>
<wsdl:input name="getSubmitResult">
<soap:header message="ns1:getSubmitResult" part="token" use="literal">
</soap:header>
<soap:body parts="parameters" use="literal"/>
</wsdl:input>
<wsdl:output name="getSubmitResultResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="addFile">
<soap:operation soapAction="" style="document"/>
<wsdl:input name="addFile">
<soap:header message="ns1:addFile" part="token" use="literal">
</soap:header>
<soap:body parts="parameters" use="literal"/>
</wsdl:input>
<wsdl:output name="addFileResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="getSentTaskResultCall">
<soap:operation soapAction="" style="document"/>
<wsdl:input name="getSentTaskResultCall">
<soap:header message="ns1:getSentTaskResultCall" part="token" use="literal">
</soap:header>
<soap:body parts="parameters" use="literal"/>
</wsdl:input>
<wsdl:output name="getSentTaskResultCallResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="getSentTaskResultSms">
<soap:operation soapAction="" style="document"/>
<wsdl:input name="getSentTaskResultSms">
<soap:header message="ns1:getSentTaskResultSms" part="token" use="literal">
</soap:header>
<soap:body parts="parameters" use="literal"/>
</wsdl:input>
<wsdl:output name="getSentTaskResultSmsResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="submitTask">
<soap:operation soapAction="" style="document"/>
<wsdl:input name="submitTask">
<soap:header message="ns1:submitTask" part="token" use="literal">
</soap:header>
<soap:body parts="parameters" use="literal"/>
</wsdl:input>
<wsdl:output name="submitTaskResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="getSentResultSms">
<soap:operation soapAction="" style="document"/>
<wsdl:input name="getSentResultSms">
<soap:header message="ns1:getSentResultSms" part="token" use="literal">
</soap:header>
<soap:body parts="parameters" use="literal"/>
</wsdl:input>
<wsdl:output name="getSentResultSmsResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="authorization">
<soap:operation soapAction="" style="document"/>
<wsdl:input name="authorization">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="authorizationResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="getSmsReceive">
<soap:operation soapAction="" style="document"/>
<wsdl:input name="getSmsReceive">
<soap:header message="ns1:getSmsReceive" part="token" use="literal">
</soap:header>
<soap:body parts="parameters" use="literal"/>
</wsdl:input>
<wsdl:output name="getSmsReceiveResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="WsItfTask">
<wsdl:port binding="tns:WsItfTaskSoapBinding" name="WsItfTaskImplPort">
<soap:address location="http://111.111.111.111:8088/ws/v1"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>

Originally posted by @willqiang in #57 (comment)

panic: runtime error: index out of range

soap, err := gosoap.SoapClient(URL)
res, err := soap.Call("__getFunctions", gosoap.Params{})
panic: runtime error: index out of range

goroutine 1 [running]:
github.com/tiaguinho/gosoap.process.MarshalXML(0xc4200a62c0, 0xc4200e2340, 0xc420168060, 0x59, 0x0, 0x0, 0x0, 0xc42015a120, 0x0, 0x0, ...)
	/xcdata/djsp/src/github.com/tiaguinho/gosoap/encode.go:27 +0x103c
github.com/tiaguinho/gosoap.(*process).MarshalXML(0xc420195c40, 0xc42015a120, 0x0, 0x0, 0x64138d, 0x7, 0x0, 0x0, 0x0, 0x0, ...)
	<autogenerated>:1 +0xaf
encoding/xml.(*printer).marshalInterface(0xc42015a120, 0x7f52ca1b8028, 0xc420195c40, 0x0, 0x0, 0x64138d, 0x7, 0x0, 0x0, 0x0, ...)
	/usr/local/go/src/encoding/xml/marshal.go:652 +0xf8
encoding/xml.(*printer).marshalValue(0xc42015a120, 0x6803a0, 0xc420195bc0, 0x16, 0x0, 0x0, 0x4af801, 0xc42015a120)
	/usr/local/go/src/encoding/xml/marshal.go:425 +0x14ae
encoding/xml.(*Encoder).Encode(0xc42015a120, 0x6803a0, 0xc420195bc0, 0xc420177000, 0x1000)
	/usr/local/go/src/encoding/xml/marshal.go:155 +0x79
encoding/xml.MarshalIndent(0x6803a0, 0xc420195bc0, 0x0, 0x0, 0x6c7461, 0x4, 0x59, 0x0, 0x0, 0x1, ...)
	/usr/local/go/src/encoding/xml/marshal.go:122 +0x1a1
github.com/tiaguinho/gosoap.(*Client).Do(0xc4200a62c0, 0xc4200e2340, 0x0, 0x0, 0x0)
	/xcdata/djsp/src/github.com/tiaguinho/gosoap/soap.go:138 +0x239
github.com/tiaguinho/gosoap.(*Client).Call(0xc4200a62c0, 0x6cdcff, 0xe, 0xc420072f90, 0xc420072f90, 0xc42006c058, 0x0)
	/xcdata/djsp/src/github.com/tiaguinho/gosoap/soap.go:61 +0x82
main.main()
	/data/test/src/main.go:22 +0x105
exit status 2

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"),
}

Wrong namespace used in call

I'm trying to make a call via this WSDL and the namespace that the server expects is http://tempuri.org/, but the library sends http://tempuri.org/Imports instead. The WSDL has a section:

<wsdl:types>
  <xsd:schema targetNamespace="http://tempuri.org/Imports">
    <xsd:import schemaLocation="https://datastore.ceidg.gov.pl/CEIDG.DataStore/services/DataStoreProvider201901.svc?xsd=xsd0" namespace="http://tempuri.org/"/>
    <xsd:import schemaLocation="https://datastore.ceidg.gov.pl/CEIDG.DataStore/services/DataStoreProvider201901.svc?xsd=xsd1" namespace="http://schemas.microsoft.com/2003/10/Serialization/"/>
    <xsd:import schemaLocation="https://datastore.ceidg.gov.pl/CEIDG.DataStore/services/DataStoreProvider201901.svc?xsd=xsd2" namespace="http://schemas.microsoft.com/2003/10/Serialization/Arrays"/>
  </xsd:schema>
</wsdl:types>

and it looks like the call takes the namespace from this section's targetNamespace instead of taking it from the xsd:import or the top level wsdl:definitions.

doRequest status code handling

Hello.

There is no handling for HTTP status code in doRequest method. It can be useful as debug info and for resolving some of the errors. I presume the status code should be logged or even return an error if it is not between 200 and 400.

So, I can create a pull request if needed.

Travis test failing

Thanks for this good package.
However, the Travis builds are currently failing. Can we fix this?
Thanks.

Complex XML Response

Hi, I've been trying to parse an answer and I still can't get it right.

I have tried in different ways, which I believe closer has been the structure provided by this tool (https://www.onlinetool.io/xmltogo/)

I need to be able to extract indexDateString and value

Can you advise me on where I am failing?

Error obtained: xml.Unmarshal error: EOF

Try 1

type GetSeriesResponse struct {
	XMLName         xml.Name `xml:"GetSeriesResponse"`
	Text            string   `xml:",chardata"`
	Xmlns           string   `xml:"xmlns,attr"`
	GetSeriesResult struct {
		Text   string `xml:",chardata"`
		Series struct {
			Text       string `xml:",chardata"`
			FameSeries struct {
				Text string `xml:",chardata"`
				Obs  []struct {
					Text            string `xml:",chardata"`
					Xmlns           string `xml:"xmlns,attr"`
					IndexDateString string `xml:"indexDateString"`
					StatusCode      string `xml:"statusCode"`
					Value           string `xml:"value"`
				} `xml:"obs"`
			} `xml:"fameSeries"`
		} `xml:"Series"`
	} `xml:"GetSeriesResult"`
} 

Try 2

type GetSeriesResponse struct {
	GetSeriesResult string `xml:"GetSeriesResult"`
}

type GetSeriesResult struct {
	XMLName xml.Name `xml:"GetSeriesResult"`
	Text    string   `xml:",chardata"`
	Series  struct {
		Text       string `xml:",chardata"`
		FameSeries struct {
			Text string `xml:",chardata"`
			Obs  []struct {
				Text            string `xml:",chardata"`
				Xmlns           string `xml:"xmlns,attr"`
				IndexDateString string `xml:"indexDateString"`
				StatusCode      string `xml:"statusCode"`
				Value           string `xml:"value"`
			} `xml:"obs"`
		} `xml:"fameSeries"`
	} `xml:"Series"`
}

Response

<GetSeriesResponse xmlns="http://bancocentral.org/">
            <GetSeriesResult>
                <Series>
                    <fameSeries>
                        <obs xmlns="">
                            <indexDateString>07-12-2020</indexDateString>
                            <statusCode>OK</statusCode>
                            <value>3.5877</value>
                        </obs>
                        <obs xmlns="">
                            <indexDateString>08-12-2020</indexDateString>
                            <statusCode>OK</statusCode>
                            <value>NaN</value>
                        </obs>
                        <obs xmlns="">
                            <indexDateString>09-12-2020</indexDateString>
                            <statusCode>OK</statusCode>
                            <value>3.6025</value>
                        </obs>
                        <obs xmlns="">
                            <indexDateString>10-12-2020</indexDateString>
                            <statusCode>OK</statusCode>
                            <value>3.6045</value>
                        </obs>
                        <obs xmlns="">
                            <indexDateString>11-12-2020</indexDateString>
                            <statusCode>OK</statusCode>
                            <value>3.5969</value>
                        </obs>
                        <obs xmlns="">
                            <indexDateString>12-12-2020</indexDateString>
                            <statusCode>OK</statusCode>
                            <value>NaN</value>
                        </obs>
                        <obs xmlns="">
                            <indexDateString>13-12-2020</indexDateString>
                            <statusCode>OK</statusCode>
                            <value>NaN</value>
                        </obs>
                        <obs xmlns="">
                            <indexDateString>14-12-2020</indexDateString>
                            <statusCode>OK</statusCode>
                            <value>3.5968</value>
                        </obs>
                        <obs xmlns="">
                            <indexDateString>15-12-2020</indexDateString>
                            <statusCode>OK</statusCode>
                            <value>3.5868</value>
                        </obs>
                    </fameSeries>
                </Series>
            </GetSeriesResult>
        </GetSeriesResponse>

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!

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{} ?

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. :)

How to use array of params?

Hello,

I'm looking for a way to send params with an array of strings but can't figure out how.

the struct I'm looking for would be the equivalent to

    <SaveDoc xmlns="http://localhost/">
      <privKey>string</privKey>
      <Codigo>string</Codigo>
      <CodigoPrivado>string</CodigoPrivado>
      <Nif>string</Nif>
      <Artigos>
        <Linhas>
          <Artigo>string</Artigo>
          <Quantidade>double</Quantidade>
          <Unidade>string</Unidade>
        </Linhas>
        <Linhas>
          <Artigo>string</Artigo>
          <Quantidade>double</Quantidade>
          <Unidade>string</Unidade>
        </Linhas>
      </Artigos>
    </SaveDoc>
  </soap:Body>

Any ideia?

Differentiate fault and response unmarshal error

In the current implementation, the response unmarhsal error is not differentiating the fault error and the response unmarshal error. Both errors are technically different. The client should be able to differentiate both the error to take action based on the type of the error.

Unmarhsal error:

expected element type <IngetResponse> but have <IngestResponse>

Fault error:

[soap:Server]: Qube.Mama.SoapException: The remote server returned an error: (550) File unavailable (e.g., file not found, no access).
The remote server returned an error: (550) File unavailable (e.g., file not found, no access).

Code Reference: https://github.com/tiaguinho/gosoap/blob/master/response.go#L16

How to use different SOAP version?

Hello all,

I'm trying to use this package to make a request to a SOAP resource.

The payload of the request generated by this package starts with the header:
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">

However the resource expects something looking like this, I believe SOAP 1.1 syntax:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">

Is there a way to define the schema used when instantiating the client to use the correct markup?

Bump tag

What about a bumping new tag (v1.4.5, ex)?
It is useful for go.mod of depended projects, using new commits (#76, ex).

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.