title: Windows Phone 8 call WCF web service
body: <p>I have been tasked with writing a WP8 application that needs to link to a WCF web service but I can't for the life of me figure out what I am doing wrong</p>
  
  <p>I can't change the WCF service, it's not mine</p>
  
  <p>The method I am struggling with takes a class as a parameter and returns a different class as the result</p>
  
  <p>The interface I have been given for a test method is:</p>
  
  <pre><code>[OperationContract]
  [WebInvoke(Method = "POST",
      BodyStyle = WebMessageBodyStyle.Wrapped,
      ResponseFormat = WebMessageFormat.Json,
      RequestFormat = WebMessageFormat.Json,
      UriTemplate = "TestLogin")]
  TestResults TestLogin(TestDetails Test);
  
  public class TestDetails
  {
      public string Username { get; set; }
      public string Password { get; set; }
      public string DeviceId { get; set; }
  }
  
  public string TestResult
  {
      public int TestId { get; set; }
      public List&lt;TestOrders&gt; Orders { get; set; }
  }
  </code></pre>
  
  <p>I have tried RestSharp but I just get a bad request</p>
  
  <p>Any advice will be much appreciated</p>
  
  <p>Here's my sample code:</p>
  
  <pre><code>var client = new RestClient
  {
          BaseUrl = "http://www.testing.co.uk/Services/Service.svc"
  };
  
  var dto = new TestDetails
  {
      username = "abc",
      password = "123",
      DeviceId = String.Empty,
      DeviceModel = String.Empty
  };
  
  var request = new RestRequest
  {
      Resource = "Testlogin",
      RequestFormat = DataFormat.Json,
      Method = Method.POST
  };
  
  request.AddParameter("TestDetails", dto, ParameterType.RequestBody);
  // request.AddBody(dto);
  var response = client.Post&lt;TestResult&gt;(request);
  </code></pre>