I have a simple data model with 3 tables (Account, Contact and User) with the following relationships:
User β account (1 - many) β contact (many - 1)
I view my data through the OData (v3) WCF data service, which is consumed by the .NET client, which uses the WCF data services client library. I used the Add Service utility to create a client proxy to invoke the data service.
All client class methods use the same DataServiceContext class to invoke the web service. i.e:.
DC.WhEntities svcClient = new DC.WhEntities(new Uri(BaseUrl));
What I'm struggling to figure out is why the same service request request starts crashing after the 6th time. I literally tried all possible ways to build a data service call:
First approach:
DataServiceQuery<DC.User> users = svcClient.Users.Expand("Accounts"); QueryOperationResponse<DC.User> response = users.Execute() as QueryOperationResponse<DC.User>; var user = response.FirstOrDefault(u => u.Id == long.Parse(key.ToString()));
Second approach:
string queryString = string.Format("Users({0}L)?$expand=Accounts", key.ToString()); foreach (var user in response) {...}
The last statement in both of the above solutions starts to crash after the message after it has successfully completed 6 times in a row:
The response payload is a not a valid response payload. Please make sure that the top level element is a valid Atom element or belongs to 'http://schemas.microsoft.com/ado/2007/08/dataservices' namespace. **StackTrace:** at System.Data.Services.Client.Materialization.ODataMaterializer.CreateODataMessageReader(IODataResponseMessage responseMessage, ResponseInfo responseInfo, Boolean projectionQuery, ODataPayloadKind& payloadKind) at System.Data.Services.Client.Materialization.ODataMaterializer.CreateMaterializerForMessage(IODataResponseMessage responseMessage, ResponseInfo responseInfo, Type materializerType, QueryComponents queryComponents, ProjectionPlan plan, ODataPayloadKind payloadKind) at System.Data.Services.Client.DataServiceRequest.Materialize(ResponseInfo responseInfo, QueryComponents queryComponents, ProjectionPlan plan, String contentType, IODataResponseMessage message, ODataPayloadKind expectedPayloadKind) at System.Data.Services.Client.QueryResult.ProcessResult[TElement](ProjectionPlan plan) at System.Data.Services.Client.DataServiceRequest.Execute[TElement](DataServiceContext context, QueryComponents queryComponents)
When this happens, my WCF data service just stopped working and returns a response using
in row 1 in column 83: Unescaped '<' is not allowed in attribute values.
Iβm not sure that I donβt have anything fundamental either if I incorrectly create a WCF data service client request or if there is something in the WCF Data Service that does not like the same client requesting the same thing 6 times.
I have already spent several days, and I had in mind 3+ days trying to figure it out. I am new to WCF data service, and it seemed to me that I could learn from this lesson, but so far I have more pain than amplification.