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

Command payload wants a xmlns attribute. #123

Open
bweston92 opened this issue May 18, 2019 · 2 comments
Open

Command payload wants a xmlns attribute. #123

bweston92 opened this issue May 18, 2019 · 2 comments

Comments

@bweston92
Copy link

I have an issue where the tag after the <soap:Body> tag requires a xmlns attribute.

Currently the request begins like the following:

<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope
    xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:ns="https://api.twenty7tec.com/sourcing.svc?wsdl"
    xmlns:tns="https://api.twenty7tec.com/sourcing.svc?wsdl"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>
   <soap:Body>
      <RunSource>

However the following is required

<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope 
    xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>
   <soap:Body>
      <RunSource xmlns="http://tempuri.org/">

My current work around:

		Pre: func(r *http.Request) {
			out, _ := ioutil.ReadAll(r.Body)
			_ = r.Body.Close()
			newBody := bytes.ReplaceAll(out, []byte("<RunSource>"), []byte("<RunSource xmlns=\"http://tempuri.org/\">"))
			r.ContentLength = int64(len(newBody))
			r.Body = ioutil.NopCloser(bytes.NewReader(newBody))
		},

Is there any other way of doing this that would work on requests that are available?

@cusspvz
Copy link

cusspvz commented Mar 19, 2020

@fiorix the simplest solution is to add this on all the generated command types:

// Command
type Command struct {
+	ActionNamespace string  `xml:"xmlns,attr,omitempty"`
	CommandArg    *string `xml:"CommandArg,omitempty" json:"CommandArg,omitempty" yaml:"CommandArg,omitempty"`
}

This way, the user can just set the fields they want when calling the command.

example:

	res, err := Client.Command(&smsprows.Command{
+		ActionNamespace: "https://mosano.eu",
		CommandArg:      true,
	})

@cusspvz
Copy link

cusspvz commented Mar 19, 2020

Or, you can also add a struct that gets extended by all the Action structs so the users can set a config file on the side with all the attributes they want to set. :D

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