Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>With Axeva's help this is what I came up with.</p> <p>iOS code:</p> <pre><code>-(void)checkWithServer { NSOperationQueue *queue = [[NSOperationQueue alloc] init]; NSURL *postURL = [NSURL URLWithString: @"http://texas/WebSite3/Service.asmx/doSomething"]; NSDictionary *jsonDict = [[NSDictionary alloc] initWithObjectsAndKeys: @"test@gmail.com", @"email", @"John Doe", @"name", nil]; NSError *error; NSData *jsonData = [NSJSONSerialization dataWithJSONObject:jsonDict options:0 error:&amp;error]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL: postURL cachePolicy: NSURLRequestUseProtocolCachePolicy timeoutInterval: 60.0]; [request setHTTPMethod: @"POST"]; [request setValue: @"application/json" forHTTPHeaderField: @"Accept"]; [request setValue: @"application/json; charset=utf-8" forHTTPHeaderField: @"content-type"]; [request setHTTPBody: jsonData]; [NSURLConnection sendAsynchronousRequest: request queue: queue completionHandler: ^(NSURLResponse *response, NSData *data, NSError *error) { if (error || !data) { // Handle the error } else { // Handle the success } } ]; } </code></pre> <p>Web-server code:</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Services; using System.Web.Services.Protocols; using System.Web.Script.Services; using System.Runtime.Serialization; using System.Runtime.Serialization.Json; using System.Xml; using System.Xml.Linq; using System.Data; using System.Data.SqlClient; [WebService(Namespace = "http://texas/WebSite3")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. [System.Web.Script.Services.ScriptService] public class Service : System.Web.Services.WebService { public Service () { //Uncomment the following line if using designed components //InitializeComponent(); } [WebMethod] [ScriptMethod(ResponseFormat = ResponseFormat.Json)] public string doSomething(string email, string name) { return "{\"name\": \"" + name + "\", \"email\": \"" + email + "\"}"; } } </code></pre> <p>Apparently the web-server is smart enough to pull the JSON apart and assign the variables name and email.</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