/// <summary> /// Executes a PUT request against the partner service. /// </summary> /// <typeparam name="TRequest">Type of resource being sent.</typeparam> /// <typeparam name="TResource">Type of resource to be returned.</typeparam> /// <param name="relativeUri">Relative address of the request.</param> /// <param name="content">The content for the body of the request.</param> /// <param name="parameters">Query string parameters that will be added to the address.</param> /// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param> /// <returns>The response from the HTTP PUT request.</returns> public async Task <TResource> PutAsync <TRequest, TResource>(Uri relativeUri, TRequest content, IDictionary <string, string> parameters = null, CancellationToken cancellationToken = default) { Uri address = new Uri(Endpoint, relativeUri); string invocationId = null; if (parameters != null) { address = address.AddQueryParemeters(parameters); } using (HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Put, address)) { await AddRequestHeadersAsync(request).ConfigureAwait(false); request.Content = new StringContent(JsonConvert.SerializeObject(content, GetSerializationSettings())); request.Content.Headers.ContentType = new MediaTypeHeaderValue(MediaType); if (ServiceClientTracing.IsEnabled) { invocationId = ServiceClientTracing.NextInvocationId.ToString(); Dictionary <string, object> tracingParameters = new Dictionary <string, object> { { "relativeUri", relativeUri }, { "content", content }, { "parameters", parameters }, { "cancellationToken", cancellationToken } }; ServiceClientTracing.Enter(invocationId, this, "Put", tracingParameters); } return(await HandleResponseAsync <TResource>(invocationId, request, cancellationToken).ConfigureAwait(false)); } }
/// <summary> /// Executes a HTTP GET request against the partner service. /// </summary> /// <typeparam name="TResource">Type of resource to be returned.</typeparam> /// <param name="relativeUri">Relative address of the request.</param> /// <param name="headers">Additional headers to be added to the request.</param> /// <param name="parameters">Query string parameters that will be added to the address.</param> /// <param name="converter">A JSON converter used to deserialize the response.</param> /// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param> /// <returns>The response from the HTTP GET request.</returns> public async Task <TResource> GetAsync <TResource>(Uri relativeUri, IDictionary <string, string> headers = null, IDictionary <string, string> parameters = null, JsonConverter converter = null, CancellationToken cancellationToken = default) { Uri address = new Uri(Endpoint, relativeUri); string invocationId = null; if (parameters != null && parameters.Count > 0) { address = address.AddQueryParemeters(parameters); } using (HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, address)) { await AddRequestHeadersAsync(request).ConfigureAwait(false); if (ServiceClientTracing.IsEnabled) { invocationId = ServiceClientTracing.NextInvocationId.ToString(); Dictionary <string, object> tracingParameters = new Dictionary <string, object> { { "relativeUri", relativeUri }, { "headers", headers }, { "parameters", parameters }, { "converter", converter }, { "cancellationToken", cancellationToken } }; ServiceClientTracing.Enter(invocationId, this, "Get", tracingParameters); } return(await HandleResponseAsync <TResource>(invocationId, request, converter, cancellationToken).ConfigureAwait(false)); } }
/// <summary> /// Executes a PUT request against the partner service. /// </summary> /// <typeparam name="TRequest">Type of resource being sent.</typeparam> /// <typeparam name="TResource">Type of resource to be returned.</typeparam> /// <param name="relativeUri">Relative address of the request.</param> /// <param name="content">The content for the body of the request.</param> /// <param name="parameters">Query string parameters that will be added to the address.</param> /// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param> /// <returns>The response from the HTTP PUT request.</returns> public async Task <TResource> PutAsync <TRequest, TResource>(Uri relativeUri, TRequest content, IDictionary <string, string> parameters = null, CancellationToken cancellationToken = default) { HttpResponseMessage response = null; Uri address; try { address = new Uri(Endpoint, relativeUri); if (parameters != null) { address = address.AddQueryParemeters(parameters); } using (HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Put, address)) { AddRequestHeaders(request); request.Content = new StringContent(JsonConvert.SerializeObject(content, GetSerializationSettings())); request.Content.Headers.ContentType = new MediaTypeHeaderValue(MediaType); response = await HttpClient.SendAsync(request, cancellationToken).ConfigureAwait(false); return(await HandleResponseAsync <TResource>(response).ConfigureAwait(false)); } } finally { response?.Dispose(); } }
/// <summary> /// Executes a HTTP GET request against the partner service. /// </summary> /// <typeparam name="TResource">Type of resource to be returned.</typeparam> /// <param name="relativeUri">Relative address of the request.</param> /// <param name="headers">Additional headers to be added to the request.</param> /// <param name="parameters">Query string parameters that will be added to the address.</param> /// <param name="converter">A JSON converter used to deserialize the response.</param> /// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param> /// <returns>The response from the HTTP GET request.</returns> public async Task <TResource> GetAsync <TResource>(Uri relativeUri, IDictionary <string, string> headers = null, IDictionary <string, string> parameters = null, JsonConverter converter = null, CancellationToken cancellationToken = default) { HttpResponseMessage response = null; Uri address; try { address = new Uri(Endpoint, relativeUri); if (parameters != null) { address = address.AddQueryParemeters(parameters); } using (HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, address)) { AddRequestHeaders(request, headers); response = await HttpClient.SendAsync(request, cancellationToken).ConfigureAwait(false); return(await HandleResponseAsync <TResource>(response, converter).ConfigureAwait(false)); } } finally { response?.Dispose(); } }
/// <summary> /// Executes a HTTP GET request against the partner service. /// </summary> /// <typeparam name="TResource">Type of resource to be returned.</typeparam> /// <param name="relativeUri">Relative address of the request.</param> /// <param name="headers">Additional headers to be added to the request.</param> /// <param name="parameters">Query string parameters that will be added to the address.</param> /// <param name="converter">A JSON converter used to deserialize the response.</param> /// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param> /// <returns>The response from the HTTP GET request.</returns> public async Task <TResource> GetAsync <TResource>(Uri relativeUri, IDictionary <string, string> headers = null, IDictionary <string, string> parameters = null, JsonConverter converter = null, CancellationToken cancellationToken = default) { Uri address = new Uri(Endpoint, relativeUri); if (parameters != null && parameters.Count > 0) { address = address.AddQueryParemeters(parameters); } using (HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, address)) { await AddRequestHeadersAsync(request).ConfigureAwait(false); return(await HandleResponseAsync <TResource>(request, converter, cancellationToken).ConfigureAwait(false)); } }