Ios AFHTTPSessionManager使用基于SOAP的服务

Ios AFHTTPSessionManager使用基于SOAP的服务,ios,objective-c,soap,afnetworking,afhttpsessionmanager,Ios,Objective C,Soap,Afnetworking,Afhttpsessionmanager,我在Stackoverflow中查看了一些帖子(和),但没有一篇回复“如何使用AFHTTPSessionManager使用基于SOAP的web服务” 这是不可能的,还是我们需要做一些调整,比如子类化等 我可以使用AFHTTPRequestOperation调用基于SOAP的服务,但这是我不想使用的,因为我在那里使用了XML和JSON web服务,我正在使用AFHTTPSessionManager。我希望在整个应用程序中采用类似的方法 使用RequestOperation的我的代码是: NSStr

我在Stackoverflow中查看了一些帖子(和),但没有一篇回复“如何使用
AFHTTPSessionManager
使用基于SOAP的web服务”

这是不可能的,还是我们需要做一些调整,比如子类化等

我可以使用
AFHTTPRequestOperation
调用基于SOAP的服务,但这是我不想使用的,因为我在那里使用了XML和JSON web服务,我正在使用
AFHTTPSessionManager
。我希望在整个应用程序中采用类似的方法

使用
RequestOperation
的我的代码是:

NSString *soapMessage = @"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
"<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/\">n"
"<soap:Body>\n"
"<CelsiusToFahrenheit xmlns=\"http://tempuri.org/\">\n"
"<Celsius>50</Celsius>\n"
"</CelsiusToFahrenheit>\n"
"</soap:Body>\n"
"</soap:Envelope>n";

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://tempuri.org/"]];
[request setValue:@"text/xml" forHTTPHeaderField:@"Content-type"];
[request setHTTPMethod:@"POST"];
[request setHTTPBody:[soapMessage dataUsingEncoding:NSUTF8StringEncoding]];

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

[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
    NSLog(@"responseObject = %@", [operation responseString]);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    NSLog(@"error = %@", error);
}];

[operation start];

我尝试了好几个小时,最终得到了一些回应,没有出现错误。以下是更新的代码:

NSString *soapMessage = @"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
"<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/\">n"
"<soap:Body>\n"
"<CelsiusToFahrenheit xmlns=\"http://tempuri.org/\">\n"
"<Celsius>50</Celsius>\n"
"</CelsiusToFahrenheit>\n"
"</soap:Body>\n"
"</soap:Envelope>n";

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://tempuri.org/"]];
[request setValue:@"text/xml" forHTTPHeaderField:@"Content-type"];
[request setHTTPMethod:@"POST"];

[request setHTTPBody:[soapMessage dataUsingEncoding:NSUTF8StringEncoding]];


AFHTTPSessionManager *sManager = [[AFHTTPSessionManager alloc] init];
sManager.responseSerializer = [AFHTTPResponseSerializer serializer];

NSURLSessionDataTask *dataTask = [sManager dataTaskWithRequest:(NSURLRequest *)request
            completionHandler:^( NSURLResponse *response, id responseObject, NSError *error){
                NSString *resString = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
                NSLog(@"Data: %@", resString);
                //NSLog(@"Resp: %@", [response ]);
                NSLog(@"Err: %@", error);
            }];
[dataTask resume];
NSString*soapMessage=@“\n”
“n”
“\n”
“\n”
“50\n”
“\n”
“\n”
“n”;
NSMutableURLRequest*请求=[NSMutableUrlRequestRequestWithURL:[NSURL URLWithString:@]http://tempuri.org/"]];
[请求设置值:@“文本/xml”用于HttpHeaderField:@“内容类型”];
[请求设置HttpMethod:@“POST”];
[请求setHTTPBody:[soapMessage dataUsingEncoding:NSUTF8StringEncoding];
AFHTTPSessionManager*sManager=[[AFHTTPSessionManager alloc]init];
sManager.responseSerializer=[AFHTTPResponseSerializer序列化程序];
NSURLSessionDataTask*dataTask=[sManager dataTaskWithRequest:(NSURLRRequest*)请求
completionHandler:^(NSURLResponse*response,id responseObject,NSError*error){
NSString*resString=[[NSString alloc]initWithData:responseObject编码:NSUTF8StringEncoding];
NSLog(@“数据:%@”,resString);
//NSLog(@“Resp:%@,[响应]);
NSLog(@“Err:%@”,error);
}];
[数据任务恢复];

将您的内容类型检查为[request setValue:@“application/soap+xml;charset=utf-8”forHTTPHeaderField:@“content type”]@Anbu.Karthik上述代码有效,但它使用了
请求操作
,我想用
AFNetworking
类的
SessionManager
实现同样的效果。没有高级,我也尝试了1个多小时,我也没有得到答案。我已经实现了上述代码,但如何在上述代码中实现NSOperationQueue?
NSString *soapMessage = @"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
"<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/\">n"
"<soap:Body>\n"
"<CelsiusToFahrenheit xmlns=\"http://tempuri.org/\">\n"
"<Celsius>50</Celsius>\n"
"</CelsiusToFahrenheit>\n"
"</soap:Body>\n"
"</soap:Envelope>n";

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://tempuri.org/"]];
[request setValue:@"text/xml" forHTTPHeaderField:@"Content-type"];
[request setHTTPMethod:@"POST"];

[request setHTTPBody:[soapMessage dataUsingEncoding:NSUTF8StringEncoding]];


AFHTTPSessionManager *sManager = [[AFHTTPSessionManager alloc] init];
sManager.responseSerializer = [AFHTTPResponseSerializer serializer];

NSURLSessionDataTask *dataTask = [sManager dataTaskWithRequest:(NSURLRequest *)request
            completionHandler:^( NSURLResponse *response, id responseObject, NSError *error){
                NSString *resString = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
                NSLog(@"Data: %@", resString);
                //NSLog(@"Resp: %@", [response ]);
                NSLog(@"Err: %@", error);
            }];
[dataTask resume];