How do I....Object Graph -> WCF Service -> External Web Service?

How do I....Object Graph -> WCF Service -> External Web Service?

Old forum URL: forums.lhotka.net/forums/t/11783.aspx


Phlar posted on Friday, January 11, 2013

Hi All,

I am not really sure how to implement this (Business Rule, CommandBase object, other).  I have an object graph residing on the client machine.  I need to communicate with an external web service from the WCF application server in order to submit & receive a response.  How do I accomplish this in CSLA.NET.

It’s technically not a business rule as this only need to done when the user selects the appropriate menu option.  I thought the CommandBase class would be an option but I am not sure how the object graph is marshaled to the application server for the DataPortal_Execute to reference for the web service call. 

The main purpose is to obtain a persons FICO score in our scenario.

Thank you,

Phlar

skagen00 replied on Friday, January 11, 2013

Like, Click a "Show FICO Score" checkbox (perhaps bound to a BO property)

In propertyhaschanged, do an command call and then LoadProperty+OnPropertyChanged or SetProperty the FICO score property of the BO - ideally asynchronously done, you can kick up a spinner by setting some kind of IsFicoScoreLoading property on the BO and bind a UI element to it (since it's a WCF service call - can give responsiveness back to the client and show that "it's in process".

That's one option if I understand you correctly.

Phlar replied on Monday, January 14, 2013

skagen00

Like, Click a "Show FICO Score" checkbox (perhaps bound to a BO property)

In propertyhaschanged, do an command call and then LoadProperty+OnPropertyChanged or SetProperty the FICO score property of the BO - ideally asynchronously done, you can kick up a spinner by setting some kind of IsFicoScoreLoading property on the BO and bind a UI element to it (since it's a WCF service call - can give responsiveness back to the client and show that "it's in process".

That's one option if I understand you correctly.

It is more of a menu event being triggered but similar concept.  Can you provide a sample of using the Command call (which I am assuming you mean using the Command object inheriting CommandBase<T>).  I am assuming it should be as easy as implementing a property on the CommandObject and assigning it the object graph (or portion of it we require) in the BeforeServer() method.

JonnyBee replied on Sunday, January 13, 2013

Assuming that you do not need the entire object graph to call the external web service,
I would create a separate CommandObject (from CommandBase) with the required data -
call the service in DataPortal_Execute method and return the output. 

You _could_ send the entire Person object over to the server - just make sure that you use a "managed property" in the command object for Person.

Phlar replied on Monday, January 14, 2013

JonnyBee

Assuming that you do not need the entire object graph to call the external web service,
I would create a separate CommandObject (from CommandBase) with the required data -
call the service in DataPortal_Execute method and return the output. 

You _could_ send the entire Person object over to the server - just make sure that you use a "managed property" in the command object for Person.

Is there any good examples of properly utilizing this object?  I am assuming the client will create an instance of this class utilizing the new keyword and pass in the appropriate items in the constructor to populate the properties.  Then it should perform the execute on that object.

Is that basically it or are there more things to consider/handle?

skagen00 replied on Monday, January 14, 2013

I obviously don't know the exact scenario, but here's an example you can tweak as needed.  In our case, we often times use "Lookup" read-only objects instead of command objects / both such things could work.

Below, we generally code a synchronous and an asynchronous parallel with .NET and Silverlight, respectively.  We just never did get comfortable with writing asynchronous tests and settled into this sort of mechanism.

In PropertyHasChanged of the BO -

     else if (property == ShowFicoScoreProperty)
            {
                // If the Organization's Id has been set, assign the name and Id as necessary.
                bool showFico = ReadProperty(ShowFicoScoreProperty);
                if (!showFico)
                {
                    // Clear out FICO info (in our cases, we're basically loading name, address, etc - of a related record - our ShowFicoScoreProperty is more analogous to setting a "contact Id" and seeing the contact's name, title, etc - load into the organization record as read-only information.
                }
                else
                {
#if SILVERLIGHT
                    FicoScoreLookup.Lookup(personId,    // FicoScoreLookup would just be a readonlybase in our case, command would work too.
                        (o, e) =>
                        {
                            if (e.Error != null) throw e.Error;

                            SetFicoScoreInformationFromLookup(e.Object);
                        });
#else
                    SetFicoScoreInformationFromLookup(FicoScoreLookup.Lookup(personId));
#endif
                }
            }


SetFicoScoreInformationFromLookup could be common sets/loads/OnPropertyChanged calls, etc - to take the lookup RO properties and do whatever is needed to the current object to load and raise necessary property changed events.

Copyright (c) Marimer LLC