Greetings.
I have a Silverlight 4 application that communicates with the server via HTTPS. In this application I have a view that calls a RIA DomainService query I created named "GetCustomersByIDQuery" to which I pass a list of customer IDs. Because I may need to send many IDs, I have decorated the query with the “HasSideEffects" attribute so that my IDs will be placed into the body of the HTTPS request and not exceed the URI length. When I attempt to access my view, I receive the following error:
*** Message ***
Load operation failed for query 'GetCustomersByID'. Error in deserializing body of request message for operation 'GetCustomersByID'. OperationFormatter encountered an invalid Message body. Expected to find node type 'Element' with name 'GetCustomersByID' and namespace 'http://tempuri.org/'. Found node type 'Element' with name 'MessageRoot' and namespace ''
*** Stack Trace ***
at System.ServiceModel.DomainServices.Client.OperationBase.Complete(Exception error)
at System.ServiceModel.DomainServices.Client.LoadOperation.Complete(Exception error)
at System.ServiceModel.DomainServices.Client.DomainContext.CompleteLoad(IAsyncResult asyncResult)
at System.ServiceModel.DomainServices.Client.DomainContext.<>c__DisplayClass1b.<Load>b__17(Object )
After some trial and error, I have deduced that the combination of HTTPS, HasSideEffects = true, and a client-side LINQ "OrderBy" (see code below) attached to the query "GetCustomersByIDQuery" is causing the problem. If I maintain both HTTPS and HasSideEffects = true, but remove the OrderBy clause, the error disappears. Similarly, if I maintain both HTTPS and the OrderBy clause, but I remove HasSideEffects = true, the error disappears. Finally, if I maintain both the OrderBy clause and HasSideEffects = true, but use HTTP (instead of HTTPS) the error disappears. In the end, however, I need all three to work in conjunction with each other.
Now, I know that I could either 1) place the OrderBy in the DomainService query or 2) perform the sort client-side once I've retrieved my data. However, my example in this post is really just a simplistic stand-in for a real-world query that is using client-side OrderBy, IncludeTotalCount, Sort, Where, Skip, and Take in conjunction with a Telerik GridView that is bound to a VirtualQueryableCollectionView.
On final thing to mention -- when the OrderBy is included in an HTTP request, "?orderby=it.LastName" appears in the QueryString. However, when requested via HTTPS, no "orderby" appears in the QueryString (why the difference?), but rather the "orderby" appears in the body of the HTTPS request along with the content below. Here “MessageRoot” as referenced in the error above, is what the serializer is complaining about.
@
MessageRoot@
QueryOptions@
QueryOptions Name?orderby
Value?
Here is my code.
[Query(HasSideEffects = true)] public IQueryable<Customer> GetCustomersByIDQuery(List<int> ids) { int[] filter = ids.ToArray<int>(); return ObjectContext.Customers.Where(s => filter.Contains(s.ID)); } List<int> customerIDs = new List<int>(){1,2,3}; DM.Context.Load(DM.Context.GetCustomersByID(customerIDs).OrderBy(ob => ob.LastName), (LoadOperation<Customer> lo) => { // Perform processing. }, null);
I tried hard to perform my due diligence with regard to researching this issue. Unfortunately, I could not find any information regarding the three settings above working in concert. I would appreciate any help you could provide. Thanks.
- Steve
** UPDATE 17-OCT-2011 **
In my previous update I wondered why the "orderby" was in the QueryString during an HTTP request and in the body of an HTTPS request. When my team accidentally set "security mode" = "transport" in the Web.config for our non SSL site, the switch occurred (the "orderby" started appearing in the body of the request). This doesn't solve my problem, but it may be a lead.
** UPDATE 12-OCT-2011 **
Since no one has yet commented on this post, I thought that I would mention the following:
- The combinations I describe above of turning on/off HTTPS, HasSideEffects, and OrderBy all occur on the same machine. So, my DLLs are the same (someone at http://social.msdn.microsoft.com/Forums/en-US/silverlightwcf/thread/111a5dfa-20c3-4792-9c3b-9be06a4e29cc//1?Error+deserializing+when+using+HasSideEffects+true+and+paging commented that a problem similar to this could be caused by a difference in DLL versions).
- I did see the post at http://social.msdn.microsoft.com/Forums/en-US/silverlightwcf/thread/111a5dfa-20c3-4792-9c3b-9be06a4e29cc//1?Error+deserializing+when+using+HasSideEffects+true+and+paging which mentioned a solution at http://stackoverflow.com/questions/492407/operationformatter-encountered-an-invalid-message-body. Unfortunately, this solution is not using a RIA DomainService query and, therefore, I believe can / will not have an OperationContract where I can specify a different WebMessageBodyStyle.
- I saw the post at http://social.msdn.microsoft.com/Forums/en-US/silverlightwcf/thread/f687bf09-a32d-4932-9434-3eacaabbd4ae#fb4b9418-8389-43b8-b1d4-646c1354df80. While the post is marked as answered, the OP never mentions what fixed the problem. In addition, the user had their OrderBy in the server method, not the client (mine is on the client). With respect to the suggestions, my query method does get hit using HTTPS and all other methods not using an OrderBy work in HTTPS. I will concede (as I mention above) that the HTTP request differs from the HTTPS request in that when requested via HTTP, the OrderBy appears in the QueryString whereas it does not in the HTTPS request (unfotunately, I don't know why).