Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Amit Jain

macrumors member
Original poster
Apr 9, 2007
45
0
Hi All,
I have a problem in calling a web service from another class.

I am taking reference from Hello_Soap Example. Whenever I call a web service as shown in example it works fine and calls following methods internally.

-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response

-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
-(void)connectionDidFinishLoading:(NSURLConnection *)connection

now I want that the web service should be called by a function call from other class. Whenever I call the function web service gets called but the control goes back to calling class without executing above 3 methods and the parsing.
I want the call to web service and parsing to be in a separate class.
These methods are not getting called. How to do it?
Thanks in advance.
Amit
 
do you create anywhere an object which is an instance of the class that implements the connection functionality?
 
do you create anywhere an object which is an instance of the class that implements the connection functionality?

Yes I call the webservice method from another class by making the instance of the class that implements the connection functionality.
Is that the reason ? If yes then how can be call the web service method without making an instance?
Please help.
regards..
Amit
 
no, youre doing the right thing. another thing that i can think of is to make sure you set the delegate of the NSURLConnection object as you want it - in your case to an instance of your parsing class, if i understood correctly.
 
no, youre doing the right thing. another thing that i can think of is to make sure you set the delegate of the NSURLConnection object as you want it - in your case to an instance of your parsing class, if i understood correctly.

Thanx a lot, we are already doing this in the Webservice Class
Code:
NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];

We have taken self because this Connection methods are written in Parser class only. But still same problem.
I will explain you in detail: there are three classes-> Webservice class, where all parsing and web service calling functionality is written. We have written one method in this class that initiates the webservice call and parsing of XML. The other two classes suppose A & B that want to use this webservice by calling the above method.
Code:
//Class A
#import "Webservice.h"
- viewDidLoad
{
Webservice *ws = [[Webservice alloc] init];
[ws callWebservice];
statement 1..
Statement 2..
...   
}

Now what happens is [ws callWebservice]; this method gets called but returns without executing the following delegate methods written in Webservice class
Code:
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data 
-(void)connectionDidFinishLoading:(NSURLConnection *)connection

after executing statement 1, statement 2 in class A , then the control goes back to above these methods.
Please help.
Thnx
 
Thanx a lot, we are already doing this in the Webservice Class
Code:
NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];

We have taken self because this Connection methods are written in Parser class only. But still same problem.
I will explain you in detail: there are three classes-> Webservice class, where all parsing and web service calling functionality is written. We have written one method in this class that initiates the webservice call and parsing of XML. The other two classes suppose A & B that want to use this webservice by calling the above method.
Code:
//Class A
#import "Webservice.h"
- viewDidLoad
{
Webservice *ws = [[Webservice alloc] init];
[ws callWebservice];
statement 1..
Statement 2..
...   
}

Now what happens is [ws callWebservice]; this method gets called but returns without executing the following delegate methods written in Webservice class
Code:
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data 
-(void)connectionDidFinishLoading:(NSURLConnection *)connection

after executing statement 1, statement 2 in class A , then the control goes back to above these methods.
Please help.
Thnx
Found various answers here, hope it helps someone:
1.https://devforums.apple.com/message/94855#94855
2.http://stackoverflow.com/questions/1096493/calling-web-service-from-another-class
3.http://www.iphonedevsdk.com/forum/i...580-web-service-calling-issue.html#post101233
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.