ServiceAdapter:InvokeMethod2 Question
 
Forums / SmartComponent Library - Developer Forum / ServiceAdapter:InvokeMethod2 Question

ServiceAdapter:InvokeMethod2 Question

10 posts, 2 answered
  1. Roger Blanchard
    Roger Blanchard avatar
    381 posts
    Registered:
    29 Jun 2018
    11 Jan
    Link to this post
    We have an existing parameter class that is configured as SERIALIZABLE as show below. 

    CLASS Osprey.Pos.Item.ItemParameter SERIALIZABLE INHERITS ImportParameterBase:

    We did not want to take the time to change it to INHERITS JsonSerializable and then use Consultingwerk/JsonSerializableProperty11.i

    It looks like we could use the InvokeMethod2 for this. We have tested and the parameter class is sent to the backend just fine. However, the values that are set in the parameter object are not returned to the front-end. 

    Can I use this METHOD to return those values or do I need to go back to InvokeMethod?

      /**
         * Purpose: Invokes a custom method of the BusinessEntity.
         * Notes: - The object passed in as a parameter must either be ABL-SERIALIZABLE or implement
         *            Consultingwerk.ISerializable
         *        - This method differs from InvokeMethod() in that it always returns the parameter object
         * @param pcPartition The name of the AppServer partition for this call or "" for the default partition
         * @param pcEntityName The name of the business entity
         * @param pcMethodName The name of the business entity method to invoke
         * @param phDataset INPUT-OUTPUT DATASET-HANDLE The handle of the dataset of the business entity, optionally INPUT, optionally OUTPUT
         * @param poParameter The serializable parameter object to the method
         * @return The return parameter object
         */
  2. Peter Judge
    Peter Judge avatar
    8 posts
    Registered:
    11 Aug 2022
    11 Jan in reply to Roger Blanchard
    Link to this post
    Hi Roger,

    The InvokeMethod2 method is intended for exactly your use-case. The method returns the parameter object, so you'd need to assign the return value of the call to a variable (instead of just using the input parameter object as would be the case for a JsonSerializable object).

  3. Roger Blanchard
    Roger Blanchard avatar
    381 posts
    Registered:
    29 Jun 2018
    11 Jan in reply to Peter Judge
    Link to this post
    Hello Peter,

    We use this call with all the JsonSerializable parameter classes with no issues.  

    ServiceAdapter:InvokeMethod  ("Default",
                                                    "Osprey.Pos.Item.ItemBusinessEntity",
                                                     "GetItem",
                                                     INPUT-OUTPUT DATASET-HANDLE hDSet, 
                                                     oItemParameter
    ).

    Are you saying we need to change to:

    oParameter = ServiceAdapter:InvokeMethod  ("Default",
                                                                        "Osprey.Pos.Item.ItemBusinessEntity",
                                                                        "GetItem",
                                                                        INPUT-OUTPUT DATASET-HANDLE hDSet, 
                                                                        oItemParameter
    ).
  4. Roger Blanchard
    Roger Blanchard avatar
    381 posts
    Registered:
    29 Jun 2018
    11 Jan in reply to Roger Blanchard
    Link to this post
    This did work. However, most of my other use cases like this are using InvokeMethod and the passed parameter object does contain the values set on the server. Maybe we implemented wring years ago.

    oParameter = ServiceAdapter:InvokeMethod2 ("Default",
                                                                         "Osprey.Pos.Item.ItemBusinessEntity",
                                                                          "GetItem",
                                                                           INPUT-OUTPUT DATASET-HANDLE hDSet,
                                                                           oItemParameter).
                                                                            

    oItemParameter = CAST (oParameter, Osprey.Pos.Item.ItemParameter ). 
  5. Peter Judge
    Peter Judge avatar
    8 posts
    Registered:
    11 Aug 2022
    Answered
    11 Jan in reply to Roger Blanchard
    Link to this post
    The way you are doing things with the JsonSerializable objects and InvokeMethod is the correct way, and thre's no need to change that at all.

    The return value for ABL SERIALIZABLE classes is needed given the way that the AVM does its serialization. We get a new object reference back from the server, and there's no way to take the contents (property values, etc) of that object and get it into the existing input parameter object.

    The return value of the InvokeMethod2 method will always be the parameter object, even if you are using JsonSerializable objects.
  6. Roger Blanchard
    Roger Blanchard avatar
    381 posts
    Registered:
    29 Jun 2018
    11 Jan in reply to Peter Judge
    Link to this post
    Ok, great. I was worried there for a minute. 

    Thanks for the quick response....there are about a dozen places we need to change this so not that much work. 
  7. Mike Fechner
    Mike Fechner avatar
    319 posts
    Registered:
    14 Sep 2016
    11 Jan in reply to Roger Blanchard
    Link to this post
    What Peter is basically trying to say is that our JsonSerialization was designed to be nicer to developers than the native serialization in the language 
  8. Roger Blanchard
    Roger Blanchard avatar
    381 posts
    Registered:
    29 Jun 2018
    20 Mar in reply to Peter Judge
    Link to this post
    Hey Peter / Mike,

    As a follow up to this ItemParameter class. We were going to use this same parameter in a method being called from an Android mobile front end. It appears that when coming through the web handler is must be JsonSerializable. Is this true?

    This is the error I am receiving

    "title": "An application error has occurred (Consultingwerk.Exceptions.InvalidTypeException)",
        "error": "Consultingwerk.Exceptions.InvalidTypeException",
        "message": "Type Osprey.Pos.Item.ItemParameter should be Consultingwerk.JsonSerializable.",
        "messageNum": 0,
        "callStack": "TypeOf Consultingwerk.Assertion.ObjectAssert at line 877  (Consultingwerk/Assertion/ObjectAssert.r)\nInvokeMethod Consultingwerk.OERA.RestResource.RestEntitiesWebHandler at line 4873  (Consultingwerk/OERA/RestResource/RestEntitiesWebHandler.r)\nHandleGet Consultingwerk.OERA.RestResource.RestEntitiesWebHandler at line 2556  (Consultingwerk/OERA/RestResource/RestEntitiesWebHandler.r)\nHandleRequest OpenEdge.Web.WebHandler at line 69  (OpenEdge/Web/WebHandler.r)\nHandleRequest OpenEdge.Web.InternalWebRouter at line 136  (OpenEdge/Web/InternalWebRouter.r)",
        "properties": {
            "ExpectedType": "Consultingwerk.JsonSerializable",
  9. Peter Judge
    Peter Judge avatar
    8 posts
    Registered:
    11 Aug 2022
    Answered
    20 Mar in reply to Roger Blanchard
    Link to this post
    Hi Roger,

    It appears that when coming through the web handler is must be JsonSerializable. Is this true?


    If the invokable method's response attribute in the RestMethod annotation contains the parameter name, then the class must implement JsonSerializable. This is because in this case the parameter values are used as part of the JSON body that's returned.

    So given somthing like the below, the ItemParameter class must inherit from Consultingwerk.JsonSerializable.

    @RestMethod (address="/UpdateItem", requestMethod="get",
                     parameterClassName="Osprey.Pos.Item.ItemParameter",
                     response="poItemParameter").
    method public void UpdateItem(poItemParameter as Osprey.Pos.Item.ItemParameter ):
        /* do work */
    end method.

    HTH,
    -- peter
  10. Roger Blanchard
    Roger Blanchard avatar
    381 posts
    Registered:
    29 Jun 2018
    20 Mar
    Link to this post
    Thanks Peter...it does help and confirmed what I thought.
10 posts, 2 answered