Back to Examples
- Binding patterns
- Typed binding pattern
- Wildcard binding pattern
- List binding patterns
- Rest binding pattern in list binding pattern
- Mapping binding pattern
- Rest binding pattern in mapping binding pattern
- Error binding pattern
- Rest binding pattern in error binding pattern
- Single use of typed binding patterns
- Single use of typed binding patterns with on fail clause
- Iterative use of typed binding patterns
- List binding pattern in match statement
- Mapping binding pattern in match statement
- Error binding pattern in match statement
- Query expressions
- Sort iterable objects
- Let clause
- Limit clause
- Join iterable objects
- Outer Join clause
- Query tables
- Create tables with a query
- Create maps with a query
- Create streams with a query
- On conflict clause
- Advanced conflict handling
- Iterate over XML with a query
- Nested query expressions
- Destructure records using a query
- Querying streams
- Aggregation
- JSON type
- Access JSON elements
- Access optional JSON elements
- Match statement with maps
- Convert from user-defined type to JSON
- Convert from table and XML to JSON
- Convert from JSON to user-defined type
- Cast JSON to user-defined type
- Resource method typing
- JSON numbers
- JSON to record
- JSON to record with projection
- JSONPath expressions
- Asynchronous function calls
- Named workers
- Sequence diagrams
- Wait for workers
- Strands
- Named worker return values
- Alternate wait
- Multiple wait
- Named workers and futures
- Inter-worker message passing
- Alternate receive
- Multiple receive
- Conditional send
- Inter-worker failure propagation
- Named worker with on fail clause
- Synchronize message passing
- Asynchronize message passing
- Flush
- Fork
SOAP client - Send/Receive
The soap
module provides APIs to connect to a SOAP endpoint that supports SOAP 1.1 or 1.2 versions. Users can specify the version when importing the soap
module. The sendReceive()
API will send a request to a SOAP endpoint and bind the response to one of the xml
or mime:Entity[]
data types determined by the user. The sendOnly()
API will fire and forget a SOAP request.
import ballerina/io;
import ballerina/soap.soap12;
xmlns "http://tempuri.org/" as quer;
public function main() returns error? {
int additionA = 37;
int additionB = 73;
// The SOAP 1.2 client connects to a live SOAP endpoint
// that executes basic arithmetic operations
soap12:Client soapClient = check new ("http://www.dneonline.com/calculator.asmx?WSDL");
// The SOAP envelope is constructed including necessary numerical values
// for the addition operation.
xml body = xml `<soap:Envelope
xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
soap:encodingStyle="http://www.w3.org/2003/05/soap-encoding">
<soap:Body>
<quer:Add xmlns:quer="http://tempuri.org/">
<quer:intA>${additionA}</quer:intA>
<quer:intB>${additionB}</quer:intB>
</quer:Add>
</soap:Body>
</soap:Envelope>`;
// `sendOnly()` fires and forgets a request.
check soapClient->sendOnly(body, "http://tempuri.org/Add");
// `sendReceive()` sends a request to a SOAP endpoint
// and receives the response in `xml` or `mime:Entity[]` format.
xml response = check soapClient->sendReceive(body, "http://tempuri.org/Add");
xml result = response/**/<quer:AddResult>/*;
io:println(string `Sum: ${additionA} + ${additionB} = `, result);
}
Run the program by executing the following command.
$ bal run soap_client_send_receive.balSum: 37 + 73 = 110
Related links
PreviousSASL authentication
NextSSL/TLS