Question : 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",... )

Answer : Create a WCF object on client side

WCF is designed for SOA so I am not even sure that you can do what you are asking for. And again, I really recommend you to use a service based approach and not an OO one. SOA is much easier to maintain actually and allows for a separation of logic between server and client. You'll probably need to rethink your project a bit but I think it is worth it. I am sure a lot of experts here will tell you the same thing, SOA is the best solution for vertical and horizontal scalability.

Also, what you can do is the following for instance:
RestaurantService.AddReservation(ReservationInfo reservation)
where reservation info is a container object with the information required to make a reservation.

To mark an object to be exposed use "DataContract" and "DataMember" in your attributes:
 [DataContract]
    public class ReservationInfo
    {
        private int reservationId;
        private string firstName;

        [DataMember]
        public int FirstName
        {
get;set;
        }
    }
Random Solutions  
 
programming4us programming4us