Endpoints Assembly: returning list of 'complex types'


Badge +4

Hello,

 

consider the following datatype:

PERSON

------------

Property: ID

Property: Name

 

If these objects were stored in SAP or in an SQL database I am able to retrieve them and return a list of persons (basically a two column table, with the first column being the ID and the second column the Name).

 

However I am having difficulty achieving something similar with the Endpoints Assembly: I can retrieve a list of ints and get a 'one column table'. But when I use the following function it DOES NOT retrieve a 'two column table' but instead returns a list of serialized objects.

 

public static void returnMultipleLists(out Int32[] ID, out String[] Name) {

    ID = new Int32[] {1,2};

    Name = new String[] {"Ben","Tim"};

}

 

I expect it to return

 

      ID    |     Name

-------------------------

       1     |     Ben

       2     |     Tim

 

Any ideas how to achieve this?

 

 

 


16 replies

Badge +10

Would be really interested to hear replies to this. I have had to create a K2 service object project which basically calls the webservice and then returns them as a list using K2's resuttable. This means that the list view controls will be able to render the returned items in the list view. 

Badge +8

You need to define a class in your assembly and return an array of objects from your method.  The endpoint assembly provider handles translating an object's properties to a K2 data type.  We do this in lots of places when interacting with other business systems that don't have SmartObject brokers out of the box.

 

In your particular case, you need to create a class with two properties (int Id and string Name).  Then return an array of said objects rather than trying to return the results through the parameters.

Badge +4

I tried that before but I'm probably doing something wrong:

 

  1. I created a 'Person' class as you described, with two public properties, constructor en getter/setter for the properties (Kinda useless bc of the public props but shh)
  2. I created a 'DataSource' class with no properties: just two public static methods: one retrieving a single Person (read) and one retrieving two Persons (array)

However when I build this assembly and import it in the Service Instance it returns serialized 'Person' objects. I could ofcourse create deserialization functions but I would prefer to limit the functionality to a single function.

 

Care to elaborate?

Badge +8

OK, so you created your assembly, dropped it in K2's HostServer/bin folder, then added a an instance of the Endpoints Assembly service broker, yes?

 

Did you then create your SmartObjects in K2 Studio?  Or directly from the SmartObject service tester app?

Badge +4

I did add it to the service endpoint and first generated it using the Smartobject Service Tester. However when trying to create a new object using the K2 Designer the method only has one return property: the serialized string.

Badge +8

Can you post your code?  The method should return a SmartObject representation of your return type.

Badge +4

Below is my code, I also tried to place the two methods (returnPerson and returnPersons) in the Person class but this did not solve the issue.

  

Person.cs

namespace X

{

   public class Person

   {

      // properties made public for testing purposes only

      public int ID;

      public String Name;

 

      public Person(int anID, String aName)

      {

         ID = anID;

         Name = aName;

      }

      public int getID()

      {

         return ID;

      }

      public String getName()

      {

         return Name;

      }

      public void setID(int anID)

      {

         ID = anID;

      }

      public void setName(String aName)

      {

         Name = aName;

      }

   }

}

Badge +4

   

TestAssembly.cs

namespace X

{

    public class TestAssembly

    {

        public static Person returnPerson()

        {

            return new Person(1, "Tom");

        }

        public static Person[] returnPersons()

        {

            Person[] returnValues = newPerson[2];

            returnValues[0] = new Person(1, "Tom");

            returnValues[1] = new Person(2, "Ben");

            return returnValues;

        }

    }

}

Badge +8

You need to mark your Person class as serializable with the System.Serializable attribute.

 

Also, don't bother with all the get/set methods (getID(), setName(), etc.) in your Person object because they won't be available to K2.  You should think of this class more along the lines of a data contract.

Badge +4

I added [Serializable()] before "public class Person", removed the getters/setters and rebuilt the assembly + rebooted the k2 blackpearl service + refreshed the service instance. To no avail: the service instance method still returns a memo. Any chance you could post a piece of code that works for you?

Badge +8

Please post a screen shot of your service instance configuration from the SmartObject service tester.

Badge +4

Ofcourse I can: find them in the attachments below.

 

And again: thanks for your time and effort!


15111i85B9C8C3008F2BAE.png
13243iDB666F134D6E8A5B.png
Badge +8

The only difference I see between your service instance and ours is our authentication mode is set to Service Account but I doubt that would change anything.

 

What's listed under the Methods folder for your assembly methods?

 

Also, have you checked your server logs for any error messages generated when the SmartObject is executed?

Badge +8

OK, I stuck your posted code in our dev environment just to test it.  After refreshing the service instance, all of our assembly methods provide two Methods in K2: Read and Read to Serialized Item.  Yours only provides Read to Serialized Item.

 

So the issue becomes how to create a Read method in your objects.  And I have no idea how to do this. :)  As far as I can tell, your objects and code are the same as ours.  Both are returning complex types with simple properties.  Both are marked as serializable.  So I'm kind of stumped.

 

Might be time to get K2 support involved in this one.

Badge +4

Ok, I'll contact them and keep you informed of the reason/solution.

 

Thanks again!

Badge +5

By default K2 needs to serialise table values that you make in order for the service broker to adapt the information for use in SmartObjects. What you can do is utilise the deserialized typed array method in the Endpoints Service Broker to obtain the information in the format that you desire. Take a look at this video, it explains in depth how to correctly utilize the Endpoint Service Broker and provides information on serialization and deserialization.

 

http://help.k2.com/displaycontent.aspx?id=6792

Reply