Encode the SOAP action element.
It should always have included this. It probably never worked properly before, except for servers that didn't require arguments or the action element.
This commit is contained in:
parent
3a950ed088
commit
5c55e50548
14
soap/soap.go
14
soap/soap.go
@ -13,7 +13,7 @@ import (
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
soapEncodingStyle = "http://schemas.xmlsoap.org/soap/encoding/"
|
soapEncodingStyle = "http://schemas.xmlsoap.org/soap/encoding/"
|
||||||
soapPrefix = `<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body>`
|
soapPrefix = `<?xml version="1.0" encoding="utf-8"?><s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body>`
|
||||||
soapSuffix = `</s:Body></s:Envelope>`
|
soapSuffix = `</s:Body></s:Envelope>`
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -30,7 +30,7 @@ func NewSOAPClient(endpointURL url.URL) *SOAPClient {
|
|||||||
|
|
||||||
// PerformSOAPAction makes a SOAP request, with the given action.
|
// PerformSOAPAction makes a SOAP request, with the given action.
|
||||||
func (client *SOAPClient) PerformAction(actionNamespace, actionName string, inAction interface{}, outAction interface{}) error {
|
func (client *SOAPClient) PerformAction(actionNamespace, actionName string, inAction interface{}, outAction interface{}) error {
|
||||||
requestBytes, err := encodeRequestAction(inAction)
|
requestBytes, err := encodeRequestAction(actionNamespace, actionName, inAction)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -85,15 +85,23 @@ func newSOAPEnvelope() *soapEnvelope {
|
|||||||
// 500s for requests where the outer default xmlns is set to the SOAP
|
// 500s for requests where the outer default xmlns is set to the SOAP
|
||||||
// namespace, and then reassigning the default namespace within that to the
|
// namespace, and then reassigning the default namespace within that to the
|
||||||
// service namespace. Hand-coding the outer XML to work-around this.
|
// service namespace. Hand-coding the outer XML to work-around this.
|
||||||
func encodeRequestAction(inAction interface{}) ([]byte, error) {
|
func encodeRequestAction(actionNamespace, actionName string, inAction interface{}) ([]byte, error) {
|
||||||
requestBuf := new(bytes.Buffer)
|
requestBuf := new(bytes.Buffer)
|
||||||
requestBuf.WriteString(soapPrefix)
|
requestBuf.WriteString(soapPrefix)
|
||||||
|
requestBuf.WriteString(`<u:`)
|
||||||
|
xml.EscapeText(requestBuf, []byte(actionName))
|
||||||
|
requestBuf.WriteString(` xmlns:u="`)
|
||||||
|
xml.EscapeText(requestBuf, []byte(actionNamespace))
|
||||||
|
requestBuf.WriteString(`">`)
|
||||||
if inAction != nil {
|
if inAction != nil {
|
||||||
requestEnc := xml.NewEncoder(requestBuf)
|
requestEnc := xml.NewEncoder(requestBuf)
|
||||||
if err := requestEnc.Encode(inAction); err != nil {
|
if err := requestEnc.Encode(inAction); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
requestBuf.WriteString(`</u:`)
|
||||||
|
xml.EscapeText(requestBuf, []byte(actionName))
|
||||||
|
requestBuf.WriteString(`>`)
|
||||||
requestBuf.WriteString(soapSuffix)
|
requestBuf.WriteString(soapSuffix)
|
||||||
return requestBuf.Bytes(), nil
|
return requestBuf.Bytes(), nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user