title: argument-passing from iOS to WCF service
body: <p>I need to pass information from the application to the server, specifically a and b in text format. Here is the code the WCF service:</p>
  
  <pre><code>public class iOSService 
  {
  // To use HTTP GET, add [WebGet] attribute. (Default ResponseFormat is WebMessageFormat.Json)
  // To create an operation that returns XML,
  // add [WebGet(ResponseFormat=WebMessageFo rmat.Xml)],
  // and include the following line in the operation body:
  // WebOperationContext.Current.Outgoin gResponse.ContentType = "text/xml";
  [OperationContract]
  public void DoWork()
  {
  // Add your operation implementation here
  return;
  }
  
  // Add more operations here and mark them with [OperationContract]
  
  
  [OperationContract]
  public string iOSTest2(string a, string b)
  {
  string res = "";
  try
  {
  res=(int.Parse(a) + int.Parse(b)).ToString();
  }
  catch (Exception exp)
  {
  res = "Not a number";
  }
  return res;
  }
  
  
  }
  </code></pre>
  
  <p>After receiving a and b, the server adds them, and sends back their sum.</p>
  
  <p>And here is my code to send parameters to the server of an iOS application:</p>
  
  <pre><code>- (IBAction)test:(id)sender {
  
      NSArray *propertyNames = [NSArray arrayWithObjects:@"23", @"342", nil];
      NSArray *propertyValues = [NSArray arrayWithObjects:@"a", @"b",  nil];
  
      NSDictionary *properties = [NSDictionary dictionaryWithObjects:propertyNames forKeys:propertyValues];
  
      NSMutableArray  * arr;
  
      arr=[[NSMutableArray alloc]initWithObjects:properties, nil];
      NSLog(@"%@",arr);
  
      NSError * error;
      NSData *jsonData2 = [NSJSONSerialization dataWithJSONObject:arr options:NSJSONWritingPrettyPrinted error:&amp;error];
  
      NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://www.mathforyou.net/iOSservice.svc/iOSTest2"]];
      NSString *jsonString = [[NSString alloc] initWithData:jsonData2 encoding:NSUTF8StringEncoding];
  
      [request setValue:@"appliction/json" forHTTPHeaderField:@"Content-Type"];
      [request setHTTPMethod:@"POST"];
      [request setHTTPBody:jsonData2];
      NSLog(@"JSON String: %@",jsonString);
      NSError *errorReturned = nil;
      NSURLResponse *theResponse =[[NSURLResponse alloc]init];
      NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&amp;theResponse error:&amp;errorReturned];
      if (errorReturned) {
          //...handle the error
          NSLog(@"error");
      }
      else {
          NSString *retVal = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
  
          NSLog(@"%@",retVal);
      }
  }
  </code></pre>
  
  <p>But the server answers me the following message:</p>
  
  <pre><code>"ExceptionDetail":null,"ExceptionType":null,"Message":"The server was unable to process the request due to an internal error.  For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the &lt;serviceDebug&gt; configuration behavior) on the server in order to send the exception information back to the client, or turn on tracing as per the Microsoft .NET Framework SDK documentation and inspect the server trace logs.","StackTrace":null
  </code></pre>
  
  <p>And here is the logs from Xcode:</p>
  
  <pre><code>2013-03-01 17:38:28.657 2231233122[3442:c07] (
          {
          a = 23;
          b = 342;
      }
  )
  2013-03-01 17:38:28.659 2231233122[3442:c07] JSON String: [
    {
      "a" : "23",
      "b" : "342"
    }
  ]
  2013-03-01 17:38:29.054 2231233122[3442:c07] {"ExceptionDetail":null,"ExceptionType":null,"Message":"The server was unable to process the request due to an internal error.  For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the &lt;serviceDebug&gt; configuration behavior) on the server in order to send the exception information back to the client, or turn on tracing as per the Microsoft .NET Framework SDK documentation and inspect the server trace logs.","StackTrace":null}
  </code></pre>
  
  <p><strong>P.S.</strong> I asked a friend to help me, but since he does not know objective-c wrote a program just for C++ and the code works, so the problem is not in the server. Here is the code:</p>
  
  <pre><code>string data = "{\"a\":\"560\",\"b\":\"90\"}";
  
  byte[] bd = Encoding.UTF8.GetBytes(data);
  
  HttpWebRequest wr = (HttpWebRequest)HttpWebRequest.Create("http://www.mathforyou.net/IOSService.svc/iOSTest2");
  wr.ContentType = "application/json";
  wr.Method = "POST";
  wr.ContentLength = bd.Length;
  Stream sw = wr.GetRequestStream();
  sw.Write(bd, 0, bd.Length);
  sw.Close();
  HttpWebResponse resp = (HttpWebResponse)wr.GetResponse();
  Stream s = resp.GetResponseStream();
  byte[] bres = new byte[resp.ContentLength];
  s.Read(bres, 0, bres.Length);
  string ans = Encoding.UTF8.GetString(bres);
  Console.WriteLine(ans);
  </code></pre>
  
  <p>Please help, I'm worn out.</p>