Application works only on a wi-fi

Discussion in 'iPhone/iPad Programming' started by Shrunga, Dec 5, 2009.

  1. macrumors newbie

    Joined:
    Aug 8, 2008
    #1
    I'm having a major problem with my application when using anything other than a wifi connection.

    I'm trying to login using a web-service which just return a success or a failure message based on the credentials.

    For some reason it appears that the following code cant locate the host and times out after the time-out period. This happens only when using Edge/3G but NOT wifi.

    I have pasted the code below. I did try with both synchronous and asychronous calls. But in vain.

    Please let me know if there is anything that Im missing out. Im lost on this , any help is heartily appreciated.

    Code:
    -(void)prepareXMLForLoginRequest
    {
    	
    	NSString *theXMLString = [[NSString alloc] initWithFormat:@"%@%@%@%@%@%@%@%@%@%@",
    							  @"<?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>",
    							  @"<UserLogin xmlns=\"",
    							  SOAPACTION_NAMESPACE_URL,
    							  @"\"><userLogin><LOGIN><EMAIL>",
    							  @"mferraby@wyanokeis.com",
    							  @"</EMAIL><PSWD>",
    							  @"unknown",
    							  @"</PSWD></LOGIN></userLogin></UserLogin></soap:Body></soap:Envelope>"];
    	
    	
    	NSLog(@"Request		:%@",theXMLString);
    	NSString *theWebServiceURLString = [[NSString alloc] initWithFormat:@"%@%@",WEB_SERVICE_URL, @"UserAuthentication.asmx"];
    	
    	NSString *theURLString = [[NSString alloc] initWithFormat:@"%@%@",SOAPACTION_NAMESPACE_URL, @"UserLogin"];
    	NSDictionary *theRequestHeader = [[NSDictionary alloc] initWithObjectsAndKeys:HOST,@"Host",
    	@"text/xml; charset=utf-8", @"Content-Type",
    	theURLString,@"SOAPAction",
    	nil];
    	
    	NSMutableURLRequest  *theRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:theWebServiceURLString]
    	cachePolicy:NSURLRequestUseProtocolCachePolicy
    	timeoutInterval:60.0];
    	[theRequest setHTTPMethod:@"POST"];
    	[theRequest setAllHTTPHeaderFields:theRequestHeader];
    	[theRequest setHTTPBody:[theXMLString dataUsingEncoding:NSUTF8StringEncoding]];
    	[theRequest setHTTPShouldHandleCookies:NO];
    	[theRequest setHTTPShouldHandleCookies:NO];
    	
    	[[NSURLCache sharedURLCache] setMemoryCapacity:0];
    	[[NSURLCache sharedURLCache] setDiskCapacity:0];
    	
    	
    	mURLConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
    	
    	[theXMLString release]; theXMLString = nil;
    	[theURLString release ]; theURLString = nil;
    	[theRequestHeader release]; theRequestHeader = nil;
    	[theWebServiceURLString release]; theWebServiceURLString= nil;
    	
    }
     

Share This Page