0

This is a tough question.

When I press on the button, it is supposed to connect to a URL, which will initiate that method of my wcf service. However, when I debug, I noticed that the connection fails (like none of the delegate methods are called and stuff). I know that my WCF service works because when i type the URL in safari directly, it works perfectly, and performs that method. Here is my code:

- (IBAction)RBCButtonPressed:(id)sender {

//[[UIApplication sharedApplication] openURL:[NSURL URLWithString: @"http://10.1.51.55:8732/windows2/OnApplication?appName=RoyalBank.BankOfTheFuture.Surface.exe&directory=C:\\Program Files (x86)\\Bank of the Future"]];
NSString *urlString = @"http://10.1.51.55:8732/windows2/OnApplication?appName=RoyalBank.BankOfTheFuture.Surface.exe&directory=C:\\Program Files (x86)\\Bank of the Future";
NSLog(urlString);
NSURL *url = [NSURL URLWithString:urlString];
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url ];
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
[connection release];
[request release];
if(connection)
    self.valueReturned = [[NSData data] retain];
else
    NSLog(@"data failed");

NSLog(@"connection failed");
[captureView addSubview:loader];

}

I'm not including the delegate methods cause they aren't called anyway. It prints "connection failed."

UPDATE: When I use a method that takes in only one parameter, it works fine from both the browser and the device (the connection succeeds and the delegate methods are called). However, when there are two parameters, it works fine only from the browser. The connection always fails. Possibilities - the use of the backslash confuses it somehow (?).

This is urgent and any help would be greatly appreciated.

EDIT: It will always print "connection failed" I realize, but I know that the connection fails because 1) the delegate methods aren't called and 2)the application does not turn on, which it will if the method is called.

jaamun
  • 181
  • 2
  • 12
  • 1
    was i not clear or something to merit deprecating my post? Any suggestions to improve the clarity of the question would be appreciated. – jaamun Aug 07 '12 at 21:49

2 Answers2

1

It's failing because you are releasing connection right after you create it. If you're not using ARC, you could create it with autorelease, or just use ARC and forget about the releases.

rdelmar
  • 103,982
  • 12
  • 207
  • 218
  • thanks for a response! Unfortuntely, that cannot be the issue. M update clearly states that the connection succeeds when I change the url to the following: http://10.1.51.55:8732/windows2/offApplicationWeb?appName=RoyalBank.BankOfTheFuture.Surface – jaamun Aug 07 '12 at 22:21
  • this url calls a method that takes one parameter – jaamun Aug 07 '12 at 22:22
  • Sorry, I didn't realize that connection had a retain count of 2 before your release. I copied your code into an app, and it did call my connection:didFailWithError: delegate method, and gave me the message "bad URL". So that is the problem -- sorry I can't help with that. – rdelmar Aug 07 '12 at 23:00
  • Thanks for trying to help me so much! Unfortunately the URL can only work from my company's corporate network. Otherwise it will be a bad URL. I will try implementing the delegate method you specified and post the error as an update. Again, thank you. I appreciate it bc I know my question isn't very straightforward. – jaamun Aug 07 '12 at 23:35
  • you were right in a sense that its a bad url bc the program doesn't encode it correctly – jaamun Aug 08 '12 at 16:19
1

If you check your NSURL object in the debugger, you'll find it's nil immediately after you try to initialize it. This is because it's malformed. Try URL encoding it first.

Notice the URL you pasted into safari changes to this:

http://10.1.51.55:8732/windows2/OnApplication?appName=RoyalBank.BankOfTheFuture.Surface.exe&directory=C:%5C%5CProgram%20Files%20(x86)%5C%5CBank%20of%20the%20Future

See all the %20s and %5Cs, etc.? That's because safari URL encodes it before sending the request. You must do the same.

Best regards.

Community
  • 1
  • 1
Matt Long
  • 24,438
  • 4
  • 73
  • 99