This is my code to send a dictionary to server but not able to do it. i am getting following message If you see this message then their are any problem in wcf service.
NSError * err;
NSData * authData = [NSJSONSerialization dataWithJSONObject:[SharedGlobal SharedSingleton].dictAuthenticationNode options:0 error:&err];
NSString * authString = [[NSString alloc] initWithData:authData encoding:NSUTF8StringEncoding];
NSData * masterData = [NSJSONSerialization dataWithJSONObject:[SharedGlobal SharedSingleton].dictMasterNode options:0 error:&err];
NSString * masterString = [[NSString alloc] initWithData:masterData encoding:NSUTF8StringEncoding];
NSString *sSOAPMessage = [NSString stringWithFormat :@"<?xml version=\"1.0\" encoding=\"UTF-8\"?><soap:Envelope xmlns:xsi=\"http://ift.tt/ra1lAU\" xmlns:xsd=\"http://ift.tt/tphNwY\" xmlns:soap=\"http://ift.tt/sVJIaE\"><soap:Header/><soap:Body><Hotel_Features xmlns=\"http://tempuri.org/\"><XmlSearchRequest> {\"Hotel_Feature_RQ\": {\"HotelDetails\": { \"@HIndex\": \"%@\"}, \"Master\":\"%@\", \"Authentication\":\"%@\",}}</XmlSearchRequest></Hotel_Features></soap:Body></soap:Envelope>",hotelIndexNumber,masterString,authString];
NSURL *sRequestURL = [NSURL URLWithString:@"http://myurl.asmx"];
NSMutableURLRequest *myRequest = [NSMutableURLRequest requestWithURL:sRequestURL];
NSString *sMessageLength = [NSString stringWithFormat:@"%lu", (unsigned long)[sSOAPMessage length]];
[myRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[myRequest addValue: @"http://ift.tt/1IIT7X1" forHTTPHeaderField:@"SOAPAction"];
[myRequest addValue: sMessageLength forHTTPHeaderField:@"Content-Length"];
[myRequest setHTTPMethod:@"POST"];
[myRequest setHTTPBody: [sSOAPMessage dataUsingEncoding:NSUTF8StringEncoding]];
[NSURLConnection sendAsynchronousRequest:myRequest queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
if (!connectionError) {
NSString *responseString = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
NSRange range1 = [responseString rangeOfString:@"<Hotel_FeaturesResult>"];
if (range1.length !=0) {
responseString = [responseString substringFromIndex:(range1.location + range1.length)];
NSRange range2 = [responseString rangeOfString:@"</Hotel_FeaturesResult>"];
responseString = [responseString substringToIndex:range2.location];
NSData *apiData = [responseString dataUsingEncoding:NSUTF8StringEncoding];
handler(response,apiData,nil);
}else
handler(response,nil,nil);
}
}];
}
Aucun commentaire:
Enregistrer un commentaire