Skip to main content
1-Visitor
October 13, 2017
Solved

SOAP based webservice

  • October 13, 2017
  • 15 replies
  • 7135 views

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

Best answer by CarlesColl

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);

}

15 replies

5-Regular Member
October 13, 2017

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.

FelixRie1-VisitorAuthor
1-Visitor
October 16, 2017

Hello Craig,

Thanks for your reply. Please let me know if there are some changes.

Thank you

Felix

1-Visitor
October 16, 2017

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.

FelixRie1-VisitorAuthor
1-Visitor
October 17, 2017

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

1-Visitor
October 17, 2017

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;

   newRow = {}

    newRow.supplierPartObid = entry.supplierPartObid;

...

}