8

I am using RestKit for connecting to our WCF Data Services.

I am having issues with adding an entity using RKObjectManager's postObject function due to response mapping issues.

When an entity is added, WCF Data Services returns a 201 status code and the newly added entity(as response).

Is it possible to ignore the response and just use the status code returned to check if the add succeeded?

Ponnu

Ponnu
  • 81
  • 3

3 Answers3

1

Why would you want to ignore the newly added entity returned from the server? Mapping that result is useful to keep in sync your local representation with the server's one. The server may have overwritten some field of your object like the object id and you want to keep track of it.

If you have mapping error it's probably because the response to the POST action returns a representation of your object which differs from the one returned with a GET. Have you tried using:

- (RKObjectLoader*)postObject:(id<NSObject>)object mapResponseWith:(RKObjectMapping*)objectMapping delegate:(id<RKObjectLoaderDelegate>)delegate

instead and specify a more suitable mapping for the data returned?

duhanebel
  • 845
  • 4
  • 17
0

Create a trivial RKObjectMapping that does not care about any parameters in response.

[RKObjectMapping mappingForClass: [NSNull class]];
Cimlman
  • 3,404
  • 5
  • 25
  • 35
0

The problem here can be to alter the REST service, so instead a simple solution would be to ignore the callback to didFailWithError in case of postObject calls to a certain resource path.

- (void)objectLoader:(RKObjectLoader *)objectLoader didFailWithError:(NSError *)error {
if ([objectLoader wasSentToResourcePath:@"/rest/api/returns/201" method:RKRequestMethodPOST] && [[objectLoader response] statusCode]==201) {
    NSLog(@"Object created");
} else {
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Communication error"
                                                        message:[NSString stringWithFormat:@"Received status code %d: %@",                                                                                               objectLoader.response.statusCode,                                                                                               error.localizedDescription]                                                           delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alertView show];
}
tchristensen
  • 86
  • 1
  • 7