WCF, Silverlight 5, Self Tracking Entities, and (de)serialization - silverlight

I am working on a Silverlight applicaiton. It uses WCF services to pass EF 4 Self Tracking Entities back and forth from client to server.
Read methods are working fine to serve the Trackable entity collections to the Silverlight client from the WCF services. Even basic updates are working correctly. I can modify a property of "OfficeEntity", and pass it as a parameter to a WCF update method.
The issue we are having is when we update one of the Entity's collections, we get the below deserialization error. For example, if "OfficeEntity" has a navigation property "Locations" that is a collection of "LocationEntity", and we add a new "Location" to the "Locations" property and save it, we get the deserialization exception.
officeEntity.Locations.Add(new Location() {LocationName = "Test 1"});
client.SaveAsync(officeEntity);
Exception Details:
The formatter threw an exception while trying to deserialize the message:
There was an error while trying to deserialize parameter :OfficeEntity. The InnerException >message was
'There was an error deserializing the object of type Entities.OfficeEntity.
End element 'ObjectsAddedToCollectionProperties' from namespace >'http://schemas.datacontract.org/2004/07/Entities' expected.
Found element 'b:AddedObjectsForProperty' from namespace >'http://schemas.datacontract.org/2004/07/Entities'.'
It appears the problem is with deserializing the change tracking properties. Any ideas on what causes this or where I can fix it?
Thanks,
Jason

Self tracking entities have issues with tracking if the actual generated entities aren't used in the client - I blogged about it here.
Not sure if this is at the root of your serialization issues but will definitely have an impact on you being able to use self-tracking entities

Related

What is the alternate way for "Request" class/object in .NET core?

I am migrating an existing ASP.NET Web API 2 project to ASP.NET Core. While migrating I am unable to find this.Request object. Can anyone help me solve out this issue?
This question was asked here, but since ASP.NET Core was still probably in an RC state then, I figured I'd answer here instead of referring to there because there is some stuff that's obsolete or completely gone from the official release.
Assuming your controller class inherits from Controller (or more specifically, ControllerBase) then it does have a this.Request property as you can see here and here. As Pawel noted, you can also access it from the this.HttpContext property.
The request's URL is broken up into several properties on HttpRequest. You can access the URL in a friendlier API by adding using Microsoft.AspNetCore.Http.Extensions; which gets you access to the following extension methods:
GetDisplayUrl()
GetEncodedUrl()
As far as the query string, HttpRequest provides QueryString and Query properties for you to interact with.
Side note: I just created an app from scratch targeting ASP.NET Core on .NET Core for the first time on this laptop, and it took a while for the Intellisense to work for the Request property, so I'm wondering if that could have been your issue.
You need to override your class like this to get this.Request
public partial class _Default : System.Web.UI.Page

public List<List<string>> MyValue - not generating on client from RIA service - need guidance

I have an object in Ria service that is being generated on the client without a problem. The only problem is that this property is not being included in the client code and therefore missing it's values.
public List<List<string>> MyValue
Everything else is fine. I assume the problem is because it's a List within a List as regular List
I am confused as to what will generate on the client and what won't with RIA services. Where can I find some guidance about this?
Anyone have any tips on how to solve this because I need these values returned back to the client?
I was able to get this to generate the proxy property on the client by creating my own class called MyStrings which has a single property of type List<string>.
Then, in the Tests class i change the object type from List<List<string>> to List<MyStrings>.
I am not sure why one serializes and one doesn't, but this is a dirty work around I will use for now.
I am certain that a List<List<string>> will definitely serialize and deserialize just fine using WCF/RIA. That leads me to believe that perhaps the problem is in your contracts. How are you setting up the service and client proxy?
For example, is MyValue a property on an object that you're sending to or receiving from the server? If so, is there a DataContract attribute on the class on both the client and server? Is there a DataMember attribute on the property of both classes?

Silverlight DbContext Validation - Entity Attributes ignored on client side

I'm using a DbContext provided by a DomainService in my Silverlight 5 (Beta) application. I'm getting warning messages while building the project:
The attribute 'System.ComponentModel.DataAnnotations.MaxLengthAttribute' requires a reference to System.ComponentModel.DataAnnotations in the client project. Skipping generation of attribute. Please add a reference to System.ComponentModel.DataAnnotations to ensure generation of the attribute.
The thing is that, there is no MaxLengthAttribute attribute in System.ComponentModel.DataAnnotations at client side. In consequence, I'm not able to validate any property length before the record has been sent to the server ... Does anybody know a solution?
MaxLengthAttribute is in EntityFramework.dll and I'm almost sure that it cannot be used in Silverlight because it would require Silverlight version of EntityFramework.dll which doesn't exist.
Try using the StringLengthAttribute instead.

Updating service reference in silverlight application not working.. Please Help!

I'm building a silverlight LOB application which uses both RIA services and a vanilla .ASMX service..
The data is wired up using entity framework..
I have 1 entity which i recently added a 1 to many relationship to a collection of a new type of object..
Using RIA services i can get to that in my silverlight application fine by saying:
instanceOfEntity.NewEntities
However in the vanilla service which is using the exact same object context class even after updating, deleting and recreating the service reference in the silverlight application.. the property is still not being exposed..
Someone Plleeaeeeeease tell my how i can get this dang thing to show up via this service!
Thanks
Daniel
Ended up switching to a WCF service instead..
Seems to work fine,
Not sure if this is a limitation in vanilla ASMX services?

Data conflict resolution in Silverlight with WCF Service

When using Silverlight together with a WCF Services library how do you solve the age old possibility of two different users loading a record, making different changes to that record and then updating. In other words when updating how does the WCF service know that the data it retrieved is the same as the data it fetched before applying an update?
Do you need to check the original loaded values against the values in the database (i.e. recall the original query before updating)?
I was hoping that there would be a more out-of-the-box answer.
Do you mean using EntityFramework? If so, here is the strategy I used :
When retrieving data on the client side you see that the "RowState" property of the entity is gone. What I did is I added the property on the client side using the "partial class" feature. And I manage locally the value of that RowState value.
When the data goes back to the server for update only send what has been modified filtering by the "RowState" property.
On your Update method, call the ApplyCurrentValues() method of the object.
Maybe there is a better solution for that, but that's what I am using on my project; and it works well on my case :)
Good luck

Resources