15 Replies Latest reply on Oct 19, 2017 2:30 AM by friedel RSS
    friedel Newbie

    SOAP based webservice

    Maybe someone can help me. We have an soap based webservice to get some properties/attribues form our windchill server.

     

    The problem now is can anybody show us an example service how to call a webservice with an own created service in Thingworx.

     

    We want to creat an service that takes the object id and calls the webservice with this object id to get the related attributes to this objects. The result of this service should be an info table, that we can bound the data to a dynamic property display.

     

    I have no idea what the service should look like to call the webservice. Maybe somebody can give an example.

     

     

    Regards Felix

      • Re: SOAP based webservice
        carko Creator

        Hello, Felix.

         

        We're actually having an internal discussion with the team about the question of using SOAP within ThingWorx. As we get more information on this we'll keep you updated with how your use case would be best handled.

         

         

        Thank you,

         

        -- Craig A.

        • Re: SOAP based webservice
          carlesc Heavyweight Champ

          Hi Felix/Craig,

           

          You just need to use built-in GET, POST.. and XML parsing TW features, here you have an answer on the community abou this:

          How to consume SOAP Web service in thingworx?

           

          Gest Regards,

          Carles.

            • Re: SOAP based webservice
              friedel Newbie

              So now I understand how to call a SOAP webservice.

               

              This brought me directly to an new Problem.

               

              If I use your way to parse the XMLList (which I get as response) to string

               

                   var returnXMLString = resultXML.*::Body.*::remoteSoapServiceNameResponse.return

                   var str = ""+returnXMLString[0].toString().replace(/\n/gi,""); 


              It works fine and I can view the whole XML as a string. The same I can see if I call the webservice in SoapUI.


              But I need this list as an info table. The problem is if I want to parse the XMLList I get this error:


                   Execution error in service script [LEONI.Leoogle.MasterThing getCustomerParts] : null

               

              This is my code to do that:

               

               

                   var params2 = {

                     infoTableName : "Info Table",

                     dataShapeName : "Test.Datashape"

                   };

               

                   // CreateInfoTableFromDataShape(infoTableName:STRING("InfoTable"), dataShapeName:STRING):INFOTABLE(StringDataShape)

                   var result = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape(params2);

               

               

                   for each (var tag in resultXML.*::output) { 

                       var newRow = new Object(); 

                       newRow.supplierPartObid = tag.*::supplierPartObid; 

                       newRow.supplierPartNumber=tag.*::supplierPartNumber;

                       newRow.supplierPartName=tag.*::supplierPartName; 

                   

                       result.AddRow(newRow); 

                   } 

               

              (resultXML is the response of the PostXML snippet)

               

              If I try to use the FromXML snippet I get the error can not cast from XMLList to XML.

               

              Maybe you know what to do

               

              Regards Felix

                • Re: SOAP based webservice
                  carlesc Heavyweight Champ

                  Hi Felix,

                   

                  Don't ask me why, but on my code to convert back the str to an XML object I set back the string to an XML in memory only property:

                   

                  me.myXMLProperty = str;

                   

                  And to iterate over XML "rows":

                   

                  var rows = me.myXMLProperty.*;

                  var nRows = rows.length();

                  for (var i=0;i<nRows;i++) {

                      entry = rows[i];

                     newRow = {}

                      newRow.supplierPartObid = entry.supplierPartObid;

                  ...

                  }

                    • Re: SOAP based webservice
                      friedel Newbie

                      If I try that I get another error:

                       

                       

                      Error executing service

                       

                      Wrapped java.lang.Exception: Property : [myXMLProperty] not found on Test.MasterThing Cause: Property : [myXMLProperty] not found on Test.MasterThing

                       

                       

                      I thougt this is just an local XML parameter.

                       

                      Should I implement this service at another Thing?

                        • Re: SOAP based webservice
                          carlesc Heavyweight Champ

                          No myXMLProperty it's a Thing's XML property, on your case create it on Test.MasterThing Thing ( XML, not Persistent )

                            • Re: SOAP based webservice
                              friedel Newbie

                              Ok thank you for that information.

                               

                              I changed it. An now this is my result.

                               

                              Error.JPG

                               

                              if i remove this command:

                               

                                   //var str = ""+returnXMLString[0].toString().replace(/\n/gi,"");

                               

                              and try the same with the parameter returnXMLString:

                               

                                   var str = resultXML.*::Body.*::getCustomerPartsResponse.return; 

                                   //var str = ""+returnXMLString[0].toString().replace(/\n/gi,""); 

                               

                                   me.myXMLProperty = str;

                                   var rows = me.myXMLProperty.*;

                                   var nRows = rows.length();

                                   for (var i=0;i<nRows;i++) {

                                       entry = rows[i];

                                      newRow = {}

                                       newRow.supplierPartObid = entry.supplierPartObid;

                                       newRow.supplierPartNumber = entry.supplierPartNumber;

                                       newRow.supplierPartName = entry.supplierPartName;     

                                   }

                               

                              I get this error again:

                              Error 2.JPG

                               

                              I have no idea why I can view the XML as string but can´t work with it

                               

                                   var result = resultXML.*::Body.*::getCustomerPartsResponse.return; 

                                   //var str = ""+returnXMLString[0].toString().replace(/\n/gi,""); 

                               

                                   //me.myXMLProperty = str;

                                   //var rows = me.myXMLProperty.*;

                                   //var nRows = rows.length();

                                   //for (var i=0;i<nRows;i++) {

                                      // entry = rows[i];

                                      //newRow = {}

                                      // newRow.supplierPartObid = entry.supplierPartObid;

                                      // newRow.supplierPartNumber = entry.supplierPartNumber;

                                      // newRow.supplierPartName = entry.supplierPartName;     

                                   //}

                               

                              This shows me the whole XML:

                               

                              resultXML.JPG

                               

                              Regards Felix

                                • Re: SOAP based webservice
                                  carlesc Heavyweight Champ

                                  For what I see on Results your XML Structure it's something like this:

                                   

                                  return

                                  - Name

                                  - Elements *

                                  -- Element

                                  --- Attributes *

                                  ---- Attribute

                                  ----- Name

                                  ----- Value

                                   

                                   

                                  Then you must access this structure and for what I see on your code you don't try to access this structure.

                                    • Re: SOAP based webservice
                                      friedel Newbie

                                      I tried it but it won´t work.

                                       

                                      My problem is that Elements and Attributes are arrays.

                                       

                                      I´m not sure how this access to the structure should look like.

                                       

                                      because i need one for each - loop for the elements to add a new row and another for each - loop to add the value as new entry to my infotable.

                                       

                                      Regards Felix

                                        • Re: SOAP based webservice
                                          carlesc Heavyweight Champ

                                          Then you will need one additional inner loop.

                                            • Re: SOAP based webservice
                                              friedel Newbie

                                              Can you give me an example, please ??

                                               

                                              I tried so many different ways, but everytime I get a new error.

                                               

                                              I know how to go through an array my problem is how to call these elements/objects in my javascript code.

                                                • Re: SOAP based webservice
                                                  carlesc Heavyweight Champ

                                                  Can you send me the XML text answer and I will try ( of course remove confidential data )

                                                    • Re: SOAP based webservice
                                                      carlesc Heavyweight Champ

                                                      Hi, no problem to read it, here you have the code:

                                                       

                                                      // -- me.data it's a STRING property that contains the XML you passed me
                                                      // -- I had to do some cleanup in order to re-create a correct XML document that's
                                                      // -- accepted by new XML();
                                                      var str =  me.data.replace('xsi:type="wc:INFOENGINE_GROUP"',"","gi");
                                                      str =  str.replace(/SOAP\-ENC\:arrayType=\"wc:INFOENGINE_ATTRIBUTE\[12\]\"/gi,"");
                                                      str =  str.replace(/SOAP\-ENC\:arrayType=\"wc:INFOENGINE_ELEMENT\[10\]\"/gi,"");
                                                      str =  str.replace(/SOAP\-ENC\:arrayType=\"wc:INFOENGINE_ATTRIBUTE\[3\]\"/gi,"");
                                                      str =  str.replace(/xsi:type=\"xsd:int\"/gi,"");
                                                      
                                                      
                                                      // -- Re-create XML document
                                                      var data = new XML(str);
                                                      var result = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape({
                                                      infoTableName : "InfoTable",
                                                      dataShapeName : "TestXMLReadDS" // -- Your DATASHAPE NAME
                                                      });
                                                      for each (var element in data.Elements.*) {
                                                          var obj = {};
                                                          for each(var attribute in element.Attributes.*) obj[attribute.Name] = attribute.Value;
                                                          result.AddRow(obj);
                                                      }