title: Consume WCF service in xcode 5 and ios 7
body: <p>I have created a WCF Service to insert data in sql server, so that why I have followed the below structure.</p>
  
  <p>I created first the method and his Implementation;</p>
  
  <p>In WCF interface:</p>
  
  <pre><code>[OperationContract]
  [WebInvoke(Method = "POST",
      ResponseFormat = WebMessageFormat.Json,
      RequestFormat = WebMessageFormat.Json,
      BodyStyle = WebMessageBodyStyle.Wrapped,
      UriTemplate = "json/InsertEmployee/{id1}/{id2}/{id3}")]
  bool InsertEmployeeMethod(string id1,string id2, string id3);
  </code></pre>
  
  <p>In Implementation:</p>
  
  <pre><code>    public bool InsertEmployeeMethod(string id1, string id2, string id3)
      {
  
          int success = 0;
  
          using (SqlConnection conn = new SqlConnection("Data Source=NXT1;User ID=zakaria;Password=11;Initial Catalog=EmpDB;Integrated Security=false"))
          {
              conn.Open();
  
              decimal value = Decimal.Parse(id3);
              string cmdStr = string.Format("INSERT INTO EmpInfo VALUES('{0}','{1}',{2})", id1, id2, value);
              SqlCommand cmd = new SqlCommand(cmdStr, conn);
              success = cmd.ExecuteNonQuery();
  
              conn.Close();
          }
  
          return (success != 0 ? true : false);
      }
  </code></pre>
  
  <p>to test the web service, try that URL:    </p>
  
  <pre><code>"41.142.251.142/JsonWcfService/GetEmployees.svc/json/InsertEmployee/myName/MylastName/6565"
  </code></pre>
  
  <p>until here all is working well,</p>
  
  <p>So to test this web servcie, I created in my Main.storyboard 3 textFields (firstName.text and lastName.text and salary.text and a button to send the data entered). note that I have worked with xcode 5 and ios 7.</p>
  
  <p>I declared the url inside my viewcontroller.m as following:
  myViewController.m:</p>
  
  <pre><code>#define BaseWcfUrl [NSURL URLWithString:@"41.142.251.142/JsonWcfService/GetEmployees.svc/json/InsertEmployee/{id1}/{id2}/{id3}"]
  </code></pre>
  
  <p>Then I implemented the Insert Employee Method related to click button.</p>
  
  <pre><code>-(void) insertEmployeeMethod
  
  {
  
  if(firstname.text.length &amp;&amp; lastname.text.length &amp;&amp; salary.text.length)
  
  {
  
  NSString *getValue= [BaseWcfUrl stringByAppendingFormat:@"InsertEmployee/%@/%@/%@",firstname.text,lastname.text,salary.text];
  
  NSURL *WcfServiceURL = [NSURL URLWithString:getValue];
  NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
  
  [request setURL:WcfServiceURL];
  
  [request setHTTPMethod:@"POST"];
  
  // connect to the web
  
  NSData *respData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
  
  // NSString *respStr = [[NSString alloc] initWithData:respData encoding:NSUTF8StringEncoding];
  
  
  NSError *error;
  
  NSDictionary* json = [NSJSONSerialization 
  
                        JSONObjectWithData:respData 
  
                        options:NSJSONReadingMutableContainers 
  
                        error:&amp;error];  
  
  
  
  NSNumber *isSuccessNumber = (NSNumber*)[json objectForKey:@"InsertEmployeeMethodResult"];
      }
  
  }
  </code></pre>
  
  <p>So the issue that I have encountered is that the system always return the str value as "Nil"</p>
  
  <pre><code>NSString *getValue= [BaseWcfUrl stringByAppendingFormat:@"InsertEmployee/%@/%@/%@",firstname.text,lastname.text,salary.text];
  </code></pre>
  
  <p>so you can see all the message error here :</p>
  
  <blockquote>
    <p>2014-02-17 19:49:49.419 InsertData[2384:70b] <strong>* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'data parameter is nil'
    *</strong> First throw call stack:</p>
    
    <p>0   CoreFoundation                      0x017395e4 __exceptionPreprocess + 180</p>
    
    <p>1   libobjc.A.dylib                     0x014bc8b6 objc_exception_throw + 44</p>
    
    <p>2   CoreFoundation                      0x017393bb +[NSException raise:format:] + 139</p>
    
    <p>3   Foundation                          0x012037a2 +[NSJSONSerialization JSONObjectWithData:options:error:] + 67</p>
    
    <p>4   InsertData                          0x0000236c -[ViewController sendData:] + 1452</p>
    
    <p>5   libobjc.A.dylib                     0x014ce874 -[NSObject performSelector:withObject:withObject:] + 77</p>
    
    <p>6   UIKit                               0x0022c0c2 -[UIApplication sendAction:to:from:forEvent:] + 108</p>
    
    <p>7   UIKit                               0x0022c04e -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 61</p>
    
    <p>8   UIKit                               0x003240c1 -[UIControl sendAction:to:forEvent:] + 66</p>
    
    <p>9   UIKit                               0x00324484 -[UIControl _sendActionsForEvents:withEvent:] + 577</p>
    
    <p>10  UIKit                               0x00323733 -[UIControl touchesEnded:withEvent:] + 641</p>
    
    <p>11  UIKit                               0x0026951d -[UIWindow _sendTouchesForEvent:] + 852</p>
    
    <p>12  UIKit                               0x0026a184 -[UIWindow sendEvent:] + 1232</p>
    
    <p>13  UIKit                               0x0023de86 -[UIApplication sendEvent:] + 242</p>
    
    <p>14  UIKit                               0x0022818f _UIApplicationHandleEventQueue + 11421</p>
    
    <p>CoreFoundation                      0x016c283f <strong>CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION</strong> + 15</p>
    
    <p>16  CoreFoundation                      0x016c21cb __CFRunLoopDoSources0 + 235</p>
    
    <p>17  CoreFoundation                      0x016df29e __CFRunLoopRun + 910</p>
    
    <p>18  CoreFoundation                      0x016deac3 CFRunLoopRunSpecific + 467</p>
    
    <p>19  CoreFoundation                      0x016de8db CFRunLoopRunInMode + 123</p>
    
    <p>20  GraphicsServices                    0x036de9e2 GSEventRunModal + 192</p>
    
    <p>21  GraphicsServices                    0x036de809 GSEventRun + 104</p>
    
    <p>22  UIKit                               0x0022ad3b UIApplicationMain + 1225</p>
    
    <p>23  InsertData                          0x00002d5d main + 141</p>
    
    <p>24  libdyld.dylib                       0x01d7770d start + 1</p>
    
    <p>)
    libc++abi.dylib: terminating with uncaught exception of type NSException</p>
  </blockquote>
  
  <p>can you please help me on that, i'm very stressed with.</p>
  
  <p>much appreciate .</p>