2014-02-14 3 views
1

Я реализовал SOAP-сервис в iOS. Я использую следующий код для отправки запроса.Проблема в SOAP XML

NSString *sSOAPMessage = @"<?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>" 
    "<CelsiusToFahrenheit xmlns=\"http://www.w3schools.com/webservices/\">" 
    "<Celsius>50</Celsius>" 
    "</CelsiusToFahrenheit>" 
    "</soap:Body>" 
    "</soap:Envelope>"; 


NSURL *sRequestURL = [NSURL URLWithString:@"http://w3schools.com/webservices/tempconvert.asmx"]; 
NSMutableURLRequest *myRequest = [NSMutableURLRequest requestWithURL:sRequestURL]; 
NSString *sMessageLength = [NSString stringWithFormat:@"%d", [sSOAPMessage length]]; 

[myRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"]; 
[myRequest addValue: @"http://www.w3schools.com/webservices/CelsiusToFahrenheit" forHTTPHeaderField:@"SOAPAction"]; 
[myRequest addValue: sMessageLength forHTTPHeaderField:@"Content-Length"]; 
[myRequest setHTTPMethod:@"POST"]; 
[myRequest setHTTPBody: [sSOAPMessage dataUsingEncoding:NSUTF8StringEncoding]]; 

NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:myRequest delegate:self]; 

if(theConnection) { 
    webData = [[NSMutableData data] retain]; 
}else { 
    NSLog(@"Some error occurred in Connection"); 

} 

И я получаю следующий ответ. Не получая никакой ценности, то есть значения Цельсия или Фаренгейта в ответ.

+0

где ответ? – preetam

+0

Он вернет веб-страницу. С некоторыми тегами HTML & spanans – Apoorv

ответ

1

Проверить это теперь работает:

NSString *soapMessage = [NSString stringWithFormat: 
@"<?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://www.w3schools.com/webservices/\"> <Celsius>25.5</Celsius>              </CelsiusToFahrenheit>" 
"</soap:Body>\n" 
"</soap:Envelope>\n" 
]; 
NSLog(soapMessage); 

NSURL *url = [NSURL URLWithString:@"http://www.w3schools.com/webservices/tempconvert.asmx?op=CelsiusToFahrenheit"]; 
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url]; 
NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]]; 

[theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"]; 
[theRequest addValue: @"http://www.w3schools.com/webservices/CelsiusToFahrenheit" forHTTPHeaderField:@"SOAPAction"]; 
[theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"]; 
[theRequest setHTTPMethod:@"POST"]; 
[theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]]; 

NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self]; 

if(theConnection) 
{ 
    webData = [[NSMutableData data] retain]; 
} 
else 
{ 
    NSLog(@"theConnection is NULL"); 
} 

Тогда получите ответ, как:

-(void)connectionDidFinishLoading:(NSURLConnection *)connection 
{ 
    NSString *data=[[NSString alloc]initWithFormat:@"%@",webData ]; 

// NSLog(@"DONE. Received Bytes: %d, \n %@", [webData length],data); 
    NSString *theXML = [[NSString alloc] initWithBytes: [webData mutableBytes] length:[webData length] encoding:NSUTF8StringEncoding]; 
    NSLog(@"Response is: %@",theXML); 
} 

Afterwords вам нужно разобрать его.

+0

Я изменил его, но теперь ничего не вернется с сервера. – Apoorv

+0

Эй Спасибо за ваш ответ .... Он начал работать и возвращать ответ .. :) Спасибо – Apoorv