You can build a URL that contains the properties of MyClass on the query string and invoke the remote client with HttpClient (or a third party option like RestSharp).
In addition, you need to mark your WebAPI endpoint method with [FromUri] so that it knows to expect a complex type from the query string rather than the request body.
[HttpGet("/")]
public string Index ([FromUri] MyClass aclass) {
...
}
using (var client = new HttpClient())
{
client.BaseAddress = new Uri("http://.../");
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var url = String.Format("api/ControllerName?ID={0}&Dept={1}",
myModel.ID, myModel.Dept);
HttpResponseMessage response = await client.GetAsync(url);
if (response.IsSuccessStatusCode)
{
MyModel model = await response.Content.ReadAsAsync<MyModel>();
}
}
In this particular case you actually don't need to create a JSON string since you can pass all of the required data on the query string. If you don't want to expose the data, you should consider changing it to a post, at which point you can post the object directly.
...
response = await client.PostAsJsonAsync(url, myModel);
...
C#class instead of creating aJSONobject and then passing it to a web api that takes a c# class?