I am converting a Windows Forms application with all of the logic in the UI layer into a 2-Tier application, using WCF for the application/business logic. We are following a pattern where every method on the service takes one parameter, and returns one response object. All of the required data is encapsulated into these objects. For example:
public GetPersonResponse GetPerson(GetPersonRequest req){
// do stuff
}
public class GetPersonRequest{
String Name{get;set;}
Date BirthDate{get;set;}
}
public class GetPersonResponse{
Person Result {get;set;}
}
My question is in the databinding on the client side. When I go to Data Sources and Show Data Sources, I see the Responses and the entities used in them, but not the requests. In the example above, I would see the GetPersonResponse and the Person, but not GetPersonRequest. It would be very handy to be able to bind the request object to a form, and submit the whole operation with one line of code:
client.GetPerson((GetPersonRequest) getPersonRequestBindingSource.Current);
or at the very least:
GetPersonRequest req = (GetPersonRequest) getPersonRequestBindingSource.Current;
Validate(req);
client.GetPerson(req);
For another example, imagine a CreatePerson method, with the following Request class:
public class CreatePersonRequest{
String Name {get;set;}
String Address {get;set;}
String Address2 {get;set;}
String City {get;set;}
String State {get;set;}
String ZipCode {get;set;}
Integer Age {get;set;}
// more stuff here
}
I don’t want code like:
CreatePersonRequest req = new CreatePersonRequest(){
Name = NameTextBox.Text,
Address = AddressTextBox.Text,
Address2 = Address2TextBox.Text,
City = CityTextBox.Text,
State = StateComboBox.SelectedValue,
ZipCode = ZipCodeTextBox.Text,
Age = Integer.ParseInt(AgeTextBox.Text)
}
client.CreatePerson(req);
I would much rather have:
client.CreatePerson((CreatePersonRequest) createPersonRequestBindingSource.Current)
IMHO, this is much cleaner and maintainable – if a field gets added to the request, I simply update the widgets on the UI, and the code itself doesn’t have to change.
Is there a way to get the requests recognized by the Data Sources within UI Databinding?
.Net 4.0 on both the client and server.
(All code written by hand, so please do not expect it to be able to be run 🙂 )
Edit: To be clear, the request object is showing in the contract; I can make one in the code behind and populate it manually. Just looking for the productivity enhancing data binding functionality to work.
Well, I guess I figured it out. The objects will still appear if you Add New Data Source, and choose Object. They are in the Service’s namespace.
It would still be nice to have the Service option give me everything I need, but alas – if programming were easy, everyone would be doing it.