cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - If community subscription notifications are filling up your inbox you can set up a daily digest and get all your notifications in a single email. X

SOAP based webservice

FelixRie
4-Participant

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

1 ACCEPTED SOLUTION

Accepted Solutions

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

}

View solution in original post

15 REPLIES 15
CRArko
17-Peridot
(To:FelixRie)

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.

FelixRie
4-Participant
(To:CRArko)

Hello Craig,

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

Thank you

Felix

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.

FelixRie
4-Participant
(To:CarlesColl)

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

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;

...

}

FelixRie
4-Participant
(To:CarlesColl)

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?

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

FelixRie
4-Participant
(To:CarlesColl)

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;

        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;

        //newRow = {}

        // newRow.supplierPartObid = entry.supplierPartObid;

        // newRow.supplierPartNumber = entry.supplierPartNumber;

        // newRow.supplierPartName = entry.supplierPartName;     

     //}

This shows me the whole XML:

resultXML.JPG

Regards Felix

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.

FelixRie
4-Participant
(To:CarlesColl)

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

Then you will need one additional inner loop.

FelixRie
4-Participant
(To:CarlesColl)

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.

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

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

}

FelixRie
4-Participant
(To:CarlesColl)

Thank you very much it works.

You saved my day. The best guy ever.

Regards Felix

Top Tags