AFNetworking 2.0,SOAP Web服务:如何发出请求?

时间:2014-02-05 17:44:08

标签: ios .net web-services soap afnetworking-2

感谢阅读。

我正在尝试使用此处的数据:Data Link 所以,我正在尝试在我的ios应用程序上实现新的Afnetworking框架。 我写这个:

   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>

我做得不好?

感谢。 此致

1 个答案:

答案 0 :(得分:-5)

问题不在于调用...而是参数:@“0035”,因为服务器需要一个json参数,其中包含正确处理请求的所有值,我的意思是,例如:

{
"companyid":"0035",
}