Skip to main content

Microsoft Silverlight

Unanswered Question Object sent via WCF to client: validation in setter methods are never called ?RSS Feed

(0)

hcbj
hcbj

Member

Member

1 points

4 Posts

Object sent via WCF to client: validation in setter methods are never called ?

 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 Tang - MSFT
Min-Hong...

Contributor

Contributor

3376 points

377 Posts

Re: Object sent via WCF to client: validation in setter methods are never called ?

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

Min-Hong Tang
Microsoft Online Community Support

Please remember to mark the replies as answers if they help and unmark them if they provide no help.
  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities