AFNetworking 2.0 SOAP web service: how to make a request?

Thanks for reading.

I am trying to use data here: Link to data So, I am trying to implement a new Afnetworking infrastructure in my ios application. I am writing this:

   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];

A call appears, but the server returns me:

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>

What am I doing badly?

Thanks. Relations

+4
source share
1 answer

The problem was not the call ... instead, there was a parameter: @ "0035", because the server needs a json parameter with all the values ​​to successfully complete the request, I mean, for example:

{
"companyid":"0035",
}
-5
source

Source: https://habr.com/ru/post/1525467/


All Articles