This question is locked. New answers and comments are not allowed.
regards,
I have a web service API generated by OpenAccess wizard. I can receive data without problems, but I need to update the data from the device.
I have this in my controller.partial.cs.:
And working perfectly from a windows project using HttpResponseMessage:
But i don't know how extract the JSon generated. I need to see it to compose the correct code in iOS, and I cant find documentation about it. May be is not relevant to put iOS code here, but I add it just in case.
Thanks in advance!
I have a web service API generated by OpenAccess wizard. I can receive data without problems, but I need to update the data from the device.
I have this in my controller.partial.cs.:
public
virtual
HttpResponseMessage Put(TuPrevencion.Auditoria entity)
{
Auditoria auditoria = (from c
in
dbContext.Auditorias where c.Id == entity.Id select c).FirstOrDefault();
auditoria.Comentarios = entity.Comentarios;
...
dbContext.SaveChanges();
return
Request.CreateResponse(HttpStatusCode.NoContent);
}
And working perfectly from a windows project using HttpResponseMessage:
var entity =
new
Auditoria() { Id = 31, Comentarios =
"Test"
, ...
};
Uri gizmoUri =
null
;
HttpResponseMessage response = client.PutAsJsonAsync(
"api/auditorias"
, entity).Result;
var resultTask = client.PutAsJsonAsync(
"api/auditorias"
, entity).Result.Content.ReadAsStringAsync();
Console.WriteLine(
"{0} "
, resultTask.ToString());
Console.ReadLine();
if
(response.IsSuccessStatusCode)
{
gizmoUri = response.Headers.Location;
}
else
{
Console.WriteLine(
"{0} ({1})"
, (
int
)response.StatusCode, response.ReasonPhrase);
Console.ReadLine();
}
But i don't know how extract the JSon generated. I need to see it to compose the correct code in iOS, and I cant find documentation about it. May be is not relevant to put iOS code here, but I add it just in case.
NSDictionary *data = [NSDictionary dictionaryWithObjectsAndKeys:
@
"Test"
, @
"Comentarios"
, @
"31"
, @
"Id"
, nil];
NSDictionary *data2 = [NSDictionary dictionaryWithObjectsAndKeys: data, @
"entity"
, nil];
NSError *error = nil;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:data2 options:NSJSONWritingPrettyPrinted error:&error];
NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
NSLog(@
"JSON Output: %@"
, jsonString);
NSString *_urlString = [NSString stringWithFormat: @
"https://url.com:449/api/auditorias"
];
NSURL *_url = [NSURL URLWithString:_urlString];
NSMutableURLRequest* _request = [[Authentication sharedInstance ] _request:_url];
NSData *requestData = [NSData dataWithBytes:[jsonString UTF8String] length:[jsonString length]];
[_request setHTTPMethod:@
"PUT"
];
[_request setValue:@
"application/json"
forHTTPHeaderField:@
"Content-Type"
];
[_request setValue:[NSString stringWithFormat:@
"%d"
, [requestData length]] forHTTPHeaderField:@
"Content-Length"
];
[_request setHTTPBody: requestData];
NSURLConnection *connection = [[NSURLConnection alloc]initWithRequest:_request
delegate
:self];
if
(connection) {
receivedData = [NSMutableData data];
}
Thanks in advance!