@@ -5,12 +5,12 @@ var serverTmpl = `
55var WSDLUndefinedError = errors.New("Server was unable to process request. --> Object reference not set to an instance of an object.")
66
77type SOAPEnvelopeRequest struct {
8- XMLName xml.Name ` + "`" + `xml:"http://schemas.xmlsoap.org/soap/envelope/ Envelope"` + "`" + `
8+ XMLName xml.Name ` + "`" + `xml:"Envelope"` + "`" + `
99 Body SOAPBodyRequest
1010}
1111
1212type SOAPBodyRequest struct {
13- XMLName xml.Name ` + "`" + `xml:"http://schemas.xmlsoap.org/soap/envelope/ Body"` + "`" + `
13+ XMLName xml.Name ` + "`" + `xml:"Body"` + "`" + `
1414 {{range .}}
1515 {{range .Operations}}
1616 {{$requestType := findType .Input.Message | replaceReservedWords | makePublic}} ` + `
@@ -36,6 +36,14 @@ func NewSOAPEnvelopResponse() *SOAPEnvelopeResponse {
3636 }
3737}
3838
39+ func NewSOAP12EnvelopResponse() *SOAPEnvelopeResponse {
40+ return &SOAPEnvelopeResponse{
41+ PrefixSoap: "http://www.w3.org/2003/05/soap-envelope",
42+ PrefixXsd: "http://www.w3.org/2001/XMLSchema",
43+ PrefixXsi: "http://www.w3.org/2001/XMLSchema-instance",
44+ }
45+ }
46+
3947type Fault struct { ` + `
4048 XMLName xml.Name ` + "`" + `xml:"SOAP-ENV:Fault"` + "`" + `
4149 Space string ` + "`" + `xml:"xmlns:SOAP-ENV,omitempty,attr"` + "`" + `
@@ -73,7 +81,14 @@ func (service *SOAPBodyRequest) {{$requestType}}Func(request *{{$requestType}})
7381
7482
7583func (service *SOAPEnvelopeRequest) call(w http.ResponseWriter, r *http.Request) {
76- w.Header().Add("Content-Type", "text/xml; charset=utf-8")
84+ var isSOAP12 bool
85+ if strings.Index(r.Header.Get("Content-Type"), "application/soap+xml") >= 0 {
86+ w.Header().Add("Content-Type", "application/soap+xml; charset=utf-8")
87+ isSOAP12 = true
88+ } else {
89+ w.Header().Add("Content-Type", "text/xml; charset=utf-8")
90+ }
91+
7792 val := reflect.ValueOf(&service.Body).Elem()
7893 n := val.NumField()
7994 var field reflect.Value
@@ -85,23 +100,25 @@ func (service *SOAPEnvelopeRequest) call(w http.ResponseWriter, r *http.Request)
85100 return
86101 }
87102
88- resp := NewSOAPEnvelopResponse()
103+ var resp *SOAPEnvelopeResponse
104+
105+ if isSOAP12 {
106+ resp = NewSOAP12EnvelopResponse()
107+ } else {
108+ resp = NewSOAPEnvelopResponse()
109+ }
110+
89111 defer func() {
90112 if r := recover(); r != nil {
91113 resp.Body.Fault = &Fault{}
92- resp.Body.Fault.Space = "http://schemas.xmlsoap.org/soap/envelope/"
114+ resp.Body.Fault.Space = resp.PrefixSoap
93115 resp.Body.Fault.Code = "soap:Server"
94116 resp.Body.Fault.Detail = fmt.Sprintf("%v", r)
95117 resp.Body.Fault.String = fmt.Sprintf("%v", r)
96118 }
97119 xml.NewEncoder(w).Encode(resp)
98120 }()
99121
100- header := r.Header.Get("Content-Type")
101- if strings.Index(header, "application/soap+xml") >= 0 {
102- panic("Could not find an appropriate Transport Binding to invoke.")
103- }
104-
105122 err := xml.NewDecoder(r.Body).Decode(service)
106123 if err != nil {
107124 panic(err)
@@ -125,6 +142,11 @@ func (service *SOAPEnvelopeRequest) call(w http.ResponseWriter, r *http.Request)
125142 if !find {
126143 panic(WSDLUndefinedError)
127144 } else {
145+ if isSOAP12 {
146+ defer func() {
147+ r.Header.Set("Soapaction", fmt.Sprintf("SOAP12: %s", name))
148+ }()
149+ }
128150 m := val.Addr().MethodByName(name + "Func")
129151 if !m.IsValid() {
130152 panic(WSDLUndefinedError)
@@ -137,7 +159,6 @@ func (service *SOAPEnvelopeRequest) call(w http.ResponseWriter, r *http.Request)
137159 panic(vals[1].Interface())
138160 }
139161 }
140-
141162}
142163
143164func Endpoint(w http.ResponseWriter, r *http.Request) {
0 commit comments