title: How can I use a query string with a WCF Service?
body: <p>I'm trying to create web services, and they've been working great so far, but I have one problem: if my query string isn't in the exact order I specify it to be in, the code gives me incorrect results.</p>
  
  <p>Before embarking on a large project, I would like to be able to pass in a query string so that order doesn't matter - passing in "?user=foo&amp;pass=bar" should be equivalent to "?pass=bar&amp;user=foo", but I'm just not sure how to get that working as expected.</p>
  
  <p>As it is, I don't get an error from changing the query string parameters around, but rather DBAgent.authenticate() will just accept the parameters in order regardless of parameter names in the query string.  </p>
  
  <p>What am I missing?</p>
  
  <p>IDBAgent.cs:</p>
  
  <pre><code>public interface IDBAgent
  {
      [OperationContract]
      [WebInvoke(UriTemplate = "/authenticate/?username={username}&amp;password={password}", Method = "GET", BodyStyle = WebMessageBodyStyle.WrappedRequest, ResponseFormat = WebMessageFormat.Json)]
      string authenticate(string username, string password);
  }
  </code></pre>
  
  <p>DBAgent.svc.cs</p>
  
  <pre><code>public class DBAgent : IDBAgent
  {
      public string authenticate(string username, string password)
      {
          return runSQL("EXEC sp_Authenticate '" + username + "', '" + password + '\'');
      }
  }
  </code></pre>
  
  <p>index.html:</p>
  
  <pre><code>var output = "";
  function callService(url, params)
  {
      try {
          return $.ajax({
              type: "GET",
              async: false,
              url: url,
              contentType: "application/json; charset=utf-8",
              dataType: "json",
              processdata: true,
              success: function (msg) {
                  output = msg;
              },
              error: function(){console.log("Oops.")}
          });
      }
      catch (e) {
          console.log("Something went wrong! (╯°□°）╯︵ ┻━┻");
      }
  }
  
  function authenticate(user, pass)
  {
      callService("http://localhost/DBAgent.svc/authenticate/?username=foo&amp;password=bar", []).done();    // Returns true
      console.log(output);
      callService("http://localhost/DBAgent.svc/authenticate/?password=bar&amp;username=foo", []).done();    // Returns false
      console.log(output);
      callService("http://localhost/DBAgent.svc/authenticate/?password=foo&amp;username=bar", []).done();    // Returns true
      console.log(output);
  }
  </code></pre>