Задача-c: NSURLConnection sendSynchronousRequest выдан 415 Ошибка неподдерживаемого типа носителя с запросом Soap - PullRequest
2 голосов
/ 19 марта 2012

Я пытаюсь сделать NSURLConnection синхронным с мыльной службой WCF * .svc (не REST) ​​и продолжаю получать ошибку 415 Тип носителя не поддерживается на моем объекте httpResponse.Я полагаю, что я устанавливаю заголовок с правильными Content-Type и SOAPAction , как видно на Fiddler .Я также написал приложение .net с WebRequest, и я получаю от него ответ с 200 статусами OK с тем же мылом.Может кто-нибудь сказать мне, где я иду не так или я что-то упустил.Я включил ARC с моим кодом объективного-c.Спасибо, любезно ....

-(void) GetJSONResponse_soap: (NSString *) PReqURL
{
  NSLog(@"URL sent: %@", PReqURL);  
  NSMutableString *sRequest = [[NSMutableString alloc] init];

  //creating soap request
  [sRequest appendString:@"<?xml version=\"1.0\" encoding=\"utf-8\"?>"];
  [sRequest appendString:@"<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">"];
  [sRequest appendString:@"<s:Body>"];
  [sRequest appendString:@"<GetJSONStrFromPrm xmlns=\"WCFJSON\">"];
  [sRequest appendString:@"<Prm>Whatever</Prm>"];
  [sRequest appendString:@"</GetJSONStrFromPrm>"];
  [sRequest appendString:@"</s:Body>"];
  [sRequest appendString:@"</s:Envelope>"];

  NSURL *reqURL = [NSURL URLWithString:PReqURL];
  //request
  NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:reqURL];

  [request addValue:@"WCFJSON/IJSONStrService/GetJSONStrFromPrm"  forHTTPHeaderField:@"SOAPAction"]; 
  [request addValue:@"text/xml; charset:utf-8" forHTTPHeaderField:@"Content-Type"];
  [request setHTTPMethod:@"POST"];
  [request setHTTPBody:[sRequest dataUsingEncoding:NSUTF8StringEncoding]];

  NSLog(@"\n\nRequest Xml: %@ \n\n", sRequest);

  NSURLResponse *theResponse = NULL;
  NSError *theError;

  //Connection start
  NSData *LcReceivedData = [NSURLConnection sendSynchronousRequest:request  returningResponse:&theResponse error:&theError];  

  //received string
  NSString *ResponseStr = [[NSString alloc] initWithData:LcReceivedData encoding:NSUTF8StringEncoding];
  NSLog(@"\n\nResponse: %@", ResponseStr);

  //response string which in this case seems to be 415
  NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)theResponse;
  long statusCode = [httpResponse statusCode];
  NSLog(@"\n\nStatus Code: %ld",statusCode);
  NSLog(@"\n\nError: %@", [theError localizedDescription]);

}
...