AnsweredAssumed Answered

Adding extern SOAP libray to WAB Custom Widget

Question asked by Gerard2020 on Jul 2, 2020
Latest reply on Aug 6, 2020 by raul.jimenezesri-es-esridist

I am trying to use `tinysoap` library (https://github.com/mhzed/tinysoap) in an Web AppBuilder Custom Widget. 

 

I am able to use this library in WebAppBuilder application, as I show on the following sample code (real code included in HTML file). All my functions are included in a class called `myClass` in `customLibrary.js` file. Most functions in `customLibrary.js` call `tinysoap` functions, and everything works well:

 

 <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="node_modules/tinysoap/tinysoap-browser-min.js"></script>

<script src="node_modules/lib/customLibrary.js"></script>
<script src="https://js.arcgis.com/4.15/"></script>
...
<script>
    var tinySoap = this.tinysoap;
    require([], function(){
        //code goes here
        myClass.myfunction(){...};
    });
</script>

 

Now I have to implement the same functionality in a Web AppBuilder Custom Widget.

I have had to modify javascript code from `customLibrary.js` class to `myModule.js`, and now I have this content (sample code):

 

# myModule.js

define([], function () {

var myModule = {};
const url = "http://example.com/wsdl?wsdl";

myModule.myFunction = function(userTxtValue, callback) {
  if (userTxtValue){
   console.log('1. myModule.myFunction:', userTxtValue);

   var args = {name: userTxtValue};
   tinySoap.createClient(url, function(err, client){
      client.soapClientFunction(args, function(err, result){
         return callback(result);
      });
   });
   }
};
return myModule;
});

# Widget.js
So, I have `Widget.js` file with reference to `myModule.js`, without problems, using in this way:

define(['./myModule'], function(customModule) {
   customModule.myFunction( userTxtValue, function(result) {
      console.log("widget.js, result:", result);
    });
});

Also, I have tried to insert in  init.js (its is not desirable situation) but it doesn't work

dojoConfig.packages = [{
name: "widgets",
location: window.path + "widgets"
}, {
   name: "jquery",
   location: "http://ajax.googleapis.com/ajax/libs/jquery/1.10.2",
   main: "jquery"
}, {
   name: "tinysoap",
   location: window.path + "widgets/myWidget/node_modules/tinysoap/lib",
   main: "soap"
},
...
}]

 

None of these test works.

So, what is the proper way to add `tinysoap` library to my widget?

Thank you in advance !

Outcomes