Skip to main content
Home Forums Silverlight Programming Programming with .NET - General Property genration in Silverlight for WCF service proxy class.
6 replies. Latest Post by spatemp on November 6, 2009.
(0)
spatemp
Member
7 points
36 Posts
11-06-2009 8:40 AM |
I have silverlight project that uses WCF services. This wcf service returns an object back to client and has following property.
{
}
When I look at the proxy class generated in WCF service in silverlight, I see property generated like this.
[System.Runtime.Serialization.
Question is whey is it stripping out my validation in the property of the object that I am returning from WCF service.
ccoombs
Contributor
5168 points
758 Posts
11-06-2009 8:51 AM |
have a look at yavor's response here:
http://forums.silverlight.net/forums/p/37731/154037.aspx
basically the cause is that the proxy generator doesn't copy your logic. the solution is to bypass the proxy generator by explicitly providing the type through a separate assembly.
11-06-2009 10:17 AM |
thanks for this post. So, I do have my types in a seprate class library. However there are two issues with this.
1) when I try to add this type class library(Add reference, Projects, types project) to silverlight project, it tells me that "You cna only add project references to othe Silverlight project in the solutions.
Is there some other options that you can think of that might accomplish the validation in silverlight using the proxy generated classes.
microsof...
2890 points
564 Posts
11-06-2009 1:40 PM |
Hey spatemp.... You don't need to set the DataMember attribute to the Private member. All you have to do is: Set the DataMember attribute to the public property which u already done. So, just remove the attribute from the private member declaration & then see...
Hope, this will resolve your problem..
11-06-2009 3:22 PM |
thats fine. I can take out the [DataMember] but the question is how do you retain the validation in property. Becuase during adding wcf service to silverlight and the type generated in proxy does not have this validation. It removes it.
sladapter
All-Star
17441 points
3,172 Posts
11-06-2009 5:48 PM |
spatemp:Is there some other options that you can think of that might accomplish the validation in silverlight using the proxy generated classes.
With ValidationAttribute from System.ComponentModel.DataAnnotations you can tag the property with ValidationAttribute Tag without putting any code logic in the Setter. But that probably won't work for your case:
If you need to limit the data range on a field, you could tag your Property with RangeAttribute :
[Range(min, max, ErrorMessage = "Value for {0} must be between {1} and {2}.")]public int YourProperty {get;set;} But in your case you are trying to compare the value with the value of another Field. I don't think using RangeAttribute can work.
[Range(min, max, ErrorMessage = "Value for {0} must be between {1} and {2}.")]
public int YourProperty {get;set;}
But in your case you are trying to compare the value with the value of another Field. I don't think using RangeAttribute can work.
11-06-2009 7:45 PM |
I solved this problem by simply creating child class in UI(silverlight) that inherits from proxy class generated from wcf service. In the child class I overidden the properties that I wanted to validate on. I then used the following extension method that copies properties from parent proxy class to the child class. And then I used the child class to bind to silverlight elements such as DataGrid. The reason for doing all these is simply I did not wated to change 100's of Type classes with this.RaisePropertyChanged("") etc that Silverlight utilizes.
origin.GetType().GetProperties().Where(x => x.CanRead &&
(x.Name == destinationProperty.Name && x.PropertyType == destinationProperty.PropertyType)).ToList()