forked from alex-arce/gosoap
-
Notifications
You must be signed in to change notification settings - Fork 3
/
doc.go
71 lines (57 loc) · 2.01 KB
/
doc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package soap
/*
Package soap provides primitives for operating on a SOAP-based web service. The library supports encrypting the SOAP request using the WS-Security x.509 protocol, enabling SOAP calls against secured web services.
A basic example usage would be as follows:
```
include (
"context"
"github.com/m29h/gosoap"
)
main() {
var (
certFile = flag.String("cert", "", "A PEM encoded cert file")
keyFile = flag.String("key", "", "A PEM encoded key file")
)
flag.Parse()
wsseInfo, authErr := soap.NewWSSEAuthInfo(*certFile, *keyFile)
if authErr != nil {
fmt.Printf("Auth error: %s\n", authErr.Error())
return
}
// Setup your request structure
// ...
//
// Create the SOAP request
// call.action is the SOAP action (i.e. method name)
// service.url is the fully qualified path to the SOAP endpoint
// call.requestData is the structure mapping to the SOAP request
// call.ResponseData is an output structure mapping to the SOAP response
// call.FaultData is an output structure mapping to the SOAP fault details
soapReq := soap.NewRequest(call.action, service.url, call.requestData, call.ResponseData, call.FaultData)
// Potentially add custom headers
soapReq.AddHeader(...)
soapReq.AddHeader(...)
// Sign the request
soapReq.SignWith(wsseInfo)
// Create the SOAP client
soapClient := soap.NewClient(&http.Client{})
// Make the request
soapResp, err := soapClient.Do(context.Background(), soapReq)
if err != nil {
fmt.Printf("Unable to validate: %s\n", err.Error())
return
} else if soapResp.StatusCode != http.StatusOK {
fmt.Printf("Unable to validate (status code invalid): %d\n", soapResp.StatusCode)
return
} else if soapResp.Fault() != nil {
fmt.Printf("SOAP fault experienced during call: %s\n", soapResp.Fault().Error())
// We can access the FaultData struct passed in for a type-safe way to get at the details.
return
}
// Now we can handle the response itself.
// Do our custom processing
// ...
//
fmt.Printf("Done!\n")
}
*/