0
- (void)viewDidLoad
 {
[super viewDidLoad];
 NSString *id=@"1";
 NSString *GetExRequest = [NSString stringWithFormat:@"<SOAP-     ENV:Envelope \n"
                     "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" \n"
                     "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" \n"
                     "xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\"\n"
                     "SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" \n"
                     "xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"> \n"
                     "<SOAP-ENV:Header> \n"
                     "<UserName xmlns=\"CH1\">a1</UserName>\n"
                     "<Password xmlns=\"CH2\">a2</Password>\n"
                     "</SOAP-ENV:Header> \n"
                     "<SOAP-ENV:Body> \n"
                     "<NewsGet xmlns=\"http://tempuri.org/\">\n"
                     "<id>%@</id> \n"
                     "</NewsGet> \n"
                     "</SOAP-ENV:Body> \n"
                     "</SOAP-ENV:Envelope>\n", id];
 NSURL *url = [NSURL URLWithString:@"https:/www.a.com/Service1.svc"];
 NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
 NSString *msgLength = [NSString stringWithFormat:@"%d",GetExRequest length]];
 [theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
 [theRequest addValue: @"http://tempuri.org/IService1/NewsGet"  forHTTPHeaderField:@"Soapaction"];
[theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPMethod:@"POST"];
[theRequest setHTTPBody: [GetExRequest dataUsingEncoding:NSUTF8StringEncoding]];
NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if(theConnection)
{
webData = [[NSMutableData data] init];
 }
else
{
 NSLog(@"theConnection is NULL");
 }
itemArray =[[NSMutableArray alloc] init];

 }

-(void)connection:(NSURLConnection *)connection didReceiveData: (NSData *)data
{
[webData appendData:data];
}

Hi there, I have problems with webservice connection on objective-c. On 3G connections, our connections are too slow or not working. But on WiFi, my app works fine. 3G connection is fast, but i cant understand why this slowing appears. Should i do something extra for 3G?

When i put breakpoin this section, On 3G time to time it enters in didReceiveData function. But on wifi, it enters always.

Darkface35
  • 78
  • 7

1 Answers1

0

as per my experience in many project your server responding lately may be thats why you are getting late reply on your device in 3G connection.

so my work around is to change default time out to explicit set timeout for my request.

check this

NSURLRequest *request = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:40.0];

use your timeout for proper response.

CodeChanger
  • 7,953
  • 5
  • 49
  • 80