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

SOAP based webservice

SOLVED
Highlighted
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

Tags (2)
1 ACCEPTED SOLUTION

Accepted Solutions

Re: SOAP based webservice

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

Re: SOAP based webservice

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

Hello Craig,

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

Thank you

Felix

Re: SOAP based webservice

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

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

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;

...

}

Re: SOAP based webservice

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

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

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

Re: SOAP based webservice

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.

Announcements

Thingworx Navigate content has a new home! Click here to access the new Thingworx Navigate forum! ______________________________