我試圖從Xcode(帶RestKit)發佈到WCF服務。這裏是我的代碼:從iOs使用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";
}
我的方法的返回空當對象是空的,所以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 '{'.}
最逗的這個錯誤是我使用RESTClient實現插件在Firefox使用相同的URL和數據證明了我的WCF和一切工作正常。
你不應該把所有的文字都加粗。 – Asciiom