Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wsdl2go issues #65

Closed
Fank opened this issue Dec 14, 2017 · 6 comments
Closed

wsdl2go issues #65

Fank opened this issue Dec 14, 2017 · 6 comments

Comments

@Fank
Copy link
Contributor

Fank commented Dec 14, 2017

wsdl: http://soap.brokerbin.com/brokerbin_search/search.wsdl

Cut from generated go file:

// NewHandleSearchPort creates an initializes a HandleSearchPort.
func NewHandleSearchPort(cli *soap.Client) HandleSearchPort {
	return &handleSearchPort{cli}
}

// HandleSearchPort was auto-generated from WSDL
// and defines interface for the remote service. Useful for testing.
type HandleSearchPort interface {
}

// handleSearchPort implements the HandleSearchPort interface.
type handleSearchPort struct {
	cli *soap.Client
}

// Authenticate was auto-generated from WSDL.
func (p *handleSearchPort) Authenticate(α string, reqPassword string, reqOptions interface{}) (β string, err error) {
	γ := struct {
		XMLName xml.Name `xml:"Envelope"`
		Body    struct {
			M string `xml:"string"`
		}
	}{}
	if err = p.cli.RoundTripWithAction("Authenticate", α, &γ); err != nil {
		return "", err
	}
	return γ.Body.M, nil
}

// Search was auto-generated from WSDL.
func (p *handleSearchPort) Search(α interface{}, reqOptions interface{}) (β interface{}, err error) {
	γ := struct {
		XMLName xml.Name `xml:"Envelope"`
		Body    struct {
			M interface{} `xml:"interface{}"`
		}
	}{}
	if err = p.cli.RoundTripWithAction("Search", α, &γ); err != nil {
		return nil, err
	}
	return γ.Body.M, nil
}

HandleSearchPort is empty which causes:
image

Authenticate and Search will only transport first parameter e.g. for Authenticate:

POST / HTTP/1.1
Host: localhost
Content-Type: text/xml
Soapaction: urn:HandleSearch/Authenticate

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="urn:HandleSearch" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><SOAP-ENV:Body><Message>foo</Message></SOAP-ENV:Body></SOAP-ENV:Envelope>

Expected or needed request for linked wsdl above:

POST / HTTP/1.1
Host: localhost
Content-Type: text/xml
Soapaction: urn:HandleSearch/Authenticate

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xmlns:tns="urn:HandleSearch">
	<soap:Body>
		<tns:Authenticate>
			<reqUsername>foo</reqUsername>
			<reqPassword>:)</reqPassword>
		</tns:Authenticate>
	</soap:Body>
</soap:Envelope>

The main difference is that Message (in first) is replaced by a "message" tns:Authenticate (in second) which also contains reqUsername (aka α) and reqPassword (aka reqPassword).

Got same issues for other wsdl files, but this is the easiest example, to explain.

@Fank
Copy link
Contributor Author

Fank commented Dec 15, 2017

Working example one:

type AuthenticateResponse struct {
	ResSession string `xml:"resSession,omitempty" json:"resSession,omitempty" yaml:"resSession,omitempty"`
}

func (p *handleSearchPort) Authenticate(reqUsername string, reqPassword string, reqOptions interface{}) (β AuthenticateResponse, err error) {
	α := struct {
		XMLName     xml.Name    `xml:"tns:Authenticate"`
		ReqUsername string      `xml:"reqUsername,omitempty"`
		ReqPassword string      `xml:"reqPassword,omitempty"`
		ReqOptions  interface{} `xml:"reqOptions,omitempty"`
	}{
		ReqUsername: reqUsername,
		ReqPassword: reqPassword,
		ReqOptions:  reqOptions,
	}
	γ := struct {
		XMLName xml.Name `xml:"Envelope"`
		Body    struct {
			M AuthenticateResponse `xml:"AuthenticateResponse"`
		}
	}{}
	if err = p.cli.RoundTripWithAction("Authenticate", α, &γ); err != nil {
		return AuthenticateResponse{}, err
	}
	return γ.Body.M, nil
}

Working example two (which i prefer):

type AuthenticateRequest struct {
	XMLName     xml.Name    `xml:"tns:Authenticate"`
	ReqUsername string      `xml:"reqUsername,omitempty" json:"reqUsername,omitempty" yaml:"reqUsername,omitempty"`
	ReqPassword string      `xml:"reqPassword,omitempty" json:"reqPassword,omitempty" yaml:"reqPassword,omitempty"`
	ReqOptions  interface{} `xml:"reqOptions,omitempty" json:"reqOptions,omitempty" yaml:"reqOptions,omitempty"`
}

type AuthenticateResponse struct {
	ResSession string `xml:"resSession,omitempty" json:"resSession,omitempty" yaml:"resSession,omitempty"`
}

func (p *handleSearchPort) Authenticate(α AuthenticateRequest) (β AuthenticateResponse, err error) {
	γ := struct {
		XMLName xml.Name `xml:"Envelope"`
		Body    struct {
			M AuthenticateResponse `xml:"AuthenticateResponse"`
		}
	}{}
	if err = p.cli.RoundTripWithAction("Authenticate", α, &γ); err != nil {
		return AuthenticateResponse{}, err
	}
	return γ.Body.M, nil
}

I don't know anything about soap or xml communication in general, i only try to rebuild the communication from a existing perl application to go.
It would be nice if the wsdl2go would generate such code, but don't know if it will break other communications.

@fiorix
Copy link
Owner

fiorix commented Dec 16, 2017

Hey, this is what the header field in soap.Client is for.

When you instantiate your Client, you can set its Header to any struct that you want, for example your AuthenticateRequest. When a Header is present, it'll be included in all requests issued by the client.

@fiorix fiorix closed this as completed Dec 16, 2017
@Fank
Copy link
Contributor Author

Fank commented Dec 18, 2017

I think you missunderstood the issue, i was talking about the wsdl2go converting.
Because the body which was generated is not as expected, there is no issue with the header, there are issues with the body.

@fiorix fiorix reopened this Dec 18, 2017
@fiorix
Copy link
Owner

fiorix commented Dec 18, 2017

Oops. This is definitely something else.

@fiorix
Copy link
Owner

fiorix commented Dec 21, 2017

Tracking in #74.

@fiorix fiorix closed this as completed Dec 21, 2017
@kernle32dll
Copy link
Contributor

@Fank @fiorix I figured out whats the problem (at least for the wrong structure - for parameters not beeing used see #74 ). The problem is, that wsdl2go does not correctly honor the style="rpc" part in the soap:binding. The rpc style means, that parameters of a operation have to be wrapped by an XML element of the operation name.

See here for examples and implications:
https://www.ibm.com/developerworks/library/ws-whichwsdl/

I will issue a PR to fix this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants