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.Reservat ion() ' 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.CreateNe wReservati on(reserva tion)
This would be so much nicer than having to do:
RestaurantService.CreateNe wReservati on("john", "smith",... )
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.Reservat
reservation.FirstName = "John"
reservation.LastName = "Smith"
....
RestaurantService.CreateNe
This would be so much nicer than having to do:
RestaurantService.CreateNe
actually, the method RestaurantService.CreateNe wReservati on("john", "smith",... ) follows SOA guidelines and is a much better design choice in my ownest opinion.
ASKER
I don't like it. It means duplication of method signatures since inside RestaurantService.CreateNe wReservati on() there will need to be another reference to a business object's respective method, for example BusinessObjects.Reservatio n.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).
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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.
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.
ASKER
I prefer exposing the object and working with it on client side than just exposing methods with many parameters.