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

Error unmarshalling responses from VirtualBox vboxwebsrv #37

Closed
md5 opened this issue Sep 10, 2015 · 5 comments
Closed

Error unmarshalling responses from VirtualBox vboxwebsrv #37

md5 opened this issue Sep 10, 2015 · 5 comments

Comments

@md5
Copy link
Contributor

md5 commented Sep 10, 2015

I'm trying to use gowsdl to generate code to interface with VirtualBox's vboxwebsrv SOAP service, but I'm running into namespace issues.

My test code can be found here: https://github.com/md5/gowsdl-vboxwebsrv-test, including the generated service code, but the stripped-down test file looks like this:

package main

import (
    "./vboxwebsrv"

    "log"
    "os"
)

func main() {
    var addr string

    if len(os.Args) < 2 {
        addr = "http://127.0.0.1:18083"
    } else {
        addr = os.Args[1]
    }

    svc := vboxwebsrv.NewVboxPortType(addr, false, nil)
    vbox, err := svc.IWebsessionManagerlogon(&vboxwebsrv.IWebsessionManagerlogon{})
    if err != nil {
        log.Fatalln(err)
    }

    log.Printf("returnval=%s\n", vbox.Returnval)
}

When I run it with go run test.go, I get the following error:

$ go run test.go http://192.168.99.1:18083
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:vbox="http://www.virtualbox.org/"><SOAP-ENV:Body><vbox:IWebsessionManager_logonResponse><returnval>954ddf3e6d57d58b-000000000000000a</returnval></vbox:IWebsessionManager_logonResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>
2015/09/10 08:42:18 expected element <IWebsessionManager_logonResponse> in name space http://www.virtualbox.org/ but have vbox
exit status 1

After looking through the gowsdl code, it appears that the issue is that the <vbox:IWebsessionManager_logonResponse><returnval>954ddf3e6d57d58b-000000000000000a</returnval></vbox:IWebsessionManager_logonResponse> body is being unmarshalled by an instance of xml.Decoder that no longer has the xmlns:vbox="http://www.virtualbox.org/" namespace mapping.

Any advice you can provide here would be appreciated. It seems like gowsdl might need to use something lower level than xml.Unmarshal to allow the same xml.Decoder to decode the entire SOAP payload and maintain its namespace mappings.

Here's my Go version:

$ go version 
go version go1.5 darwin/amd64
@c4milo
Copy link
Member

c4milo commented Sep 10, 2015

Can you confirm if the issue is similar to the one described here? #17. My comment on it here: #17 (comment)

@md5
Copy link
Contributor Author

md5 commented Sep 10, 2015

@c4milo I think this is a different problem. In that case, the NRCS web service is rejecting the request created by gowsdl and returning a SOAP fault due to how the namespaces in the request are specified.

In my case, the problem is with unmarshalling the response returned by the web service. Specifically, the fact that the xmlns:vbox="http://www.virtualbox.org/" is declared on the Envelope means that when gowsdl goes to parse the innerxml of the Body tag, it doesn't have the namespace mapping available. This makes it think that vbox is an undeclared prefix when it parses respEnvelope.Body.Content here:

body := respEnvelope.Body.Content

@md5
Copy link
Contributor Author

md5 commented Sep 11, 2015

Looks like there's a proposal to expose the namespace bindings in the decoder: golang/go#12406

This could help with this issue, though it doesn't help with Go 1.5.

@md5
Copy link
Contributor Author

md5 commented Sep 11, 2015

I managed to write some code that I think does the right thing for dynamic unmarshalling: https://github.com/md5/gowsdl-vboxwebsrv-test/blob/0f89b3888adf2c3ccb06b69dceec39c669783e97/unmarshal.go

It's getting late for me here, but I may have some time in the next few days to try to work it into a PR for gowsdl. In the meantime, have a look.

Please bear in mind that I'm still learning Go, so I may have done some silly things here...

@c4milo
Copy link
Member

c4milo commented Sep 11, 2015

hey @md5, thanks for looking into this. I think you are definitely on the right track. We need to parse the whole response in one shoot so namespaces declared at the root of the document are considered.

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

2 participants