2010-04-11 6 views
0

J'ai une tableview, lorsque l'utilisateur sélectionne une ligne, j'appelle un webservice en fonction de la ligne sélectionnée. Mon problème est que je peux me connecter au webservice mais je ne reçois aucune réponse du webservice. J'ai utilisé le client soap pour tester si webservice fonctionne correctement ou non.iphone tableview & webservice

//rootviewcontroller.m 

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {.... 
    //call to webservice 
    [self connectToWebService]; 
    } 

Sur le débogage je trouve que mon code ne va pas à l'une des méthodes suivantes

-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *) response{} 
-(void) connection:(NSURLConnection *) connection didReceiveData:(NSData *) data {} 
-(void) connection:(NSURLConnection *) connection didFailWithError:(NSError *) error{} 
-(void) connectionDidFinishLoading:(NSURLConnection *) connection {} 

des suggestions où je vais mal ??? grâce

-(void)connectToWebService 
{ 
     NSString *soapMsg = [NSString stringWithFormat: 
         @"<?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>" 
          " <GetCount xmlns=\"http://192.168.1.104/Service1\">" 
          "<PropId>718</PropId>" 
          "</GetCount>" 
          "</soap:Body>" 
          "</soap:Envelope>"]; 
     NSURL *url = [NSURL URLWithString: 
         @"http://192.168.1.104/defpath/service1.asmx"]; 
     NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url]; 
     //---set the headers--- 
     NSString *msgLength = [NSString stringWithFormat:@"%d",[soapMsg length]]; 
     [req addValue:@"text/xml; charset=utf-8" 
     forHTTPHeaderField:@"Content-Type"]; 
     [req addValue:@"http://192.168.1.104/defpath/Service1/GetCount" 
     forHTTPHeaderField:@"SOAPAction"]; 
     [req addValue:msgLength forHTTPHeaderField:@"Content-Length"]; 

     //---set the HTTP method and body--- 
     [req setHTTPMethod:@"POST"]; 
     [req setHTTPBody: [soapMsg dataUsingEncoding:NSUTF8StringEncoding]]; 

     conn = [[NSURLConnection alloc] initWithRequest:req delegate:self]; 
     if (conn) { 
      webData = [[NSMutableData data] retain]; 
      } 
+0

Le contenu de la méthode « connectToWebService » est probablement la clé ici. Pouvons-nous voir le contenu de cette méthode? – gcamp

+0

permettez-moi de reformuler la question ... Quelle méthode devrait être utilisée pour appeler la connexion au service Web lorsque l'utilisateur sélectionne une ligne du tableau? L'appel doit-il être fait à partir de didSelectRowAtIndexPath ??? – jsp

Répondre

0

Je ne sais pas si votre problème est résolu: vous pouvez obtenir la réponse comme ça:

-(void) connection:(NSURLConnection *) connection //Recive response 
didReceiveResponse:(NSURLResponse *) response { 
    [webData setLength: 0]; 
} 
-(void) connection:(NSURLConnection *) connection //Repeative call method and append data to webData 
    didReceiveData:(NSData *) data { 
    [webData appendData:data]; 
} 

-(void) connection:(NSURLConnection *) connection//If error occure error should be displayed 
    didFailWithError:(NSError *) error { 
    NSLog(@"Problème de connexion au service web appelé"); 
    [webData release]; 
    [connection release]; 
} 

-(void) connectionDidFinishLoading:(NSURLConnection *) connection { 
    NSLog(@"OK. Bytes reçues: %d", [webData length]); 

    NSString *theXML = [[NSString alloc] 
         initWithBytes: [webData mutableBytes] 
         length:[webData length] 
         encoding:NSUTF8StringEncoding]; 
    //---shows the XML--- 
    NSLog(theXML); 


    [theXML release]; 
}