Skip to main content
Home Forums Silverlight Programming Accessing Web Services with Silverlight Object sent via WCF to client: validation in setter methods are never called ?
1 replies. Latest Post by Min-Hong Tang - MSFT on November 10, 2009.
(0)
hcbj
Member
1 points
4 Posts
11-05-2009 11:14 AM |
The problem is that we have a UserDTO object on the server which is exposed to the SL client via a WCF service. In the setter methods of the UserDTO there are some validation code throwing Exceptions.
But when testing, the exceptions are never rasied .. why??
If the UserDTO is totally implemented in the silverlight project then the validation works just fine!
UserDTO implementation
private string m_PrivateCompany; public string m_Company { get { return m_PrivateCompany; } set { if (string.IsNullOrEmpty(value)) { throw new ArgumentException("Bummer"); } else if (value.Length > 250) { throw new ArgumentException("Bummer Bollocks."); } m_PrivateCompany = value; this.NotifyPropertyChanged("m_Company"); } }
On the Silverlight UI all the UserDTO properties are binded to the UI Controles ( there are a UserDTO defined in a grid.dataContext):
<TextBox x:Name="TextBoxCompany" <Text="{Binding Path=m_Company, Mode=TwoWay, NotifyOnValidationError=True, ValidatesOnExceptions=True}"></TextBox>
The Service is formulated as follows:
[OperationContract][ServiceKnownType(typeof(UserDTO))] public bool InsertUserWithAccount(UserDTO userDTO) { return DB_Controller.InsertUserWithAccount(userDTO); }
Any suggestions why the validation does not work?
Min-Hong...
Contributor
3376 points
377 Posts
11-10-2009 9:38 PM |
Hi,
I reproduced a similar program. And it just works fine. When the value does not meet the requirement it throws exception.
I almost just did some copy and paste job to create that test application.
Maybe there is something else causes the problem. You may share more of your code. Or you can upload your application to skydrive.live.com so that we can reproduce it and find out the problem.
Best Regards