Note that there are some explanatory texts on larger screens.

plurals
  1. POWCF call nested in a WCF call
    text
    copied!<p>I have a backend made in C#, where I am making WCF calls to from iOS. It works pretty good, but I am stuck in a problem Code:</p> <pre><code>#import "ListTableViewController.h" #import "ListServiceSvc.h" #import "LoginViewController.h" @interface ListTableViewController (){ NSMutableArray *productsFromWebServer; NSMutableDictionary *prodForList; } @property (nonatomic, retain) NSMutableArray *shoppingList; @property (nonatomic, retain) NSMutableArray *productList; @end @implementation ListTableViewController - (id)initWithStyle:(UITableViewStyle)style { self = [super initWithStyle:style]; if (self) { // Custom initialization } return self; } - (void) viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; NSUserDefaults *standardUserDefaults = [NSUserDefaults standardUserDefaults]; Boolean b = [standardUserDefaults boolForKey:@"HasTokenKey"]; if (!b) { [self showLoginViewController]; } [self loadListsFromRemoteServer]; [self.tableView reloadData]; //self.uname.text = [standardUserDefaults objectForKey:@"username"]; } - (void) showLoginViewController { LoginViewController* loginController = (LoginViewController*) [ApplicationDelegate.storyBoard instantiateViewControllerWithIdentifier:@"LoginViewController"]; [self presentViewController:loginController animated:YES completion:nil]; } - (void)userDidLeave { NSUserDefaults *standardUserDefaults = [NSUserDefaults standardUserDefaults]; [standardUserDefaults setBool:NO forKey:@"HasTokenKey"]; // Show the Login screen. [self showLoginViewController]; } - (IBAction)exitAction { [self userDidLeave]; } - (void)viewDidLoad { _shoppingList = [NSMutableArray array]; _productList = [NSMutableArray array]; //[self loadListsFromRemoteServer]; [super viewDidLoad]; } -(void) loadListsFromRemoteServer { NSString *uname = [[NSUserDefaults standardUserDefaults] objectForKey:@"username"]; NemListBinding *binding = [[ListServiceSvc NemListBinding]initWithAddress:@"http://balder/dm76_gr5/WCF.ListService.svc/custom?singleWsdl"]; binding.logXMLInOut=YES; ListServiceSvc_GetShoppingListsWithUname *parms = [[ListServiceSvc_GetShoppingListsWithUname alloc]init]; parms.uname = uname; [binding GetShoppingListsWithUnameAsyncUsingParameters:parms delegate:self]; } -(void) loadItemsInList:(NSNumber*)slistId { NemListBinding *binding = [[ListServiceSvc NemListBinding]initWithAddress:@"http://balder/dm76_gr5/WCF.ListService.svc/custom?singleWsdl"]; binding.logXMLInOut=YES; ListServiceSvc_GetProductsWithListId *parms = [[ListServiceSvc_GetProductsWithListId alloc]init]; parms.listId = slistId; [binding GetProductsWithListIdAsyncUsingParameters:parms delegate:self]; } - (void) operation:(NemListBindingOperation *)operation completedWithResponse:(NemListBindingResponse *)response { NSArray *responseHeaders = response.headers; NSArray *responseBodyParts = response.bodyParts; [NSThread sleepForTimeInterval:1.0]; NSMutableArray *shoppingListFromWebserver = [[NSMutableArray alloc] init]; productsFromWebServer = [[NSMutableArray alloc]init]; prodForList = [[NSMutableDictionary alloc]init]; // step 1 fill in the blanks. for(id header in responseHeaders) { // here do what you want with the headers, if there's anything of value in them } for (id mine in responseBodyParts) { if ([mine isKindOfClass:[ListServiceSvc_GetShoppingListsWithUnameResponse class]]) { for (id slist in [[mine GetShoppingListsWithUnameResult] ShoppingList]) { [shoppingListFromWebserver addObject:slist]; [self loadItemsInList:[slist ShoppingListId]]; //NSLog(@"new list :: RESPONSE FROM SERVER :: nList %@", [slist ShoppingListName]); } } if ([mine isKindOfClass:[ListServiceSvc_GetProductsWithListIdResponse class]]) { for (id products in [[mine GetProductsWithListIdResult] Product]) { [prodForList setObject:[products ProductName] forKey:[products ShoppingListId]]; NSLog(@"new product :: RESPONSE FROM SERVER :: nList %@", [products ProductName]); } } } [self performSelectorOnMainThread:@selector(updateNewView:) withObject:shoppingListFromWebserver waitUntilDone:NO]; } -(void) updateNewView:(NSMutableArray*) result { _shoppingList = result; NSLog( @"new list - number of news :: %u", [_shoppingList count]); [self.tableView reloadData]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } #pragma mark - Table view data source - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; // the number of different sections in your table view } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { // Return the number of rows in the section. return [_shoppingList count]; // the number of data in your shopping list } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"ListCell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier]; } //cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; // Configure the cell... id shopList = [_shoppingList objectAtIndex:indexPath.row]; cell.textLabel.text = [shopList ShoppingListName]; NSNumber *sid = [shopList ShoppingListId]; //[self loadItemsInList:sid]; NSNumber *prodcount = [prodForList objectForKey:sid]; NSString* pcTostring = [NSString stringWithFormat:@"%@", prodcount]; cell.detailTextLabel.text = pcTostring; return cell; </code></pre> <p>The log actually tells me that I am getting some products for the last List it gets. Problem is that all <code>cell.detailText.text</code> fields are null, until the last reload, then all cells disappear.</p> <p>I am pretty sure I'm doing it wrong, but I cant get my head around hot to get the products for the selected list, when I need to get the ShoppingListId from the <code>-(void) loadListsFromRemoteServer</code> call in order to do the <code>-(void) loadItemsInList:(NSNumber*)slistId</code></p> <p>WCF connection was made with the help of wsdl2obj</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload