CSLA & WCF

CSLA & WCF

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


SouthSpawn posted on Wednesday, June 17, 2009

How much of a performance hit, if I was to use my CSLA objects on the "Service Side" of the equation.

For example: If the client calling my service passes the service a OrderID.

I could than on the service side use my CSLA object to bring back the order, than populate a DataContract object and pass it back to the client.

Or am I thinking about this wrong.

I am new to WCF.

RockfordLhotka replied on Wednesday, June 17, 2009

In my view, there are three options for WCF with CSLA:

  1. Use the WcfProxy in the data portal, in which case you are doing n-tier architecture using WCF, with all the power of CSLA on the client and server
  2. Use WCF to implement an n-tier architecture using any tightly-coupled server-side DAL scheme (dataset/datatable, etc) and invoke that DAL from your client-side DataPortal_XYZ methods
  3. Use WCF to implement a service-oriented, message-based architecture, using loosely coupled service and message contracts to define your services, and invoke those services from your client-side DataPortal_XYZ methods

Option 1 is simplest, but may transfer unnecessary data over the wire (on a save) because the data portal makes sure you have the same context (object graph, security, etc) on client and server.

Option 2 is somewhat hard, but is next simplest. You lose most of the value of the data portal, but if you use something like ANDS on the server it is probably not too hard. Just remember your client and server are still part of the same app (because this is n-tier), and you are just implementing your own plumbing between the two instead of allowing the data portal to do the work for you.

Option 3 is hardest, because you are creating two applications - client and server - that just happen to communicate with each other using well-defined, contractual messages. The service and message definitions can't be changed arbitrarily, because that breaks other clients - so you need to architect the server in anticipation of maintaining multiple versions of your service/message contracts over time.

Option 3 is the primary reason for using raw WCF - because you want the loose coupling of SOA and message-based architecture. If this is not what you want, then I recommend sticking with the data portal and WcfProxy if possible.

AKaplan replied on Thursday, February 23, 2012

Are there samples somewhere using these scenarios? I'm having such a hard time executing my DataPortal_XYX methods.  I currently have it setup as so for example. After the BeginGetList method is executed, it comes back to the ViewModel with the Model property unpopulated with an object. So I'm curious if I'm missing something somewhere.

 

  Public Shared Sub BeginGetList(cb As EventHandler(Of DataPortalResult(Of T)))

            Dim dp As New DataPortal(Of T)

            AddHandler dp.FetchCompleted, cb

            dp.BeginFetch()

        End Sub

 

 Protected Friend Overloads Sub DataPortal_Fetch(handler As LocalProxy(Of T).CompletedHandler)

            RaiseListChangedEvents = False

            Try

                Dim client = Csla.Data.ServiceClientManager(Of ServiceReference1.WcfPortalClient, ServiceReference1.IWcfPortal).GetManager("Client").Client

                AddHandler client.FetchCompleted, Sub(s, e)

                                                      Try

                                                          Dim obj As ServiceReference1.WcfResponse = e.Result

                                                          If obj IsNot Nothing Then

                                                              Array.ForEach(Of Byte)(obj.ObjectData, Sub() Add(CType(CObj(obj.ObjectData), C)))

                                                          Else

                                                              handler(Nothing, New ArgumentException("No items found"))

                                                          End If

                                                      Catch ex As Exception

                                                          handler(Nothing, ex)

                                                      End Try

                                                  End Sub

                client.FetchAsync(New ServiceReference1.CriteriaRequest, Guid.NewGuid)

            Catch ex As Exception

                handler(Nothing, ex)

            End Try

            RaiseListChangedEvents = True

        End Sub

 

 

JonnyBee replied on Thursday, February 23, 2012

Aaron

                                                          If obj IsNot Nothing Then

                                                              Array.ForEach(Of Byte)(obj.ObjectData, Sub() Add(CType(CObj(obj.ObjectData), C)))

                                                          Else

                                                              handler(Nothing, New ArgumentException("No items found"))

                                                          End If

                                                      Catch ex As Exception

                                                          handler(Nothing, ex)

                                                      End Try

                                                  End Sub

You DAL callback handler must ALWAYS make sure to call the callback handler recieved as parameter in order to notify UI /Business that the async operation is completed and an object is ready.

IE:

                                                          If obj IsNot Nothing Then

                                                              Array.ForEach(Of Byte)(obj.ObjectData, Sub() Add(CType(CObj(obj.ObjectData), C)))
                                                              handler(Me, Nothing)

                                                          Else

                                                              handler(Nothing, New ArgumentException("No items found"))

                                                          End If

                                                      Catch ex As Exception

                                                          handler(Nothing, ex)

                                                      End Try

 

AKaplan replied on Thursday, February 23, 2012

Thank you so much johnny Bee... This was driving me crazy... I just couldn't find what I was missing.

AKaplan replied on Thursday, February 23, 2012

Ok I fixed that... but the DAL is still not hitting it's breakpoint. 

Kalpesh Shah replied on Monday, December 26, 2011

Hi, I am also new to WCF with CSLA, and facing the same scenario/question as you are. I read the Rocky's explantion but could not understand properly. Have you understood it? What approach you are using now? Kindly share.

Thanks in advanc,

Kalpesh Shah

Copyright (c) Marimer LLC