sdk/dotnet/src/Microsoft.Datasync.Client/Http/ServiceHttpClient.cs
/// <summary>
/// Sends a request through the HTTP pipeline to the remote service asynchronously.
/// </summary>
/// <param name="serviceRequest">The <see cref="ServiceRequest"/> to send to the service.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> to observe.</param>
/// <returns>A task that returns a <see cref="ServiceResponse"/> when complete.</returns>
/// <exception cref="DatasyncInvalidOperationException">if content was expected but not received.</exception>
Sends a request through the HTTP pipeline to the remote service asynchronously.
Sends a request through the HTTP pipeline to the remote service asynchronously .
internal async Task<ServiceResponse> SendAsync(ServiceRequest serviceRequest, CancellationToken cancellationToken = default)
        {
            Arguments.IsNotNull(serviceRequest, nameof(serviceRequest));
            HttpRequestMessage request = serviceRequest.ToHttpRequestMessage();
            HttpResponseMessage response = await SendAsync(request, cancellationToken).ConfigureAwait(false);
            if (!response.IsSuccessStatusCode)
            {
                throw await ThrowInvalidResponseAsync(request, response, cancellationToken);
            }
            if (serviceRequest.EnsureResponseContent)
            {
                if (!response.HasContent())
                {
                    throw new DatasyncInvalidOperationException("The server did not provide a response with the expected content.", request, response);
                }
                if (response.HasContent() && !response.IsCompressed())
                {
                    long? contentLength = response.Content.Headers.ContentLength;
                    if (contentLength == null || contentLength <= 0)
                    {
                        throw new DatasyncInvalidOperationException("The server did not provide a response with the expected content.", request, response);
                    }
                }
            }
            var serviceResponse = await ServiceResponse.CreateResponseAsync(response, cancellationToken).ConfigureAwait(false);
            request.Dispose();
            response.Dispose();
            return serviceResponse;
        }
internal async Task < ServiceResponse > SendAsync ( ServiceRequest serviceRequest , CancellationToken cancellationToken = default ) { Arguments . IsNotNull ( serviceRequest , nameof ( serviceRequest ) ) ; HttpRequestMessage request = serviceRequest . ToHttpRequestMessage ( ) ; HttpResponseMessage response = await SendAsync ( request , cancellationToken ) . ConfigureAwait ( false ) ; if ( ! response . IsSuccessStatusCode ) { throw await ThrowInvalidResponseAsync ( request , response , cancellationToken ) ; } if ( serviceRequest . EnsureResponseContent ) { if ( ! response . HasContent ( ) ) { throw new DatasyncInvalidOperationException ( " " , request , response ) ; } if ( response . HasContent ( ) && ! response . IsCompressed ( ) ) { long ? contentLength = response . Content . Headers . ContentLength ; if ( contentLength == null || contentLength <= 0 ) { throw new DatasyncInvalidOperationException ( " " , request , response ) ; } } } var serviceResponse = await ServiceResponse . CreateResponseAsync ( response , cancellationToken ) . ConfigureAwait ( false ) ; request . Dispose ( ) ; response . Dispose ( ) ; return serviceResponse ; }
Sends a request through the HTTP pipeline to the remote service asynchronously.
Sends a request through the HTTP pipeline to the remote service asynchronously .
A task that returns a  when complete.
A task that returns a when complete .
if content was expected but not received.
if content was expected but not received .
serviceRequest
ServiceRequest
The  to send to the service.
The to send to the service .
cancellationToken
CancellationToken
A  to observe.
A to observe .