AFNetworking 2.0, веб-сервис SOAP: как сделать запрос?

Спасибо за чтение.

Я пытаюсь использовать данные отсюда: Канал данных Итак, я пытаюсь внедрить новую структуру Afnetworking в свое приложение для iOS. Я пишу это:

   NSURL *baseURL = [NSURL URLWithString:@"http://www.virtualdemos.com.ar/RPSistemas/InformeDiario/WsInformeDiario/Services.asmx?op=GetEmpresasJson"];

NSString *soapBody = [NSString stringWithFormat:@"<?xml version=\"1.0\" encoding=\"utf-8\"?><soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"><soap:Body><GetEmpresasJson xmlns=\"http://tempuri.org/\"><empresaRequestJson>%@</empresaRequestJson></GetEmpresasJson></soap:Body></soap:Envelope>", @"0035" ];



NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:baseURL];

[request setHTTPMethod:@"POST"];
[request setHTTPBody:[soapBody dataUsingEncoding:NSUTF8StringEncoding]];

[request addValue:@"http://tempuri.org/GetEmpresasJson" forHTTPHeaderField:@"SOAPAction"];

[request addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];

AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];

[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
    // do whatever you'd like here; for example, if you want to convert
    // it to a string and log it, you might do something like:

    NSString *string = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
    NSLog(@"%@", string);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    NSLog(@"%s: AFHTTPRequestOperation error: %@", __FUNCTION__, error);
}];


[operation start];

Вызов работает, но сервер возвращает меня:

2014-02-05 12:29:28.842 InformeDiario[1675:70b] <?xml version="1.0" encoding="utf-8"?>    <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"     xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><GetEmpresasJsonResponse     xmlns="http://tempuri.org/"><GetEmpresasJsonResult>{
  "Empresas": [],
  "Error": {
    "Code": 2,
    "Description": "Error converting value 29 to type 'InformeDiario.Entity.EmpresaRequest'. Path '', line 1, position 4.",
    "FaultCode": 0
  },
  "MobileFechaSync": null,
  "ServerReceivedFechaSync": null,
  "ServerFechaSync": null
}</GetEmpresasJsonResult></GetEmpresasJsonResponse></soap:Body></soap:Envelope>

Что я делаю плохо?

Спасибо. С уважением


person bubudrc    schedule 05.02.2014    source источник
comment
возможный дубликат Использовать AFNetworking + использовать веб-службу мыла + как сделать запрос?   -  person Paresh Navadiya    schedule 07.04.2014
comment
jayprakashdubey.blogspot.in/2014/09/   -  person Jayprakash Dubey    schedule 30.09.2014


Ответы (1)


Проблема была не в вызове... вместо этого был параметр: @"0035", потому что серверу нужен параметр json со всеми значениями для правильной обработки запроса, я имею в виду, например:

{
"companyid":"0035",
}
person bubudrc    schedule 05.02.2014