Link to home
Start Free TrialLog in
Avatar of luminas
luminas

asked on

Create a WCF object on client side

Hi,
Could someone please let me know what is needed in order to be able to create objects which were defined on the server side of WCF, in the client code.

So, basically, if I have an object "Reservation", in WCF (let's say it is hosted on a website's App_Code folder), I would want the calling code (let's say an ASPX page which is NOT in the same website) to be able to do:

Dim reservation as new RestaurantService.Reservation() ' This object is defined on the server, but I would like it to be available to me for declaration on the client side, just as methods of the service contract are.

reservation.FirstName = "John"
reservation.LastName = "Smith"
....
RestaurantService.CreateNewReservation(reservation)

This would be so much nicer than having to do:

RestaurantService.CreateNewReservation("john", "smith",... )

Avatar of lenordiste
lenordiste
Flag of France image

actually, the method RestaurantService.CreateNewReservation("john", "smith",... ) follows SOA guidelines and is a much better design choice in my ownest opinion.
Avatar of luminas
luminas

ASKER

I don't like it. It means duplication of method signatures since inside RestaurantService.CreateNewReservation() there will need to be another reference to a business object's respective method, for example BusinessObjects.Reservation.Create("john", "smith"...), instead of taking that Reservation object in the server side and writing Reservation.Create().

It's much more maintainable. Not to mention, you have the ability on the client side to "play" with the Reservation object (receive it from server, manipulate, and send back to server).
ASKER CERTIFIED SOLUTION
Avatar of lenordiste
lenordiste
Flag of France image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
by the way, if you don't put "DataMember" on a property than it won't be exposed. In my above example it helps you to have private property (reservationId) that your client side needs to use without exposing them to the client.
Avatar of luminas

ASKER

Actually that's what I was doing - putting "DataContract" attribute on the class - but forgot to update the web service reference in VS... After doing that, I got my object on the client side, and could do exactly what I wanted.

Even if this somehow conflicts SOA guidelines (it's still hard for me to understand why, this is not about a specific architecture - it's general programming concepts) I still prefer this. It means if many clients are consuming the service, any change in the reservation structure would not break the service for them. And the method signature stays the same.
Avatar of luminas

ASKER

I prefer exposing the object and working with it on client side than just exposing methods with many parameters.