Published on : Feb 25, 2010
Category : General
Properties missing on the client side:
For people coming from SOAP/WSDL services background will find it hard to grasp some of the concepts of WCF RIA service initially. Say for example if you got an web service operation similar to this on your .asmx or WCF service
public Employee GetEmployee()
when you generate the proxy classes, the client side will be able to view all the properties of the type Employee.
emp.Manager //Complex type
emp.FirstName // simple type string
But the same operation (with similar notion like IQuerable) from WCF RIA service won’t let the client to access all the properties, only basic types like (int, string, bool etc) will be visible. So, if you try to access emp.Manager it will throw compile time exceptions.
WCF RIA service works on the concept of code projection, we need to dictate what needs to be projected on the client side. It won’t automatically generate all the properties. You need to use metadata annotations like [Include], [Associate] etc on the server side to dictate whether you need the property, and how its related to other properties etc.
Types missing on client side:
A classic example, on the default Visual Studio template file generated code, you’ll see the following snippet
// This is never used but without it RIA Services will complain RegistrationData
// is not exposed as an entity
public IEnumerable<RegistrationData> GetUsers()
throw new NotSupportedException();
So the moral is, if you intend to use a complex type on the client side from the server you need to return it as part of an operation. In the above example GetUsers methods (operation) is never been called or used directly from the client. But just to get access to RegistrationData type on the client side you need to create a dummy method like this.
The whole Service is missing on the client side:
But there is even bigger surprise, at time you won’t even see the service class at all on the client side. This can happen for various reasons. One of the common one is if you haven’t declared any methods (Operations) in your services class, or the methods (Operations) are not declared public. There could be possibly other reasons.
If you see some wired behaviour like this check the output window for any warnings. Its easy to miss them out of the 100’s of lines of text in the output window.