title: WCF GET method not getting latest data for iOS Client
body: <p>I'm running into a weird situation with my WCF service and iOS client and I'm not really sure what is going on. The problem is if I add data with my WCF POST method in my client and then call the GET to get all the data from that table, all data from the POST is not returned to the client. To clarify further:</p>
  
  <ol>
  <li>Assume table Users has one user John</li>
  <li>I call the GET method to get all Users from the table.</li>
  <li>John shows up in my iOS client.</li>
  <li>now I POST from my iOS client, adding user Mike</li>
  <li>Mike appears in the database and the POST is successful.</li>
  <li>I call the GET method again for all Users but this time Mike doesn't show up in the 
  response, only John does.</li>
  </ol>
  
  <p>I've also noticed that if I delete the app from my iPhone, then add it back with Xcode and then run the GET method, all the data from the Users table is returned. I'm not sure if the data is being cached somewhere or what. I suspect the problem might be in how my client code is running the GET but I'm not entirely sure and it could be my server code too. Here is my code below.</p>
  
  <p>//WCF Service Code</p>
  
  <p>//IService.cs</p>
  
  <pre><code>  [OperationContract]
          [WebInvoke(Method ="GET", ResponseFormat= WebMessageFormat.Json, BodyStyle= WebMessageBodyStyle.WrappedResponse, UriTemplate = "/GetUsers")]
          string GetMyUsers();
  
  [OperationContract]
      [WebInvoke(Method = "POST", RequestFormat=WebMessageFormat.Json, BodyStyle=WebMessageBodyStyle.WrappedRequest, ResponseFormat = WebMessageFormat.Json, UriTemplate = "/NewUser")]
      string AddNewUser(NewUser newUser);
  
  
  [DataContract]
  public class NewUser
  {
      [DataMember(Name="name")]
      public string name { get; set; }
  
  
  
      [DataMember(Name="age")]
      public string age { get; set; }
  }
  </code></pre>
  
  <p>//Service1.svc.cs</p>
  
  <pre><code> public  string AddNewUser(NewUser newUser)
          {
  
              var userController = new UserController();
  
              userController.AddNewUser(newUser.name, newUser.age);
  
              return "Method Call Complete";
          }
  
     public string GetMyUsers()
          {
              var userController = new UserController();
  
              string returnString = userController.GetAllUsers();
  
              return returnString;
          }
  </code></pre>
  
  <p>//UserController.cs</p>
  
  <pre><code>  public string GetAllUsers()
          {
              using(var db = new EmployeesEntities1())
              {
                  string returnString = string.Empty;
  
                  List&lt;User&gt; userList = db.Users.ToList();
  
                  JavaScriptSerializer jss = new JavaScriptSerializer();
  
                  returnString = jss.Serialize(userList);
  
                  return returnString;
              }
          }
  </code></pre>
  
  <p>//IOS Client Side GET</p>
  
  <pre><code>NSString *restCallString = [NSString stringWithFormat:@"http://myPublicIP/MyService/Service1.svc/GetUsers"];
  
  NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:restCallString]];
  [request setHTTPMethod:@"GET"];
  [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
  
  NSError *error = nil;
  NSURLResponse *response = nil;
  
  NSData *result = [NSURLConnection sendSynchronousRequest:request returningResponse:&amp;response error:&amp;error];
  
  NSDictionary *jsonArray=[NSJSONSerialization JSONObjectWithData:result options:0 error:nil];
  
  NSString  *item = [jsonArray objectForKey:@"GetMyUsersResult"];
  
  txtData.text = item;
  </code></pre>
  
  <p>//IOS Client Side POST</p>
  
  <pre><code>  NSArray *propertyNames = [NSArray arrayWithObjects:@"name", @"age",nil];
      NSArray *propertyValues = [NSArray arrayWithObjects:@"Mike", @"23",nil];
  
      NSDictionary *properties = [NSDictionary dictionaryWithObjects: propertyValues forKeys:propertyNames];
  
      NSMutableDictionary *newUserObject = [NSMutableDictionary dictionary];
  
      [newUserObject setObject:properties forKey:@"newUser"];
  
  
      NSData *jsonData = [NSJSONSerialization dataWithJSONObject:newUserObject options:kNilOptions error:nil];
  
      NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
  
         NSString *urlString = [NSString stringWithFormat:@"http://myPublicIP/MyService/Service1.svc/NewUser"];
  
      NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:urlString]];
      [request setValue:jsonString forHTTPHeaderField:@"json"];
  
      [request setHTTPMethod:@"POST"];
      [request setHTTPBody:jsonData];
      [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
  
      NSError *error = nil;
      NSURLResponse *theResponse = [[NSURLResponse alloc]init];
      NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&amp;theResponse error:&amp;error];
  
      if(error)
      {
          txtData.text = [error localizedDescription];
      }
  
      else
      {
          NSMutableString *retVal = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
      }
  </code></pre>
  
  <p>I've also tested the /GetUsers method running on localhost and this method always returns the latest list of users from the Users table to the web browser. The problem seems to be somewhere between the service and the client. I'm new to web services, any help or advice would be appreciated. </p>