Problem calling web service from another class

Discussion in 'iOS Programming' started by Amit Jain, Jul 6, 2009.

  1. Amit Jain macrumors member

    Joined:
    Apr 9, 2007
    #1
    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
     
  2. drivefast macrumors regular

    Joined:
    Mar 13, 2008
    #2
    do you create anywhere an object which is an instance of the class that implements the connection functionality?
     
  3. Amit Jain thread starter macrumors member

    Joined:
    Apr 9, 2007
    #3
    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
     
  4. drivefast macrumors regular

    Joined:
    Mar 13, 2008
    #4
    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.
     
  5. Amit Jain thread starter macrumors member

    Joined:
    Apr 9, 2007
    #5
    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
     
  6. Amit Jain thread starter macrumors member

    Joined:
    Apr 9, 2007
    #6
    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
     

Share This Page