Add a Datasource

soap-calculator-add-data-source

We will add a Datasource to the LB4 application using the CLI. This stepwill not only create two files under the src/datasources, but also will installthe necessary connector and its dependencies for us. Let’s run the followingcommand inside our application directory.

  1. lb4 datasource calculator

Select a Connector type

We specified calculator as the name for our Datasource. Now CLI is askingus to select a connector type. Let’s choose the SOAP webservices (supportedby StrongLoop) connector from the list as shown below:

  1. ? Select the connector for calculator:
  2. Oracle (supported by StrongLoop)
  3. Microsoft SQL (supported by StrongLoop)
  4. REST services (supported by StrongLoop)
  5. SOAP webservices (supported by StrongLoop)
  6. Couchbase (provided by community)
  7. Neo4j (provided by community)
  8. Kafka (provided by community)
  9. (Move up and down to reveal more choices)

Specify the SOAP web service endpoint

Now we must tell CLI about the full URL path for our web service. In thiscase, let’s type https://calculator-webservice.mybluemix.net/calculator forthe URL and https://calculator-webservice.mybluemix.net/calculator?wsdl forthe WSDL path.

  1. ? Select the connector for calculator: SOAP webservices (supported by StrongLoop)
  2. ? URL to the SOAP web service endpoint: https://calculator-webservice.mybluemix.net/calculator
  3. ? HTTP URL or local file system path to the WSDL file: https://calculator-webservice.mybluemix.net/calculator?wsdl

Enabling expose REST API operations

Following the URL endpoints, we need to tell CLI that we are going to exposethe methods available in the SOAP web service as REST end points, type Y andleave blank the Maps WSDL binding operations to Node.js methods for now, as wewill add them manually in the Datasource configuration file.

  1. ? Expose operations as REST APIs: Yes
  2. ? Maps WSDL binding operations to Node.js methods:

You will see the following message in the screen. Note that CLI created aJSON configuration file and a .ts file with the Datasource name and added anentry inside the index.ts file.

  1. create src/datasources/calculator.datasource.json
  2. create src/datasources/calculator.datasource.ts
  3. update src/datasources/index.ts
  4. Datasource Calculator was created in src/datasources/

Binding WSDL operations to Node.js methods

The SOAP web service is exposing 4 operations, all of them share the sameSOAP port, which in this case is CalculatorSoap and the serviceCalculator. The operations are:

  • multiply
  • add
  • subtract
  • divideWe need to configure in the Datasource JSON file, the corresponding Node.jsmethods for these remote SOAP operations. For simplicity, we will name theNode.js methods the same as their SOAP operation counterparts.

For example, having the following property, we are configuring the SOAP operatorMultiply that is reached in the port CalculatorSoap and Calculator service tobind the Node.js method Multiply.

  1. "operations": {
  2. "multiply": {
  3. "service": "CalculatorService",
  4. "port": "CalculatorPort",
  5. "operation": "multiply"
  6. }
  7. }

Edit the file src/datasources/calculator.datasource.json and add the followingconfiguration after the remoteEnabled: true, property as follows:

src/datasources/calculator.datasource.json

  1. "operations": {
  2. "multiply": {
  3. "service": "CalculatorService",
  4. "port": "CalculatorPort",
  5. "operation": "Multiply"
  6. },
  7. "add": {
  8. "service": "CalculatorService",
  9. "port": "CalculatorPort",
  10. "operation": "Add"
  11. },
  12. "subtract": {
  13. "service": "CalculatorService",
  14. "port": "CalculatorPort",
  15. "operation": "Subtract"
  16. },
  17. "divide": {
  18. "service": "CalculatorService",
  19. "port": "CalculatorPort",
  20. "operation": "Divide"
  21. }
  22. }

Navigation

Previous step:Create your app scaffolding

Next step: Add a Service