Skip to main content

Help of C# api sample code

Hi

Can you please advise what the reference of EndPointProvider and ServiceRequest<PersonContainer>, it shows error (both object are not existing) when I build the PesonSerivce.cs file.

publicPerson CreatePerson(Person person)

{

string endpoint = EndPointProvider.GetCreatePersonEndPoint();

var container = newPersonContainer(person);

var request = new ServiceRequest<PersonContainer>(endpoint, container);

PersonContainer result = PostWithResult<PersonContainer, PersonContainer>(request);

return result.Person;

}

 

And same issue happens on the Service.cs,  Task<HttpResponseMessage>,

ConfigProvider and MediaTypeWithQualityHeaderValue("application/json") cannot be found.

Such as code below

 

 

privatevoid SendRequest<T>(ServiceRequest<T> request, Func<HttpClient, Task<HttpResponseMessage>> sendFunc)

whereT : class

{

using (var client = newHttpClient())

{

client.Timeout = ConfigProvider.ServiceTimeout;

client.DefaultRequestHeaders.Accept.Clear();

client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

Task<HttpResponseMessage> postTask = sendFunc(client);

Task.WaitAll(postTask);

HttpResponseMessage response = postTask.Result;

if (response.IsSuccessStatusCode)

{

return;

}

Task<string> responseTask = response.Content.ReadAsStringAsync();

Task.WaitAll(responseTask);

string responseText = responseTask.Result;

string payloadString = request.Payload != null ? JsonConvert.SerializeObject(request.Payload) : null;

Logger.Error("Error sending {0} to: {1}. Response: {2}", payloadString, request.Endpoint, responseText);

thrownewInvalidOperationException("API call failed.");

}

}

 

 

regards

Stanley

Share this post

Be the first to comment

How would you tag this suggestion?
Please check your e-mail for a link to activate your account.