WCF Data Services: An error occurred while processing this request.

by Larry Spencer Friday, June 8, 2012 9:01 AM

I've enjoyed figuring out how to make WCF Data Services sing, but the experience has not been without error messages. Today, I made a query that looked like this:

 

http://http://localhost:50980/Repository.svc/Folders(3)

 

Users of OData will know that this is a request for the Folder with the unique key of 3.

My folder came back just fine, but at the bottom was this disconcerting bit:

 

<error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
  <code></code>
  <message xml:lang="en-US">An error occurred while processing this request.</message>
</error>

 

I set breakpoints everywhere and single-stepped through all my code, but could not find the source of the error. I saw no point in Googling for such a non-specific error, but ultimately resorted to that tactic. Lo and behold, Nick Harris had the answer. In my DataService<T>-derived class, I set my configuration to tell me a little more...

 

public static void InitializeService(DataServiceConfiguration config)
{
    // Other configuration here...
    config.UseVerboseErrors = true; // TODO - Remove for production?
}

 

...and learned the cause.

 

<error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
  <code></code>
  <message xml:lang="en-US">An error occurred while processing this request.</message>
  <innererror>
    <message>A single resource was expected for the result, but multiple resources were found.</message>
    <type>System.InvalidOperationException</type>
    <stacktrace>   at System.Data.Services.Serializers.Serializer.WriteRequest(IEnumerator queryResults, Boolean hasMoved)xD;
   at System.Data.Services.ResponseBodyWriter.Write(Stream stream)</stacktrace>
  </innererror>
</error>

 

OK, so now I must go figure out why I'm returning multiple results for an ID of 3, but in the meantime I offer this post in the hope that UseVerboseErrors=true might help someone else.

Tags: , ,

All | WCF Data Services

Pingbacks and trackbacks (1)+

Add comment

About the Author

Larry Spencer

Larry Spencer develops software with the Microsoft .NET Framework for ScerIS, a document-management company in Sudbury, MA.