Xcode (RestKit を使用) から WCF サービスに投稿しようとしています。これが私のコードです:
NSDictionary *queryParams;
queryParams = [NSDictionary dictionaryWithObjectsAndKeys:
@"1.0",@"oauth_version",
@"33333",@"oauth_nonce",
@"HMAC-SHA1",@"oauth_signature_method",
@"1323",@"oauth_timestamp",
@"rrr", @"oauth_consumer_key",
@"t672hpIerersdsfc", @"oauth_signature", nil];
RKObjectManager *objectManager = [RKObjectManager sharedManager];
RKURL *baseURL = [RKURL URLWithBaseURLString:@"http://myServer:80/appccservice.svc"];
objectManager = [RKObjectManager objectManagerWithBaseURL:baseURL];
objectManager.client.baseURL = baseURL;
objectManager.client.authenticationType = RKRequestAuthenticationTypeOAuth1;
objectManager.client.username = @"lsantos";
objectManager.client.password = @"clave";
NSString *resourcePath = [@"/json/post" stringByAppendingQueryParameters:queryParams];
[RKObjectManager sharedManager].serializationMIMEType = RKMIMETypeJSON;
RKObjectMapping *userSerialization = [RKObjectMapping mappingForClass:[NSMutableDictionary class]];
[userSerialization mapKeyPath:@"name" toAttribute:@"nombreNovia"];
[userSerialization mapKeyPath:@"tel" toAttribute:@"fecha"];
RKObjectMapping *serialize = [userSerialization inverseMapping];
[[RKObjectManager sharedManager].mappingProvider setSerializationMapping:serialize forClass:[User class]];
[[RKObjectManager sharedManager].router routeClass:[User class] toResourcePath:resourcePath forMethod:RKRequestMethodPOST];
User *data = [User new];
data.nombreNovia = @"joaquin";
data.fecha = @"4344";
[[RKObjectManager sharedManager] postObject:data delegate:self];
私は RKLogConfigureByName を使用し、これを得ました:
リクエスト:
URLRequest '<NSMutableURLRequest http://myServer:80/appccservice.svc/json/post?oauth_timestamp=32432304&oauth_nonce=123123&oauth_version=1.0&oauth_consumer_key=key&oauth_signature_method=HMAC-SHA1&oauth_signature=t672hasdfdsfsdsdceVBFqKc>'. HTTP Headers: {
Accept = "application/json";
"Accept-Encoding" = gzip;
Authorization = "OAuth oauth_signature=\"bEmMvO3sdfsdfsdfcdc\"";
"Content-Length" = 31;
"Content-Type" = "application/json";
}. HTTP Body: {"tel":"4344","name":"joaquin"}.
そのリクエストはすべて問題ないと思います。データはHTTPボディにあります。
一方、応答では:
Connection = "Keep-Alive";
"Content-Length" = 7;
"Content-Type" = "application/json; charset=utf-8";
Date = "Thu, 27 Sep 2012 12:34:08 GMT";
"Proxy-Connection" = "Keep-Alive";
Server = "Microsoft-IIS/7.5";
Via = "1.1 ISASERVERSM";
"X-Powered-By" = "ASP.NET";
}
オブジェクトが null の場合、メソッドは空を返すため、WCF はデータを認識していません。
2012-09-27 08:34:05.056 RESTPRUEBA2[6698:fb03] T restkit.network:RKResponse.m:231 Read response body: "empty"
そして、didFailLoadWithErrorでこのエラーが発生します
2012-09-27 09:11:25.500 RESTPRUEBA2[6698:fb03] error encontrado: Error Domain=JKErrorDomain Code=-1 "Expected either '[' or '{'." UserInfo=0x88d89c0 {JKAtIndexKey=7, JKLineNumberKey=1, NSLocalizedDescription=Expected either '[' or '{'.}
面白いのは、Firefox で同じ URL とデータを使用して RestClient アドオンを使用して WCF を証明し、すべてが正常に機能したことです。