Reputation: 1923
I am implementing a .net OData client with WCF. This uses OData version 3. The service is implemented by a vendor. When saving an object with a missing property, the server returns an error. But the error response does not have the right format (Specification). Therefore, the DataServiceContext.SaveChanges(...)
method always throws:
System.Net WebException: "The remote server returned an error: (400) Bad Request."
With this exception I don't have any possibility to get the reason of the error--no InnerException is set.
How does such an error response look like, so that the WCF DataServiceContext.SaveChanges(...) detects an error and I can get the information I need?
Thanks in advance.
EDIT:
I used fiddler to change the response from the server. With this I tried to find the right formatted response. This is the last version I tried after rereading the specification and considering the comments:
HTTP/1.1 40 Bad Request
Cache-Control: private
Content-Type: application/atom+xml;type=feed
Date: Wed, 11 May 2016 08:02:07 GMT
Content-Length: 243
DataServiceVersion: 3.0;
<?xml version="1.0" encoding="utf-8"?>
<m:error xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
<m:code />
<m:message xml:lang="en-US">
Resource not found for the segment 'Productss'.
</m:message>
</m:error>
Sadly it's still not working.
Upvotes: 1
Views: 236
Reputation: 2656
The error you are getting is not because the client cannot read the response, it's an Exception
that's telling you that the server didn't "like" the request you sent to it.
400 Bad Request is usually used to notify a client that the request it sent to server was malformed.
The error should go away once you send the request to server in the correct structure.
Hope it helps!
Upvotes: 1