< Summary

Class:Microsoft.Azure.CognitiveServices.Vision.ComputerVision.ComputerVisionClient
Assembly:Microsoft.Azure.CognitiveServices.Vision.ComputerVision
File(s):C:\Git\azure-sdk-for-net\sdk\cognitiveservices\Vision.ComputerVision\src\Generated\ComputerVisionClient.cs
Covered lines:776
Uncovered lines:916
Coverable lines:1692
Total lines:3962
Line coverage:45.8% (776 of 1692)
Covered branches:352
Total branches:866
Branch coverage:40.6% (352 of 866)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
get_BaseUri()-100%100%
get_SerializationSettings()-100%100%
get_DeserializationSettings()-100%100%
get_Endpoint()-100%100%
get_Credentials()-100%100%
.ctor(...)-0%100%
.ctor(...)-100%100%
.ctor(...)-0%100%
.ctor(...)-85.71%75%
.ctor(...)-0%0%
.ctor(...)-0%0%
Initialize()-100%100%
AnalyzeImageWithHttpMessagesAsync()-55.43%52.08%
DescribeImageWithHttpMessagesAsync()-56.18%52.17%
DetectObjectsWithHttpMessagesAsync()-54.55%44.74%
ListModelsWithHttpMessagesAsync()-0%0%
AnalyzeImageByDomainWithHttpMessagesAsync()-56.32%50%
RecognizePrintedTextWithHttpMessagesAsync()-56.47%50%
TagImageWithHttpMessagesAsync()-54.22%45.24%
GenerateThumbnailWithHttpMessagesAsync()-65.48%60.42%
GetAreaOfInterestWithHttpMessagesAsync()-54.55%44.74%
AnalyzeImageInStreamWithHttpMessagesAsync()-52.22%50%
GetAreaOfInterestInStreamWithHttpMessagesAsync()-52%45%
DescribeImageInStreamWithHttpMessagesAsync()-52.87%50%
DetectObjectsInStreamWithHttpMessagesAsync()-52%45%
GenerateThumbnailInStreamWithHttpMessagesAsync()-58.54%52%
AnalyzeImageByDomainInStreamWithHttpMessagesAsync()-51.76%45.65%
RecognizePrintedTextInStreamWithHttpMessagesAsync()-53.01%47.73%
TagImageInStreamWithHttpMessagesAsync()-54.32%50%
ReadWithHttpMessagesAsync()-0%0%
GetReadResultWithHttpMessagesAsync()-0%0%
ReadInStreamWithHttpMessagesAsync()-0%0%

File(s)

C:\Git\azure-sdk-for-net\sdk\cognitiveservices\Vision.ComputerVision\src\Generated\ComputerVisionClient.cs

#LineLine coverage
 1// <auto-generated>
 2// Copyright (c) Microsoft Corporation. All rights reserved.
 3// Licensed under the MIT License. See License.txt in the project root for
 4// license information.
 5//
 6// Code generated by Microsoft (R) AutoRest Code Generator.
 7// Changes may cause incorrect behavior and will be lost if the code is
 8// regenerated.
 9// </auto-generated>
 10
 11namespace Microsoft.Azure.CognitiveServices.Vision.ComputerVision
 12{
 13    using Microsoft.Rest;
 14    using Microsoft.Rest.Serialization;
 15    using Models;
 16    using Newtonsoft.Json;
 17    using System.Collections;
 18    using System.Collections.Generic;
 19    using System.IO;
 20    using System.Net;
 21    using System.Net.Http;
 22    using System.Threading;
 23    using System.Threading.Tasks;
 24
 25    /// <summary>
 26    /// The Computer Vision API provides state-of-the-art algorithms to process
 27    /// images and return information. For example, it can be used to determine
 28    /// if an image contains mature content, or it can be used to find all the
 29    /// faces in an image.  It also has other features like estimating dominant
 30    /// and accent colors, categorizing the content of images, and describing
 31    /// an image with complete English sentences.  Additionally, it can also
 32    /// intelligently generate images thumbnails for displaying large images
 33    /// effectively.
 34    /// </summary>
 35    public partial class ComputerVisionClient : ServiceClient<ComputerVisionClient>, IComputerVisionClient
 36    {
 37        /// <summary>
 38        /// The base URI of the service.
 39        /// </summary>
 8040        internal string BaseUri {get; set;}
 41
 42        /// <summary>
 43        /// Gets or sets json serialization settings.
 44        /// </summary>
 13445        public JsonSerializerSettings SerializationSettings { get; private set; }
 46
 47        /// <summary>
 48        /// Gets or sets json deserialization settings.
 49        /// </summary>
 11850        public JsonSerializerSettings DeserializationSettings { get; private set; }
 51
 52        /// <summary>
 53        /// Supported Cognitive Services endpoints.
 54        /// </summary>
 12855        public string Endpoint { get; set; }
 56
 57        /// <summary>
 58        /// Subscription credentials which uniquely identify client subscription.
 59        /// </summary>
 20260        public ServiceClientCredentials Credentials { get; private set; }
 61
 62        /// <summary>
 63        /// Initializes a new instance of the ComputerVisionClient class.
 64        /// </summary>
 65        /// <param name='httpClient'>
 66        /// HttpClient to be used
 67        /// </param>
 68        /// <param name='disposeHttpClient'>
 69        /// True: will dispose the provided httpClient on calling ComputerVisionClient.Dispose(). False: will not dispos
 070        protected ComputerVisionClient(HttpClient httpClient, bool disposeHttpClient) : base(httpClient, disposeHttpClie
 71        {
 072            Initialize();
 073        }
 74
 75        /// <summary>
 76        /// Initializes a new instance of the ComputerVisionClient class.
 77        /// </summary>
 78        /// <param name='handlers'>
 79        /// Optional. The delegating handlers to add to the http client pipeline.
 80        /// </param>
 4281        protected ComputerVisionClient(params DelegatingHandler[] handlers) : base(handlers)
 82        {
 4283            Initialize();
 4284        }
 85
 86        /// <summary>
 87        /// Initializes a new instance of the ComputerVisionClient class.
 88        /// </summary>
 89        /// <param name='rootHandler'>
 90        /// Optional. The http client handler used to handle http transport.
 91        /// </param>
 92        /// <param name='handlers'>
 93        /// Optional. The delegating handlers to add to the http client pipeline.
 94        /// </param>
 095        protected ComputerVisionClient(HttpClientHandler rootHandler, params DelegatingHandler[] handlers) : base(rootHa
 96        {
 097            Initialize();
 098        }
 99
 100        /// <summary>
 101        /// Initializes a new instance of the ComputerVisionClient class.
 102        /// </summary>
 103        /// <param name='credentials'>
 104        /// Required. Subscription credentials which uniquely identify client subscription.
 105        /// </param>
 106        /// <param name='handlers'>
 107        /// Optional. The delegating handlers to add to the http client pipeline.
 108        /// </param>
 109        /// <exception cref="System.ArgumentNullException">
 110        /// Thrown when a required parameter is null
 111        /// </exception>
 42112        public ComputerVisionClient(ServiceClientCredentials credentials, params DelegatingHandler[] handlers) : this(ha
 113        {
 42114            if (credentials == null)
 115            {
 0116                throw new System.ArgumentNullException("credentials");
 117            }
 42118            Credentials = credentials;
 42119            if (Credentials != null)
 120            {
 42121                Credentials.InitializeServiceClient(this);
 122            }
 42123        }
 124
 125        /// <summary>
 126        /// Initializes a new instance of the ComputerVisionClient class.
 127        /// </summary>
 128        /// <param name='credentials'>
 129        /// Required. Subscription credentials which uniquely identify client subscription.
 130        /// </param>
 131        /// <param name='httpClient'>
 132        /// HttpClient to be used
 133        /// </param>
 134        /// <param name='disposeHttpClient'>
 135        /// True: will dispose the provided httpClient on calling ComputerVisionClient.Dispose(). False: will not dispos
 136        /// <exception cref="System.ArgumentNullException">
 137        /// Thrown when a required parameter is null
 138        /// </exception>
 0139        public ComputerVisionClient(ServiceClientCredentials credentials, HttpClient httpClient, bool disposeHttpClient)
 140        {
 0141            if (credentials == null)
 142            {
 0143                throw new System.ArgumentNullException("credentials");
 144            }
 0145            Credentials = credentials;
 0146            if (Credentials != null)
 147            {
 0148                Credentials.InitializeServiceClient(this);
 149            }
 0150        }
 151
 152        /// <summary>
 153        /// Initializes a new instance of the ComputerVisionClient class.
 154        /// </summary>
 155        /// <param name='credentials'>
 156        /// Required. Subscription credentials which uniquely identify client subscription.
 157        /// </param>
 158        /// <param name='rootHandler'>
 159        /// Optional. The http client handler used to handle http transport.
 160        /// </param>
 161        /// <param name='handlers'>
 162        /// Optional. The delegating handlers to add to the http client pipeline.
 163        /// </param>
 164        /// <exception cref="System.ArgumentNullException">
 165        /// Thrown when a required parameter is null
 166        /// </exception>
 0167        public ComputerVisionClient(ServiceClientCredentials credentials, HttpClientHandler rootHandler, params Delegati
 168        {
 0169            if (credentials == null)
 170            {
 0171                throw new System.ArgumentNullException("credentials");
 172            }
 0173            Credentials = credentials;
 0174            if (Credentials != null)
 175            {
 0176                Credentials.InitializeServiceClient(this);
 177            }
 0178        }
 179
 180        /// <summary>
 181        /// An optional partial-method to perform custom initialization.
 182        ///</summary>
 183        partial void CustomInitialize();
 184        /// <summary>
 185        /// Initializes client properties.
 186        /// </summary>
 187        private void Initialize()
 188        {
 42189            BaseUri = "{Endpoint}/vision/v3.0";
 42190            SerializationSettings = new JsonSerializerSettings
 42191            {
 42192                Formatting = Newtonsoft.Json.Formatting.Indented,
 42193                DateFormatHandling = Newtonsoft.Json.DateFormatHandling.IsoDateFormat,
 42194                DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Utc,
 42195                NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore,
 42196                ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Serialize,
 42197                ContractResolver = new ReadOnlyJsonContractResolver(),
 42198                Converters = new  List<JsonConverter>
 42199                    {
 42200                        new Iso8601TimeSpanConverter()
 42201                    }
 42202            };
 42203            SerializationSettings.Converters.Add(new TransformationJsonConverter());
 42204            DeserializationSettings = new JsonSerializerSettings
 42205            {
 42206                DateFormatHandling = Newtonsoft.Json.DateFormatHandling.IsoDateFormat,
 42207                DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Utc,
 42208                NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore,
 42209                ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Serialize,
 42210                ContractResolver = new ReadOnlyJsonContractResolver(),
 42211                Converters = new List<JsonConverter>
 42212                    {
 42213                        new Iso8601TimeSpanConverter()
 42214                    }
 42215            };
 216            CustomInitialize();
 42217            DeserializationSettings.Converters.Add(new TransformationJsonConverter());
 42218        }
 219        /// <summary>
 220        /// This operation extracts a rich set of visual features based on the image
 221        /// content.
 222        /// Two input methods are supported -- (1) Uploading an image or (2) specifying
 223        /// an image URL. Within your request, there is an optional parameter to allow
 224        /// you to choose which features to return. By default, image categories are
 225        /// returned in the response.
 226        /// A successful response will be returned in JSON. If the request failed, the
 227        /// response will contain an error code and a message to help understand what
 228        /// went wrong.
 229        /// </summary>
 230        /// <param name='url'>
 231        /// Publicly reachable URL of an image.
 232        /// </param>
 233        /// <param name='visualFeatures'>
 234        /// A string indicating what visual feature types to return. Multiple values
 235        /// should be comma-separated. Valid visual feature types include: Categories -
 236        /// categorizes image content according to a taxonomy defined in documentation.
 237        /// Tags - tags the image with a detailed list of words related to the image
 238        /// content. Description - describes the image content with a complete English
 239        /// sentence. Faces - detects if faces are present. If present, generate
 240        /// coordinates, gender and age. ImageType - detects if image is clipart or a
 241        /// line drawing. Color - determines the accent color, dominant color, and
 242        /// whether an image is black&amp;white. Adult - detects if the image is
 243        /// pornographic in nature (depicts nudity or a sex act), or is gory (depicts
 244        /// extreme violence or blood). Sexually suggestive content (aka racy content)
 245        /// is also detected. Objects - detects various objects within an image,
 246        /// including the approximate location. The Objects argument is only available
 247        /// in English. Brands - detects various brands within an image, including the
 248        /// approximate location. The Brands argument is only available in English.
 249        /// </param>
 250        /// <param name='details'>
 251        /// A string indicating which domain-specific details to return. Multiple
 252        /// values should be comma-separated. Valid visual feature types include:
 253        /// Celebrities - identifies celebrities if detected in the image, Landmarks -
 254        /// identifies notable landmarks in the image.
 255        /// </param>
 256        /// <param name='language'>
 257        /// The desired language for output generation. If this parameter is not
 258        /// specified, the default value is &amp;quot;en&amp;quot;.Supported
 259        /// languages:en - English, Default. es - Spanish, ja - Japanese, pt -
 260        /// Portuguese, zh - Simplified Chinese. Possible values include: 'en', 'es',
 261        /// 'ja', 'pt', 'zh'
 262        /// </param>
 263        /// <param name='descriptionExclude'>
 264        /// Turn off specified domain models when generating the description.
 265        /// </param>
 266        /// <param name='customHeaders'>
 267        /// Headers that will be added to request.
 268        /// </param>
 269        /// <param name='cancellationToken'>
 270        /// The cancellation token.
 271        /// </param>
 272        /// <exception cref="ComputerVisionErrorException">
 273        /// Thrown when the operation returned an invalid status code
 274        /// </exception>
 275        /// <exception cref="SerializationException">
 276        /// Thrown when unable to deserialize the response
 277        /// </exception>
 278        /// <exception cref="ValidationException">
 279        /// Thrown when a required parameter is null
 280        /// </exception>
 281        /// <exception cref="System.ArgumentNullException">
 282        /// Thrown when a required parameter is null
 283        /// </exception>
 284        /// <return>
 285        /// A response object containing the response body and response headers.
 286        /// </return>
 287        public async Task<HttpOperationResponse<ImageAnalysis>> AnalyzeImageWithHttpMessagesAsync(string url, IList<Visu
 288        {
 4289            if (Endpoint == null)
 290            {
 0291                throw new ValidationException(ValidationRules.CannotBeNull, "this.Endpoint");
 292            }
 4293            if (url == null)
 294            {
 2295                throw new ValidationException(ValidationRules.CannotBeNull, "url");
 296            }
 2297            ImageUrl imageUrl = new ImageUrl();
 2298            if (url != null)
 299            {
 2300                imageUrl.Url = url;
 301            }
 302            // Tracing
 2303            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 2304            string _invocationId = null;
 2305            if (_shouldTrace)
 306            {
 0307                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0308                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0309                tracingParameters.Add("visualFeatures", visualFeatures);
 0310                tracingParameters.Add("details", details);
 0311                tracingParameters.Add("language", language);
 0312                tracingParameters.Add("descriptionExclude", descriptionExclude);
 0313                tracingParameters.Add("imageUrl", imageUrl);
 0314                tracingParameters.Add("cancellationToken", cancellationToken);
 0315                ServiceClientTracing.Enter(_invocationId, this, "AnalyzeImage", tracingParameters);
 316            }
 317            // Construct URL
 2318            var _baseUrl = BaseUri;
 2319            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "analyze";
 2320            _url = _url.Replace("{Endpoint}", Endpoint);
 2321            List<string> _queryParameters = new List<string>();
 2322            if (visualFeatures != null)
 323            {
 2324                _queryParameters.Add(string.Format("visualFeatures={0}", System.Uri.EscapeDataString(string.Join(",", vi
 325            }
 2326            if (details != null)
 327            {
 0328                _queryParameters.Add(string.Format("details={0}", System.Uri.EscapeDataString(string.Join(",", details))
 329            }
 2330            if (language != null)
 331            {
 0332                _queryParameters.Add(string.Format("language={0}", System.Uri.EscapeDataString(SafeJsonConvert.Serialize
 333            }
 2334            if (descriptionExclude != null)
 335            {
 0336                _queryParameters.Add(string.Format("descriptionExclude={0}", System.Uri.EscapeDataString(string.Join(","
 337            }
 2338            if (_queryParameters.Count > 0)
 339            {
 2340                _url += "?" + string.Join("&", _queryParameters);
 341            }
 342            // Create HTTP transport objects
 2343            var _httpRequest = new HttpRequestMessage();
 2344            HttpResponseMessage _httpResponse = null;
 2345            _httpRequest.Method = new HttpMethod("POST");
 2346            _httpRequest.RequestUri = new System.Uri(_url);
 347            // Set Headers
 348
 349
 2350            if (customHeaders != null)
 351            {
 0352                foreach(var _header in customHeaders)
 353                {
 0354                    if (_httpRequest.Headers.Contains(_header.Key))
 355                    {
 0356                        _httpRequest.Headers.Remove(_header.Key);
 357                    }
 0358                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 359                }
 360            }
 361
 362            // Serialize Request
 2363            string _requestContent = null;
 2364            if(imageUrl != null)
 365            {
 2366                _requestContent = SafeJsonConvert.SerializeObject(imageUrl, SerializationSettings);
 2367                _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
 2368                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 369            }
 370            // Set Credentials
 2371            if (Credentials != null)
 372            {
 2373                cancellationToken.ThrowIfCancellationRequested();
 2374                await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 375            }
 376            // Send Request
 2377            if (_shouldTrace)
 378            {
 0379                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 380            }
 2381            cancellationToken.ThrowIfCancellationRequested();
 2382            _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 2383            if (_shouldTrace)
 384            {
 0385                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 386            }
 2387            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 2388            cancellationToken.ThrowIfCancellationRequested();
 2389            string _responseContent = null;
 2390            if ((int)_statusCode != 200)
 391            {
 0392                var ex = new ComputerVisionErrorException(string.Format("Operation returned an invalid status code '{0}'
 393                try
 394                {
 0395                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0396                    ComputerVisionError _errorBody =  SafeJsonConvert.DeserializeObject<ComputerVisionError>(_responseCo
 0397                    if (_errorBody != null)
 398                    {
 0399                        ex.Body = _errorBody;
 400                    }
 0401                }
 0402                catch (JsonException)
 403                {
 404                    // Ignore the exception
 0405                }
 0406                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0407                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0408                if (_shouldTrace)
 409                {
 0410                    ServiceClientTracing.Error(_invocationId, ex);
 411                }
 0412                _httpRequest.Dispose();
 0413                if (_httpResponse != null)
 414                {
 0415                    _httpResponse.Dispose();
 416                }
 0417                throw ex;
 418            }
 419            // Create Result
 2420            var _result = new HttpOperationResponse<ImageAnalysis>();
 2421            _result.Request = _httpRequest;
 2422            _result.Response = _httpResponse;
 423            // Deserialize Response
 2424            if ((int)_statusCode == 200)
 425            {
 2426                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 427                try
 428                {
 2429                    _result.Body = SafeJsonConvert.DeserializeObject<ImageAnalysis>(_responseContent, DeserializationSet
 2430                }
 0431                catch (JsonException ex)
 432                {
 0433                    _httpRequest.Dispose();
 0434                    if (_httpResponse != null)
 435                    {
 0436                        _httpResponse.Dispose();
 437                    }
 0438                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 439                }
 440            }
 2441            if (_shouldTrace)
 442            {
 0443                ServiceClientTracing.Exit(_invocationId, _result);
 444            }
 2445            return _result;
 2446        }
 447
 448        /// <summary>
 449        /// This operation generates a description of an image in human readable
 450        /// language with complete sentences. The description is based on a collection
 451        /// of content tags, which are also returned by the operation. More than one
 452        /// description can be generated for each image. Descriptions are ordered by
 453        /// their confidence score. Descriptions may include results from celebrity and
 454        /// landmark domain models, if applicable.
 455        /// Two input methods are supported -- (1) Uploading an image or (2) specifying
 456        /// an image URL.
 457        /// A successful response will be returned in JSON. If the request failed, the
 458        /// response will contain an error code and a message to help understand what
 459        /// went wrong.
 460        /// </summary>
 461        /// <param name='url'>
 462        /// Publicly reachable URL of an image.
 463        /// </param>
 464        /// <param name='maxCandidates'>
 465        /// Maximum number of candidate descriptions to be returned.  The default is 1.
 466        /// </param>
 467        /// <param name='language'>
 468        /// The desired language for output generation. If this parameter is not
 469        /// specified, the default value is &amp;quot;en&amp;quot;.Supported
 470        /// languages:en - English, Default. es - Spanish, ja - Japanese, pt -
 471        /// Portuguese, zh - Simplified Chinese. Possible values include: 'en', 'es',
 472        /// 'ja', 'pt', 'zh'
 473        /// </param>
 474        /// <param name='descriptionExclude'>
 475        /// Turn off specified domain models when generating the description.
 476        /// </param>
 477        /// <param name='customHeaders'>
 478        /// Headers that will be added to request.
 479        /// </param>
 480        /// <param name='cancellationToken'>
 481        /// The cancellation token.
 482        /// </param>
 483        /// <exception cref="ComputerVisionErrorException">
 484        /// Thrown when the operation returned an invalid status code
 485        /// </exception>
 486        /// <exception cref="SerializationException">
 487        /// Thrown when unable to deserialize the response
 488        /// </exception>
 489        /// <exception cref="ValidationException">
 490        /// Thrown when a required parameter is null
 491        /// </exception>
 492        /// <exception cref="System.ArgumentNullException">
 493        /// Thrown when a required parameter is null
 494        /// </exception>
 495        /// <return>
 496        /// A response object containing the response body and response headers.
 497        /// </return>
 498        public async Task<HttpOperationResponse<ImageDescription>> DescribeImageWithHttpMessagesAsync(string url, int? m
 499        {
 4500            if (Endpoint == null)
 501            {
 0502                throw new ValidationException(ValidationRules.CannotBeNull, "this.Endpoint");
 503            }
 4504            if (url == null)
 505            {
 0506                throw new ValidationException(ValidationRules.CannotBeNull, "url");
 507            }
 4508            ImageUrl imageUrl = new ImageUrl();
 4509            if (url != null)
 510            {
 4511                imageUrl.Url = url;
 512            }
 513            // Tracing
 4514            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 4515            string _invocationId = null;
 4516            if (_shouldTrace)
 517            {
 0518                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0519                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0520                tracingParameters.Add("maxCandidates", maxCandidates);
 0521                tracingParameters.Add("language", language);
 0522                tracingParameters.Add("descriptionExclude", descriptionExclude);
 0523                tracingParameters.Add("imageUrl", imageUrl);
 0524                tracingParameters.Add("cancellationToken", cancellationToken);
 0525                ServiceClientTracing.Enter(_invocationId, this, "DescribeImage", tracingParameters);
 526            }
 527            // Construct URL
 4528            var _baseUrl = BaseUri;
 4529            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "describe";
 4530            _url = _url.Replace("{Endpoint}", Endpoint);
 4531            List<string> _queryParameters = new List<string>();
 4532            if (maxCandidates != null)
 533            {
 4534                _queryParameters.Add(string.Format("maxCandidates={0}", System.Uri.EscapeDataString(SafeJsonConvert.Seri
 535            }
 4536            if (language != null)
 537            {
 2538                _queryParameters.Add(string.Format("language={0}", System.Uri.EscapeDataString(SafeJsonConvert.Serialize
 539            }
 4540            if (descriptionExclude != null)
 541            {
 0542                _queryParameters.Add(string.Format("descriptionExclude={0}", System.Uri.EscapeDataString(string.Join(","
 543            }
 4544            if (_queryParameters.Count > 0)
 545            {
 4546                _url += "?" + string.Join("&", _queryParameters);
 547            }
 548            // Create HTTP transport objects
 4549            var _httpRequest = new HttpRequestMessage();
 4550            HttpResponseMessage _httpResponse = null;
 4551            _httpRequest.Method = new HttpMethod("POST");
 4552            _httpRequest.RequestUri = new System.Uri(_url);
 553            // Set Headers
 554
 555
 4556            if (customHeaders != null)
 557            {
 0558                foreach(var _header in customHeaders)
 559                {
 0560                    if (_httpRequest.Headers.Contains(_header.Key))
 561                    {
 0562                        _httpRequest.Headers.Remove(_header.Key);
 563                    }
 0564                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 565                }
 566            }
 567
 568            // Serialize Request
 4569            string _requestContent = null;
 4570            if(imageUrl != null)
 571            {
 4572                _requestContent = SafeJsonConvert.SerializeObject(imageUrl, SerializationSettings);
 4573                _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
 4574                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 575            }
 576            // Set Credentials
 4577            if (Credentials != null)
 578            {
 4579                cancellationToken.ThrowIfCancellationRequested();
 4580                await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 581            }
 582            // Send Request
 4583            if (_shouldTrace)
 584            {
 0585                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 586            }
 4587            cancellationToken.ThrowIfCancellationRequested();
 4588            _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 4589            if (_shouldTrace)
 590            {
 0591                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 592            }
 4593            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 4594            cancellationToken.ThrowIfCancellationRequested();
 4595            string _responseContent = null;
 4596            if ((int)_statusCode != 200)
 597            {
 0598                var ex = new ComputerVisionErrorException(string.Format("Operation returned an invalid status code '{0}'
 599                try
 600                {
 0601                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0602                    ComputerVisionError _errorBody =  SafeJsonConvert.DeserializeObject<ComputerVisionError>(_responseCo
 0603                    if (_errorBody != null)
 604                    {
 0605                        ex.Body = _errorBody;
 606                    }
 0607                }
 0608                catch (JsonException)
 609                {
 610                    // Ignore the exception
 0611                }
 0612                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0613                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0614                if (_shouldTrace)
 615                {
 0616                    ServiceClientTracing.Error(_invocationId, ex);
 617                }
 0618                _httpRequest.Dispose();
 0619                if (_httpResponse != null)
 620                {
 0621                    _httpResponse.Dispose();
 622                }
 0623                throw ex;
 624            }
 625            // Create Result
 4626            var _result = new HttpOperationResponse<ImageDescription>();
 4627            _result.Request = _httpRequest;
 4628            _result.Response = _httpResponse;
 629            // Deserialize Response
 4630            if ((int)_statusCode == 200)
 631            {
 4632                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 633                try
 634                {
 4635                    _result.Body = SafeJsonConvert.DeserializeObject<ImageDescription>(_responseContent, Deserialization
 4636                }
 0637                catch (JsonException ex)
 638                {
 0639                    _httpRequest.Dispose();
 0640                    if (_httpResponse != null)
 641                    {
 0642                        _httpResponse.Dispose();
 643                    }
 0644                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 645                }
 646            }
 4647            if (_shouldTrace)
 648            {
 0649                ServiceClientTracing.Exit(_invocationId, _result);
 650            }
 4651            return _result;
 4652        }
 653
 654        /// <summary>
 655        /// Performs object detection on the specified image.
 656        /// Two input methods are supported -- (1) Uploading an image or (2) specifying
 657        /// an image URL.
 658        /// A successful response will be returned in JSON. If the request failed, the
 659        /// response will contain an error code and a message to help understand what
 660        /// went wrong.
 661        /// </summary>
 662        /// <param name='url'>
 663        /// Publicly reachable URL of an image.
 664        /// </param>
 665        /// <param name='customHeaders'>
 666        /// Headers that will be added to request.
 667        /// </param>
 668        /// <param name='cancellationToken'>
 669        /// The cancellation token.
 670        /// </param>
 671        /// <exception cref="ComputerVisionErrorException">
 672        /// Thrown when the operation returned an invalid status code
 673        /// </exception>
 674        /// <exception cref="SerializationException">
 675        /// Thrown when unable to deserialize the response
 676        /// </exception>
 677        /// <exception cref="ValidationException">
 678        /// Thrown when a required parameter is null
 679        /// </exception>
 680        /// <exception cref="System.ArgumentNullException">
 681        /// Thrown when a required parameter is null
 682        /// </exception>
 683        /// <return>
 684        /// A response object containing the response body and response headers.
 685        /// </return>
 686        public async Task<HttpOperationResponse<DetectResult>> DetectObjectsWithHttpMessagesAsync(string url, Dictionary
 687        {
 2688            if (Endpoint == null)
 689            {
 0690                throw new ValidationException(ValidationRules.CannotBeNull, "this.Endpoint");
 691            }
 2692            if (url == null)
 693            {
 0694                throw new ValidationException(ValidationRules.CannotBeNull, "url");
 695            }
 2696            ImageUrl imageUrl = new ImageUrl();
 2697            if (url != null)
 698            {
 2699                imageUrl.Url = url;
 700            }
 701            // Tracing
 2702            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 2703            string _invocationId = null;
 2704            if (_shouldTrace)
 705            {
 0706                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0707                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0708                tracingParameters.Add("imageUrl", imageUrl);
 0709                tracingParameters.Add("cancellationToken", cancellationToken);
 0710                ServiceClientTracing.Enter(_invocationId, this, "DetectObjects", tracingParameters);
 711            }
 712            // Construct URL
 2713            var _baseUrl = BaseUri;
 2714            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "detect";
 2715            _url = _url.Replace("{Endpoint}", Endpoint);
 716            // Create HTTP transport objects
 2717            var _httpRequest = new HttpRequestMessage();
 2718            HttpResponseMessage _httpResponse = null;
 2719            _httpRequest.Method = new HttpMethod("POST");
 2720            _httpRequest.RequestUri = new System.Uri(_url);
 721            // Set Headers
 722
 723
 2724            if (customHeaders != null)
 725            {
 0726                foreach(var _header in customHeaders)
 727                {
 0728                    if (_httpRequest.Headers.Contains(_header.Key))
 729                    {
 0730                        _httpRequest.Headers.Remove(_header.Key);
 731                    }
 0732                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 733                }
 734            }
 735
 736            // Serialize Request
 2737            string _requestContent = null;
 2738            if(imageUrl != null)
 739            {
 2740                _requestContent = SafeJsonConvert.SerializeObject(imageUrl, SerializationSettings);
 2741                _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
 2742                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 743            }
 744            // Set Credentials
 2745            if (Credentials != null)
 746            {
 2747                cancellationToken.ThrowIfCancellationRequested();
 2748                await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 749            }
 750            // Send Request
 2751            if (_shouldTrace)
 752            {
 0753                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 754            }
 2755            cancellationToken.ThrowIfCancellationRequested();
 2756            _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 2757            if (_shouldTrace)
 758            {
 0759                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 760            }
 2761            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 2762            cancellationToken.ThrowIfCancellationRequested();
 2763            string _responseContent = null;
 2764            if ((int)_statusCode != 200)
 765            {
 0766                var ex = new ComputerVisionErrorException(string.Format("Operation returned an invalid status code '{0}'
 767                try
 768                {
 0769                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0770                    ComputerVisionError _errorBody =  SafeJsonConvert.DeserializeObject<ComputerVisionError>(_responseCo
 0771                    if (_errorBody != null)
 772                    {
 0773                        ex.Body = _errorBody;
 774                    }
 0775                }
 0776                catch (JsonException)
 777                {
 778                    // Ignore the exception
 0779                }
 0780                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0781                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0782                if (_shouldTrace)
 783                {
 0784                    ServiceClientTracing.Error(_invocationId, ex);
 785                }
 0786                _httpRequest.Dispose();
 0787                if (_httpResponse != null)
 788                {
 0789                    _httpResponse.Dispose();
 790                }
 0791                throw ex;
 792            }
 793            // Create Result
 2794            var _result = new HttpOperationResponse<DetectResult>();
 2795            _result.Request = _httpRequest;
 2796            _result.Response = _httpResponse;
 797            // Deserialize Response
 2798            if ((int)_statusCode == 200)
 799            {
 2800                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 801                try
 802                {
 2803                    _result.Body = SafeJsonConvert.DeserializeObject<DetectResult>(_responseContent, DeserializationSett
 2804                }
 0805                catch (JsonException ex)
 806                {
 0807                    _httpRequest.Dispose();
 0808                    if (_httpResponse != null)
 809                    {
 0810                        _httpResponse.Dispose();
 811                    }
 0812                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 813                }
 814            }
 2815            if (_shouldTrace)
 816            {
 0817                ServiceClientTracing.Exit(_invocationId, _result);
 818            }
 2819            return _result;
 2820        }
 821
 822        /// <summary>
 823        /// This operation returns the list of domain-specific models that are
 824        /// supported by the Computer Vision API. Currently, the API supports following
 825        /// domain-specific models: celebrity recognizer, landmark recognizer.
 826        /// A successful response will be returned in JSON. If the request failed, the
 827        /// response will contain an error code and a message to help understand what
 828        /// went wrong.
 829        /// </summary>
 830        /// <param name='customHeaders'>
 831        /// Headers that will be added to request.
 832        /// </param>
 833        /// <param name='cancellationToken'>
 834        /// The cancellation token.
 835        /// </param>
 836        /// <exception cref="ComputerVisionErrorException">
 837        /// Thrown when the operation returned an invalid status code
 838        /// </exception>
 839        /// <exception cref="SerializationException">
 840        /// Thrown when unable to deserialize the response
 841        /// </exception>
 842        /// <exception cref="ValidationException">
 843        /// Thrown when a required parameter is null
 844        /// </exception>
 845        /// <exception cref="System.ArgumentNullException">
 846        /// Thrown when a required parameter is null
 847        /// </exception>
 848        /// <return>
 849        /// A response object containing the response body and response headers.
 850        /// </return>
 851        public async Task<HttpOperationResponse<ListModelsResult>> ListModelsWithHttpMessagesAsync(Dictionary<string, Li
 852        {
 0853            if (Endpoint == null)
 854            {
 0855                throw new ValidationException(ValidationRules.CannotBeNull, "this.Endpoint");
 856            }
 857            // Tracing
 0858            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 0859            string _invocationId = null;
 0860            if (_shouldTrace)
 861            {
 0862                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0863                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0864                tracingParameters.Add("cancellationToken", cancellationToken);
 0865                ServiceClientTracing.Enter(_invocationId, this, "ListModels", tracingParameters);
 866            }
 867            // Construct URL
 0868            var _baseUrl = BaseUri;
 0869            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "models";
 0870            _url = _url.Replace("{Endpoint}", Endpoint);
 871            // Create HTTP transport objects
 0872            var _httpRequest = new HttpRequestMessage();
 0873            HttpResponseMessage _httpResponse = null;
 0874            _httpRequest.Method = new HttpMethod("GET");
 0875            _httpRequest.RequestUri = new System.Uri(_url);
 876            // Set Headers
 877
 878
 0879            if (customHeaders != null)
 880            {
 0881                foreach(var _header in customHeaders)
 882                {
 0883                    if (_httpRequest.Headers.Contains(_header.Key))
 884                    {
 0885                        _httpRequest.Headers.Remove(_header.Key);
 886                    }
 0887                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 888                }
 889            }
 890
 891            // Serialize Request
 0892            string _requestContent = null;
 893            // Set Credentials
 0894            if (Credentials != null)
 895            {
 0896                cancellationToken.ThrowIfCancellationRequested();
 0897                await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 898            }
 899            // Send Request
 0900            if (_shouldTrace)
 901            {
 0902                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 903            }
 0904            cancellationToken.ThrowIfCancellationRequested();
 0905            _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 0906            if (_shouldTrace)
 907            {
 0908                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 909            }
 0910            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 0911            cancellationToken.ThrowIfCancellationRequested();
 0912            string _responseContent = null;
 0913            if ((int)_statusCode != 200)
 914            {
 0915                var ex = new ComputerVisionErrorException(string.Format("Operation returned an invalid status code '{0}'
 916                try
 917                {
 0918                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0919                    ComputerVisionError _errorBody =  SafeJsonConvert.DeserializeObject<ComputerVisionError>(_responseCo
 0920                    if (_errorBody != null)
 921                    {
 0922                        ex.Body = _errorBody;
 923                    }
 0924                }
 0925                catch (JsonException)
 926                {
 927                    // Ignore the exception
 0928                }
 0929                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0930                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0931                if (_shouldTrace)
 932                {
 0933                    ServiceClientTracing.Error(_invocationId, ex);
 934                }
 0935                _httpRequest.Dispose();
 0936                if (_httpResponse != null)
 937                {
 0938                    _httpResponse.Dispose();
 939                }
 0940                throw ex;
 941            }
 942            // Create Result
 0943            var _result = new HttpOperationResponse<ListModelsResult>();
 0944            _result.Request = _httpRequest;
 0945            _result.Response = _httpResponse;
 946            // Deserialize Response
 0947            if ((int)_statusCode == 200)
 948            {
 0949                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 950                try
 951                {
 0952                    _result.Body = SafeJsonConvert.DeserializeObject<ListModelsResult>(_responseContent, Deserialization
 0953                }
 0954                catch (JsonException ex)
 955                {
 0956                    _httpRequest.Dispose();
 0957                    if (_httpResponse != null)
 958                    {
 0959                        _httpResponse.Dispose();
 960                    }
 0961                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 962                }
 963            }
 0964            if (_shouldTrace)
 965            {
 0966                ServiceClientTracing.Exit(_invocationId, _result);
 967            }
 0968            return _result;
 0969        }
 970
 971        /// <summary>
 972        /// This operation recognizes content within an image by applying a
 973        /// domain-specific model. The list of domain-specific models that are
 974        /// supported by the Computer Vision API can be retrieved using the /models GET
 975        /// request. Currently, the API provides following domain-specific models:
 976        /// celebrities, landmarks.
 977        /// Two input methods are supported -- (1) Uploading an image or (2) specifying
 978        /// an image URL.
 979        /// A successful response will be returned in JSON.
 980        /// If the request failed, the response will contain an error code and a
 981        /// message to help understand what went wrong.
 982        /// </summary>
 983        /// <param name='model'>
 984        /// The domain-specific content to recognize.
 985        /// </param>
 986        /// <param name='url'>
 987        /// Publicly reachable URL of an image.
 988        /// </param>
 989        /// <param name='language'>
 990        /// The desired language for output generation. If this parameter is not
 991        /// specified, the default value is &amp;quot;en&amp;quot;.Supported
 992        /// languages:en - English, Default. es - Spanish, ja - Japanese, pt -
 993        /// Portuguese, zh - Simplified Chinese. Possible values include: 'en', 'es',
 994        /// 'ja', 'pt', 'zh'
 995        /// </param>
 996        /// <param name='customHeaders'>
 997        /// Headers that will be added to request.
 998        /// </param>
 999        /// <param name='cancellationToken'>
 1000        /// The cancellation token.
 1001        /// </param>
 1002        /// <exception cref="ComputerVisionErrorException">
 1003        /// Thrown when the operation returned an invalid status code
 1004        /// </exception>
 1005        /// <exception cref="SerializationException">
 1006        /// Thrown when unable to deserialize the response
 1007        /// </exception>
 1008        /// <exception cref="ValidationException">
 1009        /// Thrown when a required parameter is null
 1010        /// </exception>
 1011        /// <exception cref="System.ArgumentNullException">
 1012        /// Thrown when a required parameter is null
 1013        /// </exception>
 1014        /// <return>
 1015        /// A response object containing the response body and response headers.
 1016        /// </return>
 1017        public async Task<HttpOperationResponse<DomainModelResults>> AnalyzeImageByDomainWithHttpMessagesAsync(string mo
 1018        {
 41019            if (Endpoint == null)
 1020            {
 01021                throw new ValidationException(ValidationRules.CannotBeNull, "this.Endpoint");
 1022            }
 41023            if (model == null)
 1024            {
 01025                throw new ValidationException(ValidationRules.CannotBeNull, "model");
 1026            }
 41027            if (url == null)
 1028            {
 01029                throw new ValidationException(ValidationRules.CannotBeNull, "url");
 1030            }
 41031            ImageUrl imageUrl = new ImageUrl();
 41032            if (url != null)
 1033            {
 41034                imageUrl.Url = url;
 1035            }
 1036            // Tracing
 41037            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 41038            string _invocationId = null;
 41039            if (_shouldTrace)
 1040            {
 01041                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 01042                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 01043                tracingParameters.Add("model", model);
 01044                tracingParameters.Add("language", language);
 01045                tracingParameters.Add("imageUrl", imageUrl);
 01046                tracingParameters.Add("cancellationToken", cancellationToken);
 01047                ServiceClientTracing.Enter(_invocationId, this, "AnalyzeImageByDomain", tracingParameters);
 1048            }
 1049            // Construct URL
 41050            var _baseUrl = BaseUri;
 41051            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "models/{model}/analyze";
 41052            _url = _url.Replace("{Endpoint}", Endpoint);
 41053            _url = _url.Replace("{model}", System.Uri.EscapeDataString(model));
 41054            List<string> _queryParameters = new List<string>();
 41055            if (language != null)
 1056            {
 21057                _queryParameters.Add(string.Format("language={0}", System.Uri.EscapeDataString(SafeJsonConvert.Serialize
 1058            }
 41059            if (_queryParameters.Count > 0)
 1060            {
 21061                _url += "?" + string.Join("&", _queryParameters);
 1062            }
 1063            // Create HTTP transport objects
 41064            var _httpRequest = new HttpRequestMessage();
 41065            HttpResponseMessage _httpResponse = null;
 41066            _httpRequest.Method = new HttpMethod("POST");
 41067            _httpRequest.RequestUri = new System.Uri(_url);
 1068            // Set Headers
 1069
 1070
 41071            if (customHeaders != null)
 1072            {
 01073                foreach(var _header in customHeaders)
 1074                {
 01075                    if (_httpRequest.Headers.Contains(_header.Key))
 1076                    {
 01077                        _httpRequest.Headers.Remove(_header.Key);
 1078                    }
 01079                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 1080                }
 1081            }
 1082
 1083            // Serialize Request
 41084            string _requestContent = null;
 41085            if(imageUrl != null)
 1086            {
 41087                _requestContent = SafeJsonConvert.SerializeObject(imageUrl, SerializationSettings);
 41088                _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
 41089                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 1090            }
 1091            // Set Credentials
 41092            if (Credentials != null)
 1093            {
 41094                cancellationToken.ThrowIfCancellationRequested();
 41095                await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 1096            }
 1097            // Send Request
 41098            if (_shouldTrace)
 1099            {
 01100                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 1101            }
 41102            cancellationToken.ThrowIfCancellationRequested();
 41103            _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 41104            if (_shouldTrace)
 1105            {
 01106                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 1107            }
 41108            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 41109            cancellationToken.ThrowIfCancellationRequested();
 41110            string _responseContent = null;
 41111            if ((int)_statusCode != 200)
 1112            {
 01113                var ex = new ComputerVisionErrorException(string.Format("Operation returned an invalid status code '{0}'
 1114                try
 1115                {
 01116                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 01117                    ComputerVisionError _errorBody =  SafeJsonConvert.DeserializeObject<ComputerVisionError>(_responseCo
 01118                    if (_errorBody != null)
 1119                    {
 01120                        ex.Body = _errorBody;
 1121                    }
 01122                }
 01123                catch (JsonException)
 1124                {
 1125                    // Ignore the exception
 01126                }
 01127                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 01128                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 01129                if (_shouldTrace)
 1130                {
 01131                    ServiceClientTracing.Error(_invocationId, ex);
 1132                }
 01133                _httpRequest.Dispose();
 01134                if (_httpResponse != null)
 1135                {
 01136                    _httpResponse.Dispose();
 1137                }
 01138                throw ex;
 1139            }
 1140            // Create Result
 41141            var _result = new HttpOperationResponse<DomainModelResults>();
 41142            _result.Request = _httpRequest;
 41143            _result.Response = _httpResponse;
 1144            // Deserialize Response
 41145            if ((int)_statusCode == 200)
 1146            {
 41147                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 1148                try
 1149                {
 41150                    _result.Body = SafeJsonConvert.DeserializeObject<DomainModelResults>(_responseContent, Deserializati
 41151                }
 01152                catch (JsonException ex)
 1153                {
 01154                    _httpRequest.Dispose();
 01155                    if (_httpResponse != null)
 1156                    {
 01157                        _httpResponse.Dispose();
 1158                    }
 01159                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 1160                }
 1161            }
 41162            if (_shouldTrace)
 1163            {
 01164                ServiceClientTracing.Exit(_invocationId, _result);
 1165            }
 41166            return _result;
 41167        }
 1168
 1169        /// <summary>
 1170        /// Optical Character Recognition (OCR) detects text in an image and extracts
 1171        /// the recognized characters into a machine-usable character stream.
 1172        /// Upon success, the OCR results will be returned.
 1173        /// Upon failure, the error code together with an error message will be
 1174        /// returned. The error code can be one of InvalidImageUrl, InvalidImageFormat,
 1175        /// InvalidImageSize, NotSupportedImage, NotSupportedLanguage, or
 1176        /// InternalServerError.
 1177        /// </summary>
 1178        /// <param name='detectOrientation'>
 1179        /// Whether detect the text orientation in the image. With
 1180        /// detectOrientation=true the OCR service tries to detect the image
 1181        /// orientation and correct it before further processing (e.g. if it's
 1182        /// upside-down).
 1183        /// </param>
 1184        /// <param name='url'>
 1185        /// Publicly reachable URL of an image.
 1186        /// </param>
 1187        /// <param name='language'>
 1188        /// The BCP-47 language code of the text to be detected in the image. The
 1189        /// default value is 'unk'. Possible values include: 'unk', 'zh-Hans',
 1190        /// 'zh-Hant', 'cs', 'da', 'nl', 'en', 'fi', 'fr', 'de', 'el', 'hu', 'it',
 1191        /// 'ja', 'ko', 'nb', 'pl', 'pt', 'ru', 'es', 'sv', 'tr', 'ar', 'ro',
 1192        /// 'sr-Cyrl', 'sr-Latn', 'sk'
 1193        /// </param>
 1194        /// <param name='customHeaders'>
 1195        /// Headers that will be added to request.
 1196        /// </param>
 1197        /// <param name='cancellationToken'>
 1198        /// The cancellation token.
 1199        /// </param>
 1200        /// <exception cref="ComputerVisionErrorException">
 1201        /// Thrown when the operation returned an invalid status code
 1202        /// </exception>
 1203        /// <exception cref="SerializationException">
 1204        /// Thrown when unable to deserialize the response
 1205        /// </exception>
 1206        /// <exception cref="ValidationException">
 1207        /// Thrown when a required parameter is null
 1208        /// </exception>
 1209        /// <exception cref="System.ArgumentNullException">
 1210        /// Thrown when a required parameter is null
 1211        /// </exception>
 1212        /// <return>
 1213        /// A response object containing the response body and response headers.
 1214        /// </return>
 1215        public async Task<HttpOperationResponse<OcrResult>> RecognizePrintedTextWithHttpMessagesAsync(bool detectOrienta
 1216        {
 21217            if (Endpoint == null)
 1218            {
 01219                throw new ValidationException(ValidationRules.CannotBeNull, "this.Endpoint");
 1220            }
 21221            if (url == null)
 1222            {
 01223                throw new ValidationException(ValidationRules.CannotBeNull, "url");
 1224            }
 21225            ImageUrl imageUrl = new ImageUrl();
 21226            if (url != null)
 1227            {
 21228                imageUrl.Url = url;
 1229            }
 1230            // Tracing
 21231            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 21232            string _invocationId = null;
 21233            if (_shouldTrace)
 1234            {
 01235                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 01236                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 01237                tracingParameters.Add("detectOrientation", detectOrientation);
 01238                tracingParameters.Add("language", language);
 01239                tracingParameters.Add("imageUrl", imageUrl);
 01240                tracingParameters.Add("cancellationToken", cancellationToken);
 01241                ServiceClientTracing.Enter(_invocationId, this, "RecognizePrintedText", tracingParameters);
 1242            }
 1243            // Construct URL
 21244            var _baseUrl = BaseUri;
 21245            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "ocr";
 21246            _url = _url.Replace("{Endpoint}", Endpoint);
 21247            List<string> _queryParameters = new List<string>();
 21248            _queryParameters.Add(string.Format("detectOrientation={0}", System.Uri.EscapeDataString(SafeJsonConvert.Seri
 21249            if (language != null)
 1250            {
 21251                _queryParameters.Add(string.Format("language={0}", System.Uri.EscapeDataString(SafeJsonConvert.Serialize
 1252            }
 21253            if (_queryParameters.Count > 0)
 1254            {
 21255                _url += "?" + string.Join("&", _queryParameters);
 1256            }
 1257            // Create HTTP transport objects
 21258            var _httpRequest = new HttpRequestMessage();
 21259            HttpResponseMessage _httpResponse = null;
 21260            _httpRequest.Method = new HttpMethod("POST");
 21261            _httpRequest.RequestUri = new System.Uri(_url);
 1262            // Set Headers
 1263
 1264
 21265            if (customHeaders != null)
 1266            {
 01267                foreach(var _header in customHeaders)
 1268                {
 01269                    if (_httpRequest.Headers.Contains(_header.Key))
 1270                    {
 01271                        _httpRequest.Headers.Remove(_header.Key);
 1272                    }
 01273                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 1274                }
 1275            }
 1276
 1277            // Serialize Request
 21278            string _requestContent = null;
 21279            if(imageUrl != null)
 1280            {
 21281                _requestContent = SafeJsonConvert.SerializeObject(imageUrl, SerializationSettings);
 21282                _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
 21283                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 1284            }
 1285            // Set Credentials
 21286            if (Credentials != null)
 1287            {
 21288                cancellationToken.ThrowIfCancellationRequested();
 21289                await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 1290            }
 1291            // Send Request
 21292            if (_shouldTrace)
 1293            {
 01294                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 1295            }
 21296            cancellationToken.ThrowIfCancellationRequested();
 21297            _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 21298            if (_shouldTrace)
 1299            {
 01300                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 1301            }
 21302            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 21303            cancellationToken.ThrowIfCancellationRequested();
 21304            string _responseContent = null;
 21305            if ((int)_statusCode != 200)
 1306            {
 01307                var ex = new ComputerVisionErrorException(string.Format("Operation returned an invalid status code '{0}'
 1308                try
 1309                {
 01310                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 01311                    ComputerVisionError _errorBody =  SafeJsonConvert.DeserializeObject<ComputerVisionError>(_responseCo
 01312                    if (_errorBody != null)
 1313                    {
 01314                        ex.Body = _errorBody;
 1315                    }
 01316                }
 01317                catch (JsonException)
 1318                {
 1319                    // Ignore the exception
 01320                }
 01321                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 01322                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 01323                if (_shouldTrace)
 1324                {
 01325                    ServiceClientTracing.Error(_invocationId, ex);
 1326                }
 01327                _httpRequest.Dispose();
 01328                if (_httpResponse != null)
 1329                {
 01330                    _httpResponse.Dispose();
 1331                }
 01332                throw ex;
 1333            }
 1334            // Create Result
 21335            var _result = new HttpOperationResponse<OcrResult>();
 21336            _result.Request = _httpRequest;
 21337            _result.Response = _httpResponse;
 1338            // Deserialize Response
 21339            if ((int)_statusCode == 200)
 1340            {
 21341                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 1342                try
 1343                {
 21344                    _result.Body = SafeJsonConvert.DeserializeObject<OcrResult>(_responseContent, DeserializationSetting
 21345                }
 01346                catch (JsonException ex)
 1347                {
 01348                    _httpRequest.Dispose();
 01349                    if (_httpResponse != null)
 1350                    {
 01351                        _httpResponse.Dispose();
 1352                    }
 01353                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 1354                }
 1355            }
 21356            if (_shouldTrace)
 1357            {
 01358                ServiceClientTracing.Exit(_invocationId, _result);
 1359            }
 21360            return _result;
 21361        }
 1362
 1363        /// <summary>
 1364        /// This operation generates a list of words, or tags, that are relevant to the
 1365        /// content of the supplied image. The Computer Vision API can return tags
 1366        /// based on objects, living beings, scenery or actions found in images. Unlike
 1367        /// categories, tags are not organized according to a hierarchical
 1368        /// classification system, but correspond to image content. Tags may contain
 1369        /// hints to avoid ambiguity or provide context, for example the tag
 1370        /// "ascomycete" may be accompanied by the hint "fungus".
 1371        /// Two input methods are supported -- (1) Uploading an image or (2) specifying
 1372        /// an image URL.
 1373        /// A successful response will be returned in JSON. If the request failed, the
 1374        /// response will contain an error code and a message to help understand what
 1375        /// went wrong.
 1376        /// </summary>
 1377        /// <param name='url'>
 1378        /// Publicly reachable URL of an image.
 1379        /// </param>
 1380        /// <param name='language'>
 1381        /// The desired language for output generation. If this parameter is not
 1382        /// specified, the default value is &amp;quot;en&amp;quot;.Supported
 1383        /// languages:en - English, Default. es - Spanish, ja - Japanese, pt -
 1384        /// Portuguese, zh - Simplified Chinese. Possible values include: 'en', 'es',
 1385        /// 'ja', 'pt', 'zh'
 1386        /// </param>
 1387        /// <param name='customHeaders'>
 1388        /// Headers that will be added to request.
 1389        /// </param>
 1390        /// <param name='cancellationToken'>
 1391        /// The cancellation token.
 1392        /// </param>
 1393        /// <exception cref="ComputerVisionErrorException">
 1394        /// Thrown when the operation returned an invalid status code
 1395        /// </exception>
 1396        /// <exception cref="SerializationException">
 1397        /// Thrown when unable to deserialize the response
 1398        /// </exception>
 1399        /// <exception cref="ValidationException">
 1400        /// Thrown when a required parameter is null
 1401        /// </exception>
 1402        /// <exception cref="System.ArgumentNullException">
 1403        /// Thrown when a required parameter is null
 1404        /// </exception>
 1405        /// <return>
 1406        /// A response object containing the response body and response headers.
 1407        /// </return>
 1408        public async Task<HttpOperationResponse<TagResult>> TagImageWithHttpMessagesAsync(string url, string language = 
 1409        {
 21410            if (Endpoint == null)
 1411            {
 01412                throw new ValidationException(ValidationRules.CannotBeNull, "this.Endpoint");
 1413            }
 21414            if (url == null)
 1415            {
 01416                throw new ValidationException(ValidationRules.CannotBeNull, "url");
 1417            }
 21418            ImageUrl imageUrl = new ImageUrl();
 21419            if (url != null)
 1420            {
 21421                imageUrl.Url = url;
 1422            }
 1423            // Tracing
 21424            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 21425            string _invocationId = null;
 21426            if (_shouldTrace)
 1427            {
 01428                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 01429                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 01430                tracingParameters.Add("language", language);
 01431                tracingParameters.Add("imageUrl", imageUrl);
 01432                tracingParameters.Add("cancellationToken", cancellationToken);
 01433                ServiceClientTracing.Enter(_invocationId, this, "TagImage", tracingParameters);
 1434            }
 1435            // Construct URL
 21436            var _baseUrl = BaseUri;
 21437            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "tag";
 21438            _url = _url.Replace("{Endpoint}", Endpoint);
 21439            List<string> _queryParameters = new List<string>();
 21440            if (language != null)
 1441            {
 01442                _queryParameters.Add(string.Format("language={0}", System.Uri.EscapeDataString(SafeJsonConvert.Serialize
 1443            }
 21444            if (_queryParameters.Count > 0)
 1445            {
 01446                _url += "?" + string.Join("&", _queryParameters);
 1447            }
 1448            // Create HTTP transport objects
 21449            var _httpRequest = new HttpRequestMessage();
 21450            HttpResponseMessage _httpResponse = null;
 21451            _httpRequest.Method = new HttpMethod("POST");
 21452            _httpRequest.RequestUri = new System.Uri(_url);
 1453            // Set Headers
 1454
 1455
 21456            if (customHeaders != null)
 1457            {
 01458                foreach(var _header in customHeaders)
 1459                {
 01460                    if (_httpRequest.Headers.Contains(_header.Key))
 1461                    {
 01462                        _httpRequest.Headers.Remove(_header.Key);
 1463                    }
 01464                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 1465                }
 1466            }
 1467
 1468            // Serialize Request
 21469            string _requestContent = null;
 21470            if(imageUrl != null)
 1471            {
 21472                _requestContent = SafeJsonConvert.SerializeObject(imageUrl, SerializationSettings);
 21473                _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
 21474                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 1475            }
 1476            // Set Credentials
 21477            if (Credentials != null)
 1478            {
 21479                cancellationToken.ThrowIfCancellationRequested();
 21480                await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 1481            }
 1482            // Send Request
 21483            if (_shouldTrace)
 1484            {
 01485                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 1486            }
 21487            cancellationToken.ThrowIfCancellationRequested();
 21488            _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 21489            if (_shouldTrace)
 1490            {
 01491                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 1492            }
 21493            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 21494            cancellationToken.ThrowIfCancellationRequested();
 21495            string _responseContent = null;
 21496            if ((int)_statusCode != 200)
 1497            {
 01498                var ex = new ComputerVisionErrorException(string.Format("Operation returned an invalid status code '{0}'
 1499                try
 1500                {
 01501                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 01502                    ComputerVisionError _errorBody =  SafeJsonConvert.DeserializeObject<ComputerVisionError>(_responseCo
 01503                    if (_errorBody != null)
 1504                    {
 01505                        ex.Body = _errorBody;
 1506                    }
 01507                }
 01508                catch (JsonException)
 1509                {
 1510                    // Ignore the exception
 01511                }
 01512                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 01513                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 01514                if (_shouldTrace)
 1515                {
 01516                    ServiceClientTracing.Error(_invocationId, ex);
 1517                }
 01518                _httpRequest.Dispose();
 01519                if (_httpResponse != null)
 1520                {
 01521                    _httpResponse.Dispose();
 1522                }
 01523                throw ex;
 1524            }
 1525            // Create Result
 21526            var _result = new HttpOperationResponse<TagResult>();
 21527            _result.Request = _httpRequest;
 21528            _result.Response = _httpResponse;
 1529            // Deserialize Response
 21530            if ((int)_statusCode == 200)
 1531            {
 21532                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 1533                try
 1534                {
 21535                    _result.Body = SafeJsonConvert.DeserializeObject<TagResult>(_responseContent, DeserializationSetting
 21536                }
 01537                catch (JsonException ex)
 1538                {
 01539                    _httpRequest.Dispose();
 01540                    if (_httpResponse != null)
 1541                    {
 01542                        _httpResponse.Dispose();
 1543                    }
 01544                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 1545                }
 1546            }
 21547            if (_shouldTrace)
 1548            {
 01549                ServiceClientTracing.Exit(_invocationId, _result);
 1550            }
 21551            return _result;
 21552        }
 1553
 1554        /// <summary>
 1555        /// This operation generates a thumbnail image with the user-specified width
 1556        /// and height. By default, the service analyzes the image, identifies the
 1557        /// region of interest (ROI), and generates smart cropping coordinates based on
 1558        /// the ROI. Smart cropping helps when you specify an aspect ratio that differs
 1559        /// from that of the input image.
 1560        /// A successful response contains the thumbnail image binary. If the request
 1561        /// failed, the response contains an error code and a message to help determine
 1562        /// what went wrong.
 1563        /// Upon failure, the error code and an error message are returned. The error
 1564        /// code could be one of InvalidImageUrl, InvalidImageFormat, InvalidImageSize,
 1565        /// InvalidThumbnailSize, NotSupportedImage, FailedToProcess, Timeout, or
 1566        /// InternalServerError.
 1567        /// </summary>
 1568        /// <param name='width'>
 1569        /// Width of the thumbnail, in pixels. It must be between 1 and 1024.
 1570        /// Recommended minimum of 50.
 1571        /// </param>
 1572        /// <param name='height'>
 1573        /// Height of the thumbnail, in pixels. It must be between 1 and 1024.
 1574        /// Recommended minimum of 50.
 1575        /// </param>
 1576        /// <param name='url'>
 1577        /// Publicly reachable URL of an image.
 1578        /// </param>
 1579        /// <param name='smartCropping'>
 1580        /// Boolean flag for enabling smart cropping.
 1581        /// </param>
 1582        /// <param name='customHeaders'>
 1583        /// Headers that will be added to request.
 1584        /// </param>
 1585        /// <param name='cancellationToken'>
 1586        /// The cancellation token.
 1587        /// </param>
 1588        /// <exception cref="HttpOperationException">
 1589        /// Thrown when the operation returned an invalid status code
 1590        /// </exception>
 1591        /// <exception cref="SerializationException">
 1592        /// Thrown when unable to deserialize the response
 1593        /// </exception>
 1594        /// <exception cref="ValidationException">
 1595        /// Thrown when a required parameter is null
 1596        /// </exception>
 1597        /// <exception cref="System.ArgumentNullException">
 1598        /// Thrown when a required parameter is null
 1599        /// </exception>
 1600        /// <return>
 1601        /// A response object containing the response body and response headers.
 1602        /// </return>
 1603        public async Task<HttpOperationResponse<Stream>> GenerateThumbnailWithHttpMessagesAsync(int width, int height, s
 1604        {
 101605            if (Endpoint == null)
 1606            {
 01607                throw new ValidationException(ValidationRules.CannotBeNull, "this.Endpoint");
 1608            }
 101609            if (width > 1024)
 1610            {
 21611                throw new ValidationException(ValidationRules.InclusiveMaximum, "width", 1024);
 1612            }
 81613            if (width < 1)
 1614            {
 21615                throw new ValidationException(ValidationRules.InclusiveMinimum, "width", 1);
 1616            }
 61617            if (height > 1024)
 1618            {
 21619                throw new ValidationException(ValidationRules.InclusiveMaximum, "height", 1024);
 1620            }
 41621            if (height < 1)
 1622            {
 21623                throw new ValidationException(ValidationRules.InclusiveMinimum, "height", 1);
 1624            }
 21625            if (url == null)
 1626            {
 01627                throw new ValidationException(ValidationRules.CannotBeNull, "url");
 1628            }
 21629            ImageUrl imageUrl = new ImageUrl();
 21630            if (url != null)
 1631            {
 21632                imageUrl.Url = url;
 1633            }
 1634            // Tracing
 21635            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 21636            string _invocationId = null;
 21637            if (_shouldTrace)
 1638            {
 01639                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 01640                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 01641                tracingParameters.Add("width", width);
 01642                tracingParameters.Add("height", height);
 01643                tracingParameters.Add("smartCropping", smartCropping);
 01644                tracingParameters.Add("imageUrl", imageUrl);
 01645                tracingParameters.Add("cancellationToken", cancellationToken);
 01646                ServiceClientTracing.Enter(_invocationId, this, "GenerateThumbnail", tracingParameters);
 1647            }
 1648            // Construct URL
 21649            var _baseUrl = BaseUri;
 21650            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "generateThumbnail";
 21651            _url = _url.Replace("{Endpoint}", Endpoint);
 21652            List<string> _queryParameters = new List<string>();
 21653            _queryParameters.Add(string.Format("width={0}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeObject(
 21654            _queryParameters.Add(string.Format("height={0}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeObject
 21655            if (smartCropping != null)
 1656            {
 21657                _queryParameters.Add(string.Format("smartCropping={0}", System.Uri.EscapeDataString(SafeJsonConvert.Seri
 1658            }
 21659            if (_queryParameters.Count > 0)
 1660            {
 21661                _url += "?" + string.Join("&", _queryParameters);
 1662            }
 1663            // Create HTTP transport objects
 21664            var _httpRequest = new HttpRequestMessage();
 21665            HttpResponseMessage _httpResponse = null;
 21666            _httpRequest.Method = new HttpMethod("POST");
 21667            _httpRequest.RequestUri = new System.Uri(_url);
 1668            // Set Headers
 1669
 1670
 21671            if (customHeaders != null)
 1672            {
 01673                foreach(var _header in customHeaders)
 1674                {
 01675                    if (_httpRequest.Headers.Contains(_header.Key))
 1676                    {
 01677                        _httpRequest.Headers.Remove(_header.Key);
 1678                    }
 01679                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 1680                }
 1681            }
 1682
 1683            // Serialize Request
 21684            string _requestContent = null;
 21685            if(imageUrl != null)
 1686            {
 21687                _requestContent = SafeJsonConvert.SerializeObject(imageUrl, SerializationSettings);
 21688                _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
 21689                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 1690            }
 1691            // Set Credentials
 21692            if (Credentials != null)
 1693            {
 21694                cancellationToken.ThrowIfCancellationRequested();
 21695                await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 1696            }
 1697            // Send Request
 21698            if (_shouldTrace)
 1699            {
 01700                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 1701            }
 21702            cancellationToken.ThrowIfCancellationRequested();
 21703            _httpResponse = await HttpClient.SendAsync(_httpRequest, System.Net.Http.HttpCompletionOption.ResponseHeader
 21704            if (_shouldTrace)
 1705            {
 01706                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 1707            }
 21708            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 21709            cancellationToken.ThrowIfCancellationRequested();
 21710            string _responseContent = null;
 21711            if ((int)_statusCode != 200)
 1712            {
 01713                var ex = new HttpOperationException(string.Format("Operation returned an invalid status code '{0}'", _st
 01714                if (_httpResponse.Content != null) {
 01715                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 1716                }
 1717                else {
 01718                    _responseContent = string.Empty;
 1719                }
 01720                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 01721                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 01722                if (_shouldTrace)
 1723                {
 01724                    ServiceClientTracing.Error(_invocationId, ex);
 1725                }
 01726                _httpRequest.Dispose();
 01727                if (_httpResponse != null)
 1728                {
 01729                    _httpResponse.Dispose();
 1730                }
 01731                throw ex;
 1732            }
 1733            // Create Result
 21734            var _result = new HttpOperationResponse<Stream>();
 21735            _result.Request = _httpRequest;
 21736            _result.Response = _httpResponse;
 1737            // Deserialize Response
 21738            if ((int)_statusCode == 200)
 1739            {
 21740                _result.Body = await _httpResponse.Content.ReadAsStreamAsync().ConfigureAwait(false);
 1741            }
 21742            if (_shouldTrace)
 1743            {
 01744                ServiceClientTracing.Exit(_invocationId, _result);
 1745            }
 21746            return _result;
 21747        }
 1748
 1749        /// <summary>
 1750        /// This operation returns a bounding box around the most important area of the
 1751        /// image.
 1752        /// A successful response will be returned in JSON. If the request failed, the
 1753        /// response contains an error code and a message to help determine what went
 1754        /// wrong.
 1755        /// Upon failure, the error code and an error message are returned. The error
 1756        /// code could be one of InvalidImageUrl, InvalidImageFormat, InvalidImageSize,
 1757        /// NotSupportedImage, FailedToProcess, Timeout, or InternalServerError.
 1758        /// </summary>
 1759        /// <param name='url'>
 1760        /// Publicly reachable URL of an image.
 1761        /// </param>
 1762        /// <param name='customHeaders'>
 1763        /// Headers that will be added to request.
 1764        /// </param>
 1765        /// <param name='cancellationToken'>
 1766        /// The cancellation token.
 1767        /// </param>
 1768        /// <exception cref="ComputerVisionErrorException">
 1769        /// Thrown when the operation returned an invalid status code
 1770        /// </exception>
 1771        /// <exception cref="SerializationException">
 1772        /// Thrown when unable to deserialize the response
 1773        /// </exception>
 1774        /// <exception cref="ValidationException">
 1775        /// Thrown when a required parameter is null
 1776        /// </exception>
 1777        /// <exception cref="System.ArgumentNullException">
 1778        /// Thrown when a required parameter is null
 1779        /// </exception>
 1780        /// <return>
 1781        /// A response object containing the response body and response headers.
 1782        /// </return>
 1783        public async Task<HttpOperationResponse<AreaOfInterestResult>> GetAreaOfInterestWithHttpMessagesAsync(string url
 1784        {
 21785            if (Endpoint == null)
 1786            {
 01787                throw new ValidationException(ValidationRules.CannotBeNull, "this.Endpoint");
 1788            }
 21789            if (url == null)
 1790            {
 01791                throw new ValidationException(ValidationRules.CannotBeNull, "url");
 1792            }
 21793            ImageUrl imageUrl = new ImageUrl();
 21794            if (url != null)
 1795            {
 21796                imageUrl.Url = url;
 1797            }
 1798            // Tracing
 21799            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 21800            string _invocationId = null;
 21801            if (_shouldTrace)
 1802            {
 01803                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 01804                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 01805                tracingParameters.Add("imageUrl", imageUrl);
 01806                tracingParameters.Add("cancellationToken", cancellationToken);
 01807                ServiceClientTracing.Enter(_invocationId, this, "GetAreaOfInterest", tracingParameters);
 1808            }
 1809            // Construct URL
 21810            var _baseUrl = BaseUri;
 21811            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "areaOfInterest";
 21812            _url = _url.Replace("{Endpoint}", Endpoint);
 1813            // Create HTTP transport objects
 21814            var _httpRequest = new HttpRequestMessage();
 21815            HttpResponseMessage _httpResponse = null;
 21816            _httpRequest.Method = new HttpMethod("POST");
 21817            _httpRequest.RequestUri = new System.Uri(_url);
 1818            // Set Headers
 1819
 1820
 21821            if (customHeaders != null)
 1822            {
 01823                foreach(var _header in customHeaders)
 1824                {
 01825                    if (_httpRequest.Headers.Contains(_header.Key))
 1826                    {
 01827                        _httpRequest.Headers.Remove(_header.Key);
 1828                    }
 01829                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 1830                }
 1831            }
 1832
 1833            // Serialize Request
 21834            string _requestContent = null;
 21835            if(imageUrl != null)
 1836            {
 21837                _requestContent = SafeJsonConvert.SerializeObject(imageUrl, SerializationSettings);
 21838                _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
 21839                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 1840            }
 1841            // Set Credentials
 21842            if (Credentials != null)
 1843            {
 21844                cancellationToken.ThrowIfCancellationRequested();
 21845                await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 1846            }
 1847            // Send Request
 21848            if (_shouldTrace)
 1849            {
 01850                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 1851            }
 21852            cancellationToken.ThrowIfCancellationRequested();
 21853            _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 21854            if (_shouldTrace)
 1855            {
 01856                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 1857            }
 21858            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 21859            cancellationToken.ThrowIfCancellationRequested();
 21860            string _responseContent = null;
 21861            if ((int)_statusCode != 200)
 1862            {
 01863                var ex = new ComputerVisionErrorException(string.Format("Operation returned an invalid status code '{0}'
 1864                try
 1865                {
 01866                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 01867                    ComputerVisionError _errorBody =  SafeJsonConvert.DeserializeObject<ComputerVisionError>(_responseCo
 01868                    if (_errorBody != null)
 1869                    {
 01870                        ex.Body = _errorBody;
 1871                    }
 01872                }
 01873                catch (JsonException)
 1874                {
 1875                    // Ignore the exception
 01876                }
 01877                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 01878                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 01879                if (_shouldTrace)
 1880                {
 01881                    ServiceClientTracing.Error(_invocationId, ex);
 1882                }
 01883                _httpRequest.Dispose();
 01884                if (_httpResponse != null)
 1885                {
 01886                    _httpResponse.Dispose();
 1887                }
 01888                throw ex;
 1889            }
 1890            // Create Result
 21891            var _result = new HttpOperationResponse<AreaOfInterestResult>();
 21892            _result.Request = _httpRequest;
 21893            _result.Response = _httpResponse;
 1894            // Deserialize Response
 21895            if ((int)_statusCode == 200)
 1896            {
 21897                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 1898                try
 1899                {
 21900                    _result.Body = SafeJsonConvert.DeserializeObject<AreaOfInterestResult>(_responseContent, Deserializa
 21901                }
 01902                catch (JsonException ex)
 1903                {
 01904                    _httpRequest.Dispose();
 01905                    if (_httpResponse != null)
 1906                    {
 01907                        _httpResponse.Dispose();
 1908                    }
 01909                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 1910                }
 1911            }
 21912            if (_shouldTrace)
 1913            {
 01914                ServiceClientTracing.Exit(_invocationId, _result);
 1915            }
 21916            return _result;
 21917        }
 1918
 1919        /// <summary>
 1920        /// This operation extracts a rich set of visual features based on the image
 1921        /// content.
 1922        /// Two input methods are supported -- (1) Uploading an image or (2) specifying
 1923        /// an image URL. Within your request, there is an optional parameter to allow
 1924        /// you to choose which features to return. By default, image categories are
 1925        /// returned in the response.
 1926        /// A successful response will be returned in JSON. If the request failed, the
 1927        /// response will contain an error code and a message to help understand what
 1928        /// went wrong.
 1929        /// </summary>
 1930        /// <param name='image'>
 1931        /// An image stream.
 1932        /// </param>
 1933        /// <param name='visualFeatures'>
 1934        /// A string indicating what visual feature types to return. Multiple values
 1935        /// should be comma-separated. Valid visual feature types include: Categories -
 1936        /// categorizes image content according to a taxonomy defined in documentation.
 1937        /// Tags - tags the image with a detailed list of words related to the image
 1938        /// content. Description - describes the image content with a complete English
 1939        /// sentence. Faces - detects if faces are present. If present, generate
 1940        /// coordinates, gender and age. ImageType - detects if image is clipart or a
 1941        /// line drawing. Color - determines the accent color, dominant color, and
 1942        /// whether an image is black&amp;white. Adult - detects if the image is
 1943        /// pornographic in nature (depicts nudity or a sex act), or is gory (depicts
 1944        /// extreme violence or blood). Sexually suggestive content (aka racy content)
 1945        /// is also detected. Objects - detects various objects within an image,
 1946        /// including the approximate location. The Objects argument is only available
 1947        /// in English. Brands - detects various brands within an image, including the
 1948        /// approximate location. The Brands argument is only available in English.
 1949        /// </param>
 1950        /// <param name='details'>
 1951        /// A string indicating which domain-specific details to return. Multiple
 1952        /// values should be comma-separated. Valid visual feature types include:
 1953        /// Celebrities - identifies celebrities if detected in the image, Landmarks -
 1954        /// identifies notable landmarks in the image.
 1955        /// </param>
 1956        /// <param name='language'>
 1957        /// The desired language for output generation. If this parameter is not
 1958        /// specified, the default value is &amp;quot;en&amp;quot;.Supported
 1959        /// languages:en - English, Default. es - Spanish, ja - Japanese, pt -
 1960        /// Portuguese, zh - Simplified Chinese. Possible values include: 'en', 'es',
 1961        /// 'ja', 'pt', 'zh'
 1962        /// </param>
 1963        /// <param name='descriptionExclude'>
 1964        /// Turn off specified domain models when generating the description.
 1965        /// </param>
 1966        /// <param name='customHeaders'>
 1967        /// Headers that will be added to request.
 1968        /// </param>
 1969        /// <param name='cancellationToken'>
 1970        /// The cancellation token.
 1971        /// </param>
 1972        /// <exception cref="ComputerVisionErrorException">
 1973        /// Thrown when the operation returned an invalid status code
 1974        /// </exception>
 1975        /// <exception cref="SerializationException">
 1976        /// Thrown when unable to deserialize the response
 1977        /// </exception>
 1978        /// <exception cref="ValidationException">
 1979        /// Thrown when a required parameter is null
 1980        /// </exception>
 1981        /// <exception cref="System.ArgumentNullException">
 1982        /// Thrown when a required parameter is null
 1983        /// </exception>
 1984        /// <return>
 1985        /// A response object containing the response body and response headers.
 1986        /// </return>
 1987        public async Task<HttpOperationResponse<ImageAnalysis>> AnalyzeImageInStreamWithHttpMessagesAsync(Stream image, 
 1988        {
 21989            if (Endpoint == null)
 1990            {
 01991                throw new ValidationException(ValidationRules.CannotBeNull, "this.Endpoint");
 1992            }
 21993            if (image == null)
 1994            {
 01995                throw new ValidationException(ValidationRules.CannotBeNull, "image");
 1996            }
 1997            // Tracing
 21998            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 21999            string _invocationId = null;
 22000            if (_shouldTrace)
 2001            {
 02002                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 02003                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 02004                tracingParameters.Add("visualFeatures", visualFeatures);
 02005                tracingParameters.Add("details", details);
 02006                tracingParameters.Add("language", language);
 02007                tracingParameters.Add("descriptionExclude", descriptionExclude);
 02008                tracingParameters.Add("image", image);
 02009                tracingParameters.Add("cancellationToken", cancellationToken);
 02010                ServiceClientTracing.Enter(_invocationId, this, "AnalyzeImageInStream", tracingParameters);
 2011            }
 2012            // Construct URL
 22013            var _baseUrl = BaseUri;
 22014            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "analyze";
 22015            _url = _url.Replace("{Endpoint}", Endpoint);
 22016            List<string> _queryParameters = new List<string>();
 22017            if (visualFeatures != null)
 2018            {
 22019                _queryParameters.Add(string.Format("visualFeatures={0}", System.Uri.EscapeDataString(string.Join(",", vi
 2020            }
 22021            if (details != null)
 2022            {
 02023                _queryParameters.Add(string.Format("details={0}", System.Uri.EscapeDataString(string.Join(",", details))
 2024            }
 22025            if (language != null)
 2026            {
 02027                _queryParameters.Add(string.Format("language={0}", System.Uri.EscapeDataString(SafeJsonConvert.Serialize
 2028            }
 22029            if (descriptionExclude != null)
 2030            {
 02031                _queryParameters.Add(string.Format("descriptionExclude={0}", System.Uri.EscapeDataString(string.Join(","
 2032            }
 22033            if (_queryParameters.Count > 0)
 2034            {
 22035                _url += "?" + string.Join("&", _queryParameters);
 2036            }
 2037            // Create HTTP transport objects
 22038            var _httpRequest = new HttpRequestMessage();
 22039            HttpResponseMessage _httpResponse = null;
 22040            _httpRequest.Method = new HttpMethod("POST");
 22041            _httpRequest.RequestUri = new System.Uri(_url);
 2042            // Set Headers
 2043
 2044
 22045            if (customHeaders != null)
 2046            {
 02047                foreach(var _header in customHeaders)
 2048                {
 02049                    if (_httpRequest.Headers.Contains(_header.Key))
 2050                    {
 02051                        _httpRequest.Headers.Remove(_header.Key);
 2052                    }
 02053                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 2054                }
 2055            }
 2056
 2057            // Serialize Request
 22058            string _requestContent = null;
 22059            if(image == null)
 2060            {
 02061              throw new System.ArgumentNullException("image");
 2062            }
 22063            if (image != null && image != Stream.Null)
 2064            {
 22065                _httpRequest.Content = new StreamContent(image);
 22066                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 2067            }
 2068            // Set Credentials
 22069            if (Credentials != null)
 2070            {
 22071                cancellationToken.ThrowIfCancellationRequested();
 22072                await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 2073            }
 2074            // Send Request
 22075            if (_shouldTrace)
 2076            {
 02077                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 2078            }
 22079            cancellationToken.ThrowIfCancellationRequested();
 22080            _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 22081            if (_shouldTrace)
 2082            {
 02083                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 2084            }
 22085            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 22086            cancellationToken.ThrowIfCancellationRequested();
 22087            string _responseContent = null;
 22088            if ((int)_statusCode != 200)
 2089            {
 02090                var ex = new ComputerVisionErrorException(string.Format("Operation returned an invalid status code '{0}'
 2091                try
 2092                {
 02093                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 02094                    ComputerVisionError _errorBody =  SafeJsonConvert.DeserializeObject<ComputerVisionError>(_responseCo
 02095                    if (_errorBody != null)
 2096                    {
 02097                        ex.Body = _errorBody;
 2098                    }
 02099                }
 02100                catch (JsonException)
 2101                {
 2102                    // Ignore the exception
 02103                }
 02104                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 02105                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 02106                if (_shouldTrace)
 2107                {
 02108                    ServiceClientTracing.Error(_invocationId, ex);
 2109                }
 02110                _httpRequest.Dispose();
 02111                if (_httpResponse != null)
 2112                {
 02113                    _httpResponse.Dispose();
 2114                }
 02115                throw ex;
 2116            }
 2117            // Create Result
 22118            var _result = new HttpOperationResponse<ImageAnalysis>();
 22119            _result.Request = _httpRequest;
 22120            _result.Response = _httpResponse;
 2121            // Deserialize Response
 22122            if ((int)_statusCode == 200)
 2123            {
 22124                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 2125                try
 2126                {
 22127                    _result.Body = SafeJsonConvert.DeserializeObject<ImageAnalysis>(_responseContent, DeserializationSet
 22128                }
 02129                catch (JsonException ex)
 2130                {
 02131                    _httpRequest.Dispose();
 02132                    if (_httpResponse != null)
 2133                    {
 02134                        _httpResponse.Dispose();
 2135                    }
 02136                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 2137                }
 2138            }
 22139            if (_shouldTrace)
 2140            {
 02141                ServiceClientTracing.Exit(_invocationId, _result);
 2142            }
 22143            return _result;
 22144        }
 2145
 2146        /// <summary>
 2147        /// This operation returns a bounding box around the most important area of the
 2148        /// image.
 2149        /// A successful response will be returned in JSON. If the request failed, the
 2150        /// response contains an error code and a message to help determine what went
 2151        /// wrong.
 2152        /// Upon failure, the error code and an error message are returned. The error
 2153        /// code could be one of InvalidImageUrl, InvalidImageFormat, InvalidImageSize,
 2154        /// NotSupportedImage, FailedToProcess, Timeout, or InternalServerError.
 2155        /// </summary>
 2156        /// <param name='image'>
 2157        /// An image stream.
 2158        /// </param>
 2159        /// <param name='customHeaders'>
 2160        /// Headers that will be added to request.
 2161        /// </param>
 2162        /// <param name='cancellationToken'>
 2163        /// The cancellation token.
 2164        /// </param>
 2165        /// <exception cref="ComputerVisionErrorException">
 2166        /// Thrown when the operation returned an invalid status code
 2167        /// </exception>
 2168        /// <exception cref="SerializationException">
 2169        /// Thrown when unable to deserialize the response
 2170        /// </exception>
 2171        /// <exception cref="ValidationException">
 2172        /// Thrown when a required parameter is null
 2173        /// </exception>
 2174        /// <exception cref="System.ArgumentNullException">
 2175        /// Thrown when a required parameter is null
 2176        /// </exception>
 2177        /// <return>
 2178        /// A response object containing the response body and response headers.
 2179        /// </return>
 2180        public async Task<HttpOperationResponse<AreaOfInterestResult>> GetAreaOfInterestInStreamWithHttpMessagesAsync(St
 2181        {
 42182            if (Endpoint == null)
 2183            {
 02184                throw new ValidationException(ValidationRules.CannotBeNull, "this.Endpoint");
 2185            }
 42186            if (image == null)
 2187            {
 02188                throw new ValidationException(ValidationRules.CannotBeNull, "image");
 2189            }
 2190            // Tracing
 42191            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 42192            string _invocationId = null;
 42193            if (_shouldTrace)
 2194            {
 02195                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 02196                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 02197                tracingParameters.Add("image", image);
 02198                tracingParameters.Add("cancellationToken", cancellationToken);
 02199                ServiceClientTracing.Enter(_invocationId, this, "GetAreaOfInterestInStream", tracingParameters);
 2200            }
 2201            // Construct URL
 42202            var _baseUrl = BaseUri;
 42203            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "areaOfInterest";
 42204            _url = _url.Replace("{Endpoint}", Endpoint);
 2205            // Create HTTP transport objects
 42206            var _httpRequest = new HttpRequestMessage();
 42207            HttpResponseMessage _httpResponse = null;
 42208            _httpRequest.Method = new HttpMethod("POST");
 42209            _httpRequest.RequestUri = new System.Uri(_url);
 2210            // Set Headers
 2211
 2212
 42213            if (customHeaders != null)
 2214            {
 02215                foreach(var _header in customHeaders)
 2216                {
 02217                    if (_httpRequest.Headers.Contains(_header.Key))
 2218                    {
 02219                        _httpRequest.Headers.Remove(_header.Key);
 2220                    }
 02221                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 2222                }
 2223            }
 2224
 2225            // Serialize Request
 42226            string _requestContent = null;
 42227            if(image == null)
 2228            {
 02229              throw new System.ArgumentNullException("image");
 2230            }
 42231            if (image != null && image != Stream.Null)
 2232            {
 42233                _httpRequest.Content = new StreamContent(image);
 42234                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 2235            }
 2236            // Set Credentials
 42237            if (Credentials != null)
 2238            {
 42239                cancellationToken.ThrowIfCancellationRequested();
 42240                await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 2241            }
 2242            // Send Request
 42243            if (_shouldTrace)
 2244            {
 02245                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 2246            }
 42247            cancellationToken.ThrowIfCancellationRequested();
 42248            _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 42249            if (_shouldTrace)
 2250            {
 02251                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 2252            }
 42253            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 42254            cancellationToken.ThrowIfCancellationRequested();
 42255            string _responseContent = null;
 42256            if ((int)_statusCode != 200)
 2257            {
 02258                var ex = new ComputerVisionErrorException(string.Format("Operation returned an invalid status code '{0}'
 2259                try
 2260                {
 02261                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 02262                    ComputerVisionError _errorBody =  SafeJsonConvert.DeserializeObject<ComputerVisionError>(_responseCo
 02263                    if (_errorBody != null)
 2264                    {
 02265                        ex.Body = _errorBody;
 2266                    }
 02267                }
 02268                catch (JsonException)
 2269                {
 2270                    // Ignore the exception
 02271                }
 02272                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 02273                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 02274                if (_shouldTrace)
 2275                {
 02276                    ServiceClientTracing.Error(_invocationId, ex);
 2277                }
 02278                _httpRequest.Dispose();
 02279                if (_httpResponse != null)
 2280                {
 02281                    _httpResponse.Dispose();
 2282                }
 02283                throw ex;
 2284            }
 2285            // Create Result
 42286            var _result = new HttpOperationResponse<AreaOfInterestResult>();
 42287            _result.Request = _httpRequest;
 42288            _result.Response = _httpResponse;
 2289            // Deserialize Response
 42290            if ((int)_statusCode == 200)
 2291            {
 42292                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 2293                try
 2294                {
 42295                    _result.Body = SafeJsonConvert.DeserializeObject<AreaOfInterestResult>(_responseContent, Deserializa
 42296                }
 02297                catch (JsonException ex)
 2298                {
 02299                    _httpRequest.Dispose();
 02300                    if (_httpResponse != null)
 2301                    {
 02302                        _httpResponse.Dispose();
 2303                    }
 02304                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 2305                }
 2306            }
 42307            if (_shouldTrace)
 2308            {
 02309                ServiceClientTracing.Exit(_invocationId, _result);
 2310            }
 42311            return _result;
 42312        }
 2313
 2314        /// <summary>
 2315        /// This operation generates a description of an image in human readable
 2316        /// language with complete sentences. The description is based on a collection
 2317        /// of content tags, which are also returned by the operation. More than one
 2318        /// description can be generated for each image. Descriptions are ordered by
 2319        /// their confidence score. Descriptions may include results from celebrity and
 2320        /// landmark domain models, if applicable.
 2321        /// Two input methods are supported -- (1) Uploading an image or (2) specifying
 2322        /// an image URL.
 2323        /// A successful response will be returned in JSON. If the request failed, the
 2324        /// response will contain an error code and a message to help understand what
 2325        /// went wrong.
 2326        /// </summary>
 2327        /// <param name='image'>
 2328        /// An image stream.
 2329        /// </param>
 2330        /// <param name='maxCandidates'>
 2331        /// Maximum number of candidate descriptions to be returned.  The default is 1.
 2332        /// </param>
 2333        /// <param name='language'>
 2334        /// The desired language for output generation. If this parameter is not
 2335        /// specified, the default value is &amp;quot;en&amp;quot;.Supported
 2336        /// languages:en - English, Default. es - Spanish, ja - Japanese, pt -
 2337        /// Portuguese, zh - Simplified Chinese. Possible values include: 'en', 'es',
 2338        /// 'ja', 'pt', 'zh'
 2339        /// </param>
 2340        /// <param name='descriptionExclude'>
 2341        /// Turn off specified domain models when generating the description.
 2342        /// </param>
 2343        /// <param name='customHeaders'>
 2344        /// Headers that will be added to request.
 2345        /// </param>
 2346        /// <param name='cancellationToken'>
 2347        /// The cancellation token.
 2348        /// </param>
 2349        /// <exception cref="ComputerVisionErrorException">
 2350        /// Thrown when the operation returned an invalid status code
 2351        /// </exception>
 2352        /// <exception cref="SerializationException">
 2353        /// Thrown when unable to deserialize the response
 2354        /// </exception>
 2355        /// <exception cref="ValidationException">
 2356        /// Thrown when a required parameter is null
 2357        /// </exception>
 2358        /// <exception cref="System.ArgumentNullException">
 2359        /// Thrown when a required parameter is null
 2360        /// </exception>
 2361        /// <return>
 2362        /// A response object containing the response body and response headers.
 2363        /// </return>
 2364        public async Task<HttpOperationResponse<ImageDescription>> DescribeImageInStreamWithHttpMessagesAsync(Stream ima
 2365        {
 22366            if (Endpoint == null)
 2367            {
 02368                throw new ValidationException(ValidationRules.CannotBeNull, "this.Endpoint");
 2369            }
 22370            if (image == null)
 2371            {
 02372                throw new ValidationException(ValidationRules.CannotBeNull, "image");
 2373            }
 2374            // Tracing
 22375            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 22376            string _invocationId = null;
 22377            if (_shouldTrace)
 2378            {
 02379                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 02380                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 02381                tracingParameters.Add("maxCandidates", maxCandidates);
 02382                tracingParameters.Add("language", language);
 02383                tracingParameters.Add("descriptionExclude", descriptionExclude);
 02384                tracingParameters.Add("image", image);
 02385                tracingParameters.Add("cancellationToken", cancellationToken);
 02386                ServiceClientTracing.Enter(_invocationId, this, "DescribeImageInStream", tracingParameters);
 2387            }
 2388            // Construct URL
 22389            var _baseUrl = BaseUri;
 22390            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "describe";
 22391            _url = _url.Replace("{Endpoint}", Endpoint);
 22392            List<string> _queryParameters = new List<string>();
 22393            if (maxCandidates != null)
 2394            {
 22395                _queryParameters.Add(string.Format("maxCandidates={0}", System.Uri.EscapeDataString(SafeJsonConvert.Seri
 2396            }
 22397            if (language != null)
 2398            {
 02399                _queryParameters.Add(string.Format("language={0}", System.Uri.EscapeDataString(SafeJsonConvert.Serialize
 2400            }
 22401            if (descriptionExclude != null)
 2402            {
 02403                _queryParameters.Add(string.Format("descriptionExclude={0}", System.Uri.EscapeDataString(string.Join(","
 2404            }
 22405            if (_queryParameters.Count > 0)
 2406            {
 22407                _url += "?" + string.Join("&", _queryParameters);
 2408            }
 2409            // Create HTTP transport objects
 22410            var _httpRequest = new HttpRequestMessage();
 22411            HttpResponseMessage _httpResponse = null;
 22412            _httpRequest.Method = new HttpMethod("POST");
 22413            _httpRequest.RequestUri = new System.Uri(_url);
 2414            // Set Headers
 2415
 2416
 22417            if (customHeaders != null)
 2418            {
 02419                foreach(var _header in customHeaders)
 2420                {
 02421                    if (_httpRequest.Headers.Contains(_header.Key))
 2422                    {
 02423                        _httpRequest.Headers.Remove(_header.Key);
 2424                    }
 02425                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 2426                }
 2427            }
 2428
 2429            // Serialize Request
 22430            string _requestContent = null;
 22431            if(image == null)
 2432            {
 02433              throw new System.ArgumentNullException("image");
 2434            }
 22435            if (image != null && image != Stream.Null)
 2436            {
 22437                _httpRequest.Content = new StreamContent(image);
 22438                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 2439            }
 2440            // Set Credentials
 22441            if (Credentials != null)
 2442            {
 22443                cancellationToken.ThrowIfCancellationRequested();
 22444                await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 2445            }
 2446            // Send Request
 22447            if (_shouldTrace)
 2448            {
 02449                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 2450            }
 22451            cancellationToken.ThrowIfCancellationRequested();
 22452            _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 22453            if (_shouldTrace)
 2454            {
 02455                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 2456            }
 22457            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 22458            cancellationToken.ThrowIfCancellationRequested();
 22459            string _responseContent = null;
 22460            if ((int)_statusCode != 200)
 2461            {
 02462                var ex = new ComputerVisionErrorException(string.Format("Operation returned an invalid status code '{0}'
 2463                try
 2464                {
 02465                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 02466                    ComputerVisionError _errorBody =  SafeJsonConvert.DeserializeObject<ComputerVisionError>(_responseCo
 02467                    if (_errorBody != null)
 2468                    {
 02469                        ex.Body = _errorBody;
 2470                    }
 02471                }
 02472                catch (JsonException)
 2473                {
 2474                    // Ignore the exception
 02475                }
 02476                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 02477                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 02478                if (_shouldTrace)
 2479                {
 02480                    ServiceClientTracing.Error(_invocationId, ex);
 2481                }
 02482                _httpRequest.Dispose();
 02483                if (_httpResponse != null)
 2484                {
 02485                    _httpResponse.Dispose();
 2486                }
 02487                throw ex;
 2488            }
 2489            // Create Result
 22490            var _result = new HttpOperationResponse<ImageDescription>();
 22491            _result.Request = _httpRequest;
 22492            _result.Response = _httpResponse;
 2493            // Deserialize Response
 22494            if ((int)_statusCode == 200)
 2495            {
 22496                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 2497                try
 2498                {
 22499                    _result.Body = SafeJsonConvert.DeserializeObject<ImageDescription>(_responseContent, Deserialization
 22500                }
 02501                catch (JsonException ex)
 2502                {
 02503                    _httpRequest.Dispose();
 02504                    if (_httpResponse != null)
 2505                    {
 02506                        _httpResponse.Dispose();
 2507                    }
 02508                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 2509                }
 2510            }
 22511            if (_shouldTrace)
 2512            {
 02513                ServiceClientTracing.Exit(_invocationId, _result);
 2514            }
 22515            return _result;
 22516        }
 2517
 2518        /// <summary>
 2519        /// Performs object detection on the specified image.
 2520        /// Two input methods are supported -- (1) Uploading an image or (2) specifying
 2521        /// an image URL.
 2522        /// A successful response will be returned in JSON. If the request failed, the
 2523        /// response will contain an error code and a message to help understand what
 2524        /// went wrong.
 2525        /// </summary>
 2526        /// <param name='image'>
 2527        /// An image stream.
 2528        /// </param>
 2529        /// <param name='customHeaders'>
 2530        /// Headers that will be added to request.
 2531        /// </param>
 2532        /// <param name='cancellationToken'>
 2533        /// The cancellation token.
 2534        /// </param>
 2535        /// <exception cref="ComputerVisionErrorException">
 2536        /// Thrown when the operation returned an invalid status code
 2537        /// </exception>
 2538        /// <exception cref="SerializationException">
 2539        /// Thrown when unable to deserialize the response
 2540        /// </exception>
 2541        /// <exception cref="ValidationException">
 2542        /// Thrown when a required parameter is null
 2543        /// </exception>
 2544        /// <exception cref="System.ArgumentNullException">
 2545        /// Thrown when a required parameter is null
 2546        /// </exception>
 2547        /// <return>
 2548        /// A response object containing the response body and response headers.
 2549        /// </return>
 2550        public async Task<HttpOperationResponse<DetectResult>> DetectObjectsInStreamWithHttpMessagesAsync(Stream image, 
 2551        {
 22552            if (Endpoint == null)
 2553            {
 02554                throw new ValidationException(ValidationRules.CannotBeNull, "this.Endpoint");
 2555            }
 22556            if (image == null)
 2557            {
 02558                throw new ValidationException(ValidationRules.CannotBeNull, "image");
 2559            }
 2560            // Tracing
 22561            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 22562            string _invocationId = null;
 22563            if (_shouldTrace)
 2564            {
 02565                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 02566                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 02567                tracingParameters.Add("image", image);
 02568                tracingParameters.Add("cancellationToken", cancellationToken);
 02569                ServiceClientTracing.Enter(_invocationId, this, "DetectObjectsInStream", tracingParameters);
 2570            }
 2571            // Construct URL
 22572            var _baseUrl = BaseUri;
 22573            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "detect";
 22574            _url = _url.Replace("{Endpoint}", Endpoint);
 2575            // Create HTTP transport objects
 22576            var _httpRequest = new HttpRequestMessage();
 22577            HttpResponseMessage _httpResponse = null;
 22578            _httpRequest.Method = new HttpMethod("POST");
 22579            _httpRequest.RequestUri = new System.Uri(_url);
 2580            // Set Headers
 2581
 2582
 22583            if (customHeaders != null)
 2584            {
 02585                foreach(var _header in customHeaders)
 2586                {
 02587                    if (_httpRequest.Headers.Contains(_header.Key))
 2588                    {
 02589                        _httpRequest.Headers.Remove(_header.Key);
 2590                    }
 02591                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 2592                }
 2593            }
 2594
 2595            // Serialize Request
 22596            string _requestContent = null;
 22597            if(image == null)
 2598            {
 02599              throw new System.ArgumentNullException("image");
 2600            }
 22601            if (image != null && image != Stream.Null)
 2602            {
 22603                _httpRequest.Content = new StreamContent(image);
 22604                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 2605            }
 2606            // Set Credentials
 22607            if (Credentials != null)
 2608            {
 22609                cancellationToken.ThrowIfCancellationRequested();
 22610                await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 2611            }
 2612            // Send Request
 22613            if (_shouldTrace)
 2614            {
 02615                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 2616            }
 22617            cancellationToken.ThrowIfCancellationRequested();
 22618            _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 22619            if (_shouldTrace)
 2620            {
 02621                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 2622            }
 22623            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 22624            cancellationToken.ThrowIfCancellationRequested();
 22625            string _responseContent = null;
 22626            if ((int)_statusCode != 200)
 2627            {
 02628                var ex = new ComputerVisionErrorException(string.Format("Operation returned an invalid status code '{0}'
 2629                try
 2630                {
 02631                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 02632                    ComputerVisionError _errorBody =  SafeJsonConvert.DeserializeObject<ComputerVisionError>(_responseCo
 02633                    if (_errorBody != null)
 2634                    {
 02635                        ex.Body = _errorBody;
 2636                    }
 02637                }
 02638                catch (JsonException)
 2639                {
 2640                    // Ignore the exception
 02641                }
 02642                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 02643                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 02644                if (_shouldTrace)
 2645                {
 02646                    ServiceClientTracing.Error(_invocationId, ex);
 2647                }
 02648                _httpRequest.Dispose();
 02649                if (_httpResponse != null)
 2650                {
 02651                    _httpResponse.Dispose();
 2652                }
 02653                throw ex;
 2654            }
 2655            // Create Result
 22656            var _result = new HttpOperationResponse<DetectResult>();
 22657            _result.Request = _httpRequest;
 22658            _result.Response = _httpResponse;
 2659            // Deserialize Response
 22660            if ((int)_statusCode == 200)
 2661            {
 22662                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 2663                try
 2664                {
 22665                    _result.Body = SafeJsonConvert.DeserializeObject<DetectResult>(_responseContent, DeserializationSett
 22666                }
 02667                catch (JsonException ex)
 2668                {
 02669                    _httpRequest.Dispose();
 02670                    if (_httpResponse != null)
 2671                    {
 02672                        _httpResponse.Dispose();
 2673                    }
 02674                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 2675                }
 2676            }
 22677            if (_shouldTrace)
 2678            {
 02679                ServiceClientTracing.Exit(_invocationId, _result);
 2680            }
 22681            return _result;
 22682        }
 2683
 2684        /// <summary>
 2685        /// This operation generates a thumbnail image with the user-specified width
 2686        /// and height. By default, the service analyzes the image, identifies the
 2687        /// region of interest (ROI), and generates smart cropping coordinates based on
 2688        /// the ROI. Smart cropping helps when you specify an aspect ratio that differs
 2689        /// from that of the input image.
 2690        /// A successful response contains the thumbnail image binary. If the request
 2691        /// failed, the response contains an error code and a message to help determine
 2692        /// what went wrong.
 2693        /// Upon failure, the error code and an error message are returned. The error
 2694        /// code could be one of InvalidImageUrl, InvalidImageFormat, InvalidImageSize,
 2695        /// InvalidThumbnailSize, NotSupportedImage, FailedToProcess, Timeout, or
 2696        /// InternalServerError.
 2697        /// </summary>
 2698        /// <param name='width'>
 2699        /// Width of the thumbnail, in pixels. It must be between 1 and 1024.
 2700        /// Recommended minimum of 50.
 2701        /// </param>
 2702        /// <param name='height'>
 2703        /// Height of the thumbnail, in pixels. It must be between 1 and 1024.
 2704        /// Recommended minimum of 50.
 2705        /// </param>
 2706        /// <param name='image'>
 2707        /// An image stream.
 2708        /// </param>
 2709        /// <param name='smartCropping'>
 2710        /// Boolean flag for enabling smart cropping.
 2711        /// </param>
 2712        /// <param name='customHeaders'>
 2713        /// Headers that will be added to request.
 2714        /// </param>
 2715        /// <param name='cancellationToken'>
 2716        /// The cancellation token.
 2717        /// </param>
 2718        /// <exception cref="HttpOperationException">
 2719        /// Thrown when the operation returned an invalid status code
 2720        /// </exception>
 2721        /// <exception cref="SerializationException">
 2722        /// Thrown when unable to deserialize the response
 2723        /// </exception>
 2724        /// <exception cref="ValidationException">
 2725        /// Thrown when a required parameter is null
 2726        /// </exception>
 2727        /// <exception cref="System.ArgumentNullException">
 2728        /// Thrown when a required parameter is null
 2729        /// </exception>
 2730        /// <return>
 2731        /// A response object containing the response body and response headers.
 2732        /// </return>
 2733        public async Task<HttpOperationResponse<Stream>> GenerateThumbnailInStreamWithHttpMessagesAsync(int width, int h
 2734        {
 22735            if (Endpoint == null)
 2736            {
 02737                throw new ValidationException(ValidationRules.CannotBeNull, "this.Endpoint");
 2738            }
 22739            if (width > 1024)
 2740            {
 02741                throw new ValidationException(ValidationRules.InclusiveMaximum, "width", 1024);
 2742            }
 22743            if (width < 1)
 2744            {
 02745                throw new ValidationException(ValidationRules.InclusiveMinimum, "width", 1);
 2746            }
 22747            if (height > 1024)
 2748            {
 02749                throw new ValidationException(ValidationRules.InclusiveMaximum, "height", 1024);
 2750            }
 22751            if (height < 1)
 2752            {
 02753                throw new ValidationException(ValidationRules.InclusiveMinimum, "height", 1);
 2754            }
 22755            if (image == null)
 2756            {
 02757                throw new ValidationException(ValidationRules.CannotBeNull, "image");
 2758            }
 2759            // Tracing
 22760            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 22761            string _invocationId = null;
 22762            if (_shouldTrace)
 2763            {
 02764                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 02765                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 02766                tracingParameters.Add("width", width);
 02767                tracingParameters.Add("height", height);
 02768                tracingParameters.Add("smartCropping", smartCropping);
 02769                tracingParameters.Add("image", image);
 02770                tracingParameters.Add("cancellationToken", cancellationToken);
 02771                ServiceClientTracing.Enter(_invocationId, this, "GenerateThumbnailInStream", tracingParameters);
 2772            }
 2773            // Construct URL
 22774            var _baseUrl = BaseUri;
 22775            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "generateThumbnail";
 22776            _url = _url.Replace("{Endpoint}", Endpoint);
 22777            List<string> _queryParameters = new List<string>();
 22778            _queryParameters.Add(string.Format("width={0}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeObject(
 22779            _queryParameters.Add(string.Format("height={0}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeObject
 22780            if (smartCropping != null)
 2781            {
 22782                _queryParameters.Add(string.Format("smartCropping={0}", System.Uri.EscapeDataString(SafeJsonConvert.Seri
 2783            }
 22784            if (_queryParameters.Count > 0)
 2785            {
 22786                _url += "?" + string.Join("&", _queryParameters);
 2787            }
 2788            // Create HTTP transport objects
 22789            var _httpRequest = new HttpRequestMessage();
 22790            HttpResponseMessage _httpResponse = null;
 22791            _httpRequest.Method = new HttpMethod("POST");
 22792            _httpRequest.RequestUri = new System.Uri(_url);
 2793            // Set Headers
 2794
 2795
 22796            if (customHeaders != null)
 2797            {
 02798                foreach(var _header in customHeaders)
 2799                {
 02800                    if (_httpRequest.Headers.Contains(_header.Key))
 2801                    {
 02802                        _httpRequest.Headers.Remove(_header.Key);
 2803                    }
 02804                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 2805                }
 2806            }
 2807
 2808            // Serialize Request
 22809            string _requestContent = null;
 22810            if(image == null)
 2811            {
 02812              throw new System.ArgumentNullException("image");
 2813            }
 22814            if (image != null && image != Stream.Null)
 2815            {
 22816                _httpRequest.Content = new StreamContent(image);
 22817                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 2818            }
 2819            // Set Credentials
 22820            if (Credentials != null)
 2821            {
 22822                cancellationToken.ThrowIfCancellationRequested();
 22823                await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 2824            }
 2825            // Send Request
 22826            if (_shouldTrace)
 2827            {
 02828                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 2829            }
 22830            cancellationToken.ThrowIfCancellationRequested();
 22831            _httpResponse = await HttpClient.SendAsync(_httpRequest, System.Net.Http.HttpCompletionOption.ResponseHeader
 22832            if (_shouldTrace)
 2833            {
 02834                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 2835            }
 22836            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 22837            cancellationToken.ThrowIfCancellationRequested();
 22838            string _responseContent = null;
 22839            if ((int)_statusCode != 200)
 2840            {
 02841                var ex = new HttpOperationException(string.Format("Operation returned an invalid status code '{0}'", _st
 02842                if (_httpResponse.Content != null) {
 02843                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 2844                }
 2845                else {
 02846                    _responseContent = string.Empty;
 2847                }
 02848                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 02849                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 02850                if (_shouldTrace)
 2851                {
 02852                    ServiceClientTracing.Error(_invocationId, ex);
 2853                }
 02854                _httpRequest.Dispose();
 02855                if (_httpResponse != null)
 2856                {
 02857                    _httpResponse.Dispose();
 2858                }
 02859                throw ex;
 2860            }
 2861            // Create Result
 22862            var _result = new HttpOperationResponse<Stream>();
 22863            _result.Request = _httpRequest;
 22864            _result.Response = _httpResponse;
 2865            // Deserialize Response
 22866            if ((int)_statusCode == 200)
 2867            {
 22868                _result.Body = await _httpResponse.Content.ReadAsStreamAsync().ConfigureAwait(false);
 2869            }
 22870            if (_shouldTrace)
 2871            {
 02872                ServiceClientTracing.Exit(_invocationId, _result);
 2873            }
 22874            return _result;
 22875        }
 2876
 2877        /// <summary>
 2878        /// This operation recognizes content within an image by applying a
 2879        /// domain-specific model. The list of domain-specific models that are
 2880        /// supported by the Computer Vision API can be retrieved using the /models GET
 2881        /// request. Currently, the API provides following domain-specific models:
 2882        /// celebrities, landmarks.
 2883        /// Two input methods are supported -- (1) Uploading an image or (2) specifying
 2884        /// an image URL.
 2885        /// A successful response will be returned in JSON.
 2886        /// If the request failed, the response will contain an error code and a
 2887        /// message to help understand what went wrong.
 2888        /// </summary>
 2889        /// <param name='model'>
 2890        /// The domain-specific content to recognize.
 2891        /// </param>
 2892        /// <param name='image'>
 2893        /// An image stream.
 2894        /// </param>
 2895        /// <param name='language'>
 2896        /// The desired language for output generation. If this parameter is not
 2897        /// specified, the default value is &amp;quot;en&amp;quot;.Supported
 2898        /// languages:en - English, Default. es - Spanish, ja - Japanese, pt -
 2899        /// Portuguese, zh - Simplified Chinese. Possible values include: 'en', 'es',
 2900        /// 'ja', 'pt', 'zh'
 2901        /// </param>
 2902        /// <param name='customHeaders'>
 2903        /// Headers that will be added to request.
 2904        /// </param>
 2905        /// <param name='cancellationToken'>
 2906        /// The cancellation token.
 2907        /// </param>
 2908        /// <exception cref="ComputerVisionErrorException">
 2909        /// Thrown when the operation returned an invalid status code
 2910        /// </exception>
 2911        /// <exception cref="SerializationException">
 2912        /// Thrown when unable to deserialize the response
 2913        /// </exception>
 2914        /// <exception cref="ValidationException">
 2915        /// Thrown when a required parameter is null
 2916        /// </exception>
 2917        /// <exception cref="System.ArgumentNullException">
 2918        /// Thrown when a required parameter is null
 2919        /// </exception>
 2920        /// <return>
 2921        /// A response object containing the response body and response headers.
 2922        /// </return>
 2923        public async Task<HttpOperationResponse<DomainModelResults>> AnalyzeImageByDomainInStreamWithHttpMessagesAsync(s
 2924        {
 22925            if (Endpoint == null)
 2926            {
 02927                throw new ValidationException(ValidationRules.CannotBeNull, "this.Endpoint");
 2928            }
 22929            if (model == null)
 2930            {
 02931                throw new ValidationException(ValidationRules.CannotBeNull, "model");
 2932            }
 22933            if (image == null)
 2934            {
 02935                throw new ValidationException(ValidationRules.CannotBeNull, "image");
 2936            }
 2937            // Tracing
 22938            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 22939            string _invocationId = null;
 22940            if (_shouldTrace)
 2941            {
 02942                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 02943                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 02944                tracingParameters.Add("model", model);
 02945                tracingParameters.Add("language", language);
 02946                tracingParameters.Add("image", image);
 02947                tracingParameters.Add("cancellationToken", cancellationToken);
 02948                ServiceClientTracing.Enter(_invocationId, this, "AnalyzeImageByDomainInStream", tracingParameters);
 2949            }
 2950            // Construct URL
 22951            var _baseUrl = BaseUri;
 22952            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "models/{model}/analyze";
 22953            _url = _url.Replace("{Endpoint}", Endpoint);
 22954            _url = _url.Replace("{model}", System.Uri.EscapeDataString(model));
 22955            List<string> _queryParameters = new List<string>();
 22956            if (language != null)
 2957            {
 02958                _queryParameters.Add(string.Format("language={0}", System.Uri.EscapeDataString(SafeJsonConvert.Serialize
 2959            }
 22960            if (_queryParameters.Count > 0)
 2961            {
 02962                _url += "?" + string.Join("&", _queryParameters);
 2963            }
 2964            // Create HTTP transport objects
 22965            var _httpRequest = new HttpRequestMessage();
 22966            HttpResponseMessage _httpResponse = null;
 22967            _httpRequest.Method = new HttpMethod("POST");
 22968            _httpRequest.RequestUri = new System.Uri(_url);
 2969            // Set Headers
 2970
 2971
 22972            if (customHeaders != null)
 2973            {
 02974                foreach(var _header in customHeaders)
 2975                {
 02976                    if (_httpRequest.Headers.Contains(_header.Key))
 2977                    {
 02978                        _httpRequest.Headers.Remove(_header.Key);
 2979                    }
 02980                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 2981                }
 2982            }
 2983
 2984            // Serialize Request
 22985            string _requestContent = null;
 22986            if(image == null)
 2987            {
 02988              throw new System.ArgumentNullException("image");
 2989            }
 22990            if (image != null && image != Stream.Null)
 2991            {
 22992                _httpRequest.Content = new StreamContent(image);
 22993                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 2994            }
 2995            // Set Credentials
 22996            if (Credentials != null)
 2997            {
 22998                cancellationToken.ThrowIfCancellationRequested();
 22999                await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 3000            }
 3001            // Send Request
 23002            if (_shouldTrace)
 3003            {
 03004                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 3005            }
 23006            cancellationToken.ThrowIfCancellationRequested();
 23007            _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 23008            if (_shouldTrace)
 3009            {
 03010                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 3011            }
 23012            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 23013            cancellationToken.ThrowIfCancellationRequested();
 23014            string _responseContent = null;
 23015            if ((int)_statusCode != 200)
 3016            {
 03017                var ex = new ComputerVisionErrorException(string.Format("Operation returned an invalid status code '{0}'
 3018                try
 3019                {
 03020                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 03021                    ComputerVisionError _errorBody =  SafeJsonConvert.DeserializeObject<ComputerVisionError>(_responseCo
 03022                    if (_errorBody != null)
 3023                    {
 03024                        ex.Body = _errorBody;
 3025                    }
 03026                }
 03027                catch (JsonException)
 3028                {
 3029                    // Ignore the exception
 03030                }
 03031                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 03032                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 03033                if (_shouldTrace)
 3034                {
 03035                    ServiceClientTracing.Error(_invocationId, ex);
 3036                }
 03037                _httpRequest.Dispose();
 03038                if (_httpResponse != null)
 3039                {
 03040                    _httpResponse.Dispose();
 3041                }
 03042                throw ex;
 3043            }
 3044            // Create Result
 23045            var _result = new HttpOperationResponse<DomainModelResults>();
 23046            _result.Request = _httpRequest;
 23047            _result.Response = _httpResponse;
 3048            // Deserialize Response
 23049            if ((int)_statusCode == 200)
 3050            {
 23051                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 3052                try
 3053                {
 23054                    _result.Body = SafeJsonConvert.DeserializeObject<DomainModelResults>(_responseContent, Deserializati
 23055                }
 03056                catch (JsonException ex)
 3057                {
 03058                    _httpRequest.Dispose();
 03059                    if (_httpResponse != null)
 3060                    {
 03061                        _httpResponse.Dispose();
 3062                    }
 03063                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 3064                }
 3065            }
 23066            if (_shouldTrace)
 3067            {
 03068                ServiceClientTracing.Exit(_invocationId, _result);
 3069            }
 23070            return _result;
 23071        }
 3072
 3073        /// <summary>
 3074        /// Optical Character Recognition (OCR) detects text in an image and extracts
 3075        /// the recognized characters into a machine-usable character stream.
 3076        /// Upon success, the OCR results will be returned.
 3077        /// Upon failure, the error code together with an error message will be
 3078        /// returned. The error code can be one of InvalidImageUrl, InvalidImageFormat,
 3079        /// InvalidImageSize, NotSupportedImage, NotSupportedLanguage, or
 3080        /// InternalServerError.
 3081        /// </summary>
 3082        /// <param name='detectOrientation'>
 3083        /// Whether detect the text orientation in the image. With
 3084        /// detectOrientation=true the OCR service tries to detect the image
 3085        /// orientation and correct it before further processing (e.g. if it's
 3086        /// upside-down).
 3087        /// </param>
 3088        /// <param name='image'>
 3089        /// An image stream.
 3090        /// </param>
 3091        /// <param name='language'>
 3092        /// The BCP-47 language code of the text to be detected in the image. The
 3093        /// default value is 'unk'. Possible values include: 'unk', 'zh-Hans',
 3094        /// 'zh-Hant', 'cs', 'da', 'nl', 'en', 'fi', 'fr', 'de', 'el', 'hu', 'it',
 3095        /// 'ja', 'ko', 'nb', 'pl', 'pt', 'ru', 'es', 'sv', 'tr', 'ar', 'ro',
 3096        /// 'sr-Cyrl', 'sr-Latn', 'sk'
 3097        /// </param>
 3098        /// <param name='customHeaders'>
 3099        /// Headers that will be added to request.
 3100        /// </param>
 3101        /// <param name='cancellationToken'>
 3102        /// The cancellation token.
 3103        /// </param>
 3104        /// <exception cref="ComputerVisionErrorException">
 3105        /// Thrown when the operation returned an invalid status code
 3106        /// </exception>
 3107        /// <exception cref="SerializationException">
 3108        /// Thrown when unable to deserialize the response
 3109        /// </exception>
 3110        /// <exception cref="ValidationException">
 3111        /// Thrown when a required parameter is null
 3112        /// </exception>
 3113        /// <exception cref="System.ArgumentNullException">
 3114        /// Thrown when a required parameter is null
 3115        /// </exception>
 3116        /// <return>
 3117        /// A response object containing the response body and response headers.
 3118        /// </return>
 3119        public async Task<HttpOperationResponse<OcrResult>> RecognizePrintedTextInStreamWithHttpMessagesAsync(bool detec
 3120        {
 23121            if (Endpoint == null)
 3122            {
 03123                throw new ValidationException(ValidationRules.CannotBeNull, "this.Endpoint");
 3124            }
 23125            if (image == null)
 3126            {
 03127                throw new ValidationException(ValidationRules.CannotBeNull, "image");
 3128            }
 3129            // Tracing
 23130            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 23131            string _invocationId = null;
 23132            if (_shouldTrace)
 3133            {
 03134                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 03135                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 03136                tracingParameters.Add("detectOrientation", detectOrientation);
 03137                tracingParameters.Add("language", language);
 03138                tracingParameters.Add("image", image);
 03139                tracingParameters.Add("cancellationToken", cancellationToken);
 03140                ServiceClientTracing.Enter(_invocationId, this, "RecognizePrintedTextInStream", tracingParameters);
 3141            }
 3142            // Construct URL
 23143            var _baseUrl = BaseUri;
 23144            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "ocr";
 23145            _url = _url.Replace("{Endpoint}", Endpoint);
 23146            List<string> _queryParameters = new List<string>();
 23147            _queryParameters.Add(string.Format("detectOrientation={0}", System.Uri.EscapeDataString(SafeJsonConvert.Seri
 23148            if (language != null)
 3149            {
 03150                _queryParameters.Add(string.Format("language={0}", System.Uri.EscapeDataString(SafeJsonConvert.Serialize
 3151            }
 23152            if (_queryParameters.Count > 0)
 3153            {
 23154                _url += "?" + string.Join("&", _queryParameters);
 3155            }
 3156            // Create HTTP transport objects
 23157            var _httpRequest = new HttpRequestMessage();
 23158            HttpResponseMessage _httpResponse = null;
 23159            _httpRequest.Method = new HttpMethod("POST");
 23160            _httpRequest.RequestUri = new System.Uri(_url);
 3161            // Set Headers
 3162
 3163
 23164            if (customHeaders != null)
 3165            {
 03166                foreach(var _header in customHeaders)
 3167                {
 03168                    if (_httpRequest.Headers.Contains(_header.Key))
 3169                    {
 03170                        _httpRequest.Headers.Remove(_header.Key);
 3171                    }
 03172                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 3173                }
 3174            }
 3175
 3176            // Serialize Request
 23177            string _requestContent = null;
 23178            if(image == null)
 3179            {
 03180              throw new System.ArgumentNullException("image");
 3181            }
 23182            if (image != null && image != Stream.Null)
 3183            {
 23184                _httpRequest.Content = new StreamContent(image);
 23185                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 3186            }
 3187            // Set Credentials
 23188            if (Credentials != null)
 3189            {
 23190                cancellationToken.ThrowIfCancellationRequested();
 23191                await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 3192            }
 3193            // Send Request
 23194            if (_shouldTrace)
 3195            {
 03196                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 3197            }
 23198            cancellationToken.ThrowIfCancellationRequested();
 23199            _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 23200            if (_shouldTrace)
 3201            {
 03202                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 3203            }
 23204            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 23205            cancellationToken.ThrowIfCancellationRequested();
 23206            string _responseContent = null;
 23207            if ((int)_statusCode != 200)
 3208            {
 03209                var ex = new ComputerVisionErrorException(string.Format("Operation returned an invalid status code '{0}'
 3210                try
 3211                {
 03212                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 03213                    ComputerVisionError _errorBody =  SafeJsonConvert.DeserializeObject<ComputerVisionError>(_responseCo
 03214                    if (_errorBody != null)
 3215                    {
 03216                        ex.Body = _errorBody;
 3217                    }
 03218                }
 03219                catch (JsonException)
 3220                {
 3221                    // Ignore the exception
 03222                }
 03223                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 03224                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 03225                if (_shouldTrace)
 3226                {
 03227                    ServiceClientTracing.Error(_invocationId, ex);
 3228                }
 03229                _httpRequest.Dispose();
 03230                if (_httpResponse != null)
 3231                {
 03232                    _httpResponse.Dispose();
 3233                }
 03234                throw ex;
 3235            }
 3236            // Create Result
 23237            var _result = new HttpOperationResponse<OcrResult>();
 23238            _result.Request = _httpRequest;
 23239            _result.Response = _httpResponse;
 3240            // Deserialize Response
 23241            if ((int)_statusCode == 200)
 3242            {
 23243                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 3244                try
 3245                {
 23246                    _result.Body = SafeJsonConvert.DeserializeObject<OcrResult>(_responseContent, DeserializationSetting
 23247                }
 03248                catch (JsonException ex)
 3249                {
 03250                    _httpRequest.Dispose();
 03251                    if (_httpResponse != null)
 3252                    {
 03253                        _httpResponse.Dispose();
 3254                    }
 03255                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 3256                }
 3257            }
 23258            if (_shouldTrace)
 3259            {
 03260                ServiceClientTracing.Exit(_invocationId, _result);
 3261            }
 23262            return _result;
 23263        }
 3264
 3265        /// <summary>
 3266        /// This operation generates a list of words, or tags, that are relevant to the
 3267        /// content of the supplied image. The Computer Vision API can return tags
 3268        /// based on objects, living beings, scenery or actions found in images. Unlike
 3269        /// categories, tags are not organized according to a hierarchical
 3270        /// classification system, but correspond to image content. Tags may contain
 3271        /// hints to avoid ambiguity or provide context, for example the tag
 3272        /// "ascomycete" may be accompanied by the hint "fungus".
 3273        /// Two input methods are supported -- (1) Uploading an image or (2) specifying
 3274        /// an image URL.
 3275        /// A successful response will be returned in JSON. If the request failed, the
 3276        /// response will contain an error code and a message to help understand what
 3277        /// went wrong.
 3278        /// </summary>
 3279        /// <param name='image'>
 3280        /// An image stream.
 3281        /// </param>
 3282        /// <param name='language'>
 3283        /// The desired language for output generation. If this parameter is not
 3284        /// specified, the default value is &amp;quot;en&amp;quot;.Supported
 3285        /// languages:en - English, Default. es - Spanish, ja - Japanese, pt -
 3286        /// Portuguese, zh - Simplified Chinese. Possible values include: 'en', 'es',
 3287        /// 'ja', 'pt', 'zh'
 3288        /// </param>
 3289        /// <param name='customHeaders'>
 3290        /// Headers that will be added to request.
 3291        /// </param>
 3292        /// <param name='cancellationToken'>
 3293        /// The cancellation token.
 3294        /// </param>
 3295        /// <exception cref="ComputerVisionErrorException">
 3296        /// Thrown when the operation returned an invalid status code
 3297        /// </exception>
 3298        /// <exception cref="SerializationException">
 3299        /// Thrown when unable to deserialize the response
 3300        /// </exception>
 3301        /// <exception cref="ValidationException">
 3302        /// Thrown when a required parameter is null
 3303        /// </exception>
 3304        /// <exception cref="System.ArgumentNullException">
 3305        /// Thrown when a required parameter is null
 3306        /// </exception>
 3307        /// <return>
 3308        /// A response object containing the response body and response headers.
 3309        /// </return>
 3310        public async Task<HttpOperationResponse<TagResult>> TagImageInStreamWithHttpMessagesAsync(Stream image, string l
 3311        {
 23312            if (Endpoint == null)
 3313            {
 03314                throw new ValidationException(ValidationRules.CannotBeNull, "this.Endpoint");
 3315            }
 23316            if (image == null)
 3317            {
 03318                throw new ValidationException(ValidationRules.CannotBeNull, "image");
 3319            }
 3320            // Tracing
 23321            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 23322            string _invocationId = null;
 23323            if (_shouldTrace)
 3324            {
 03325                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 03326                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 03327                tracingParameters.Add("language", language);
 03328                tracingParameters.Add("image", image);
 03329                tracingParameters.Add("cancellationToken", cancellationToken);
 03330                ServiceClientTracing.Enter(_invocationId, this, "TagImageInStream", tracingParameters);
 3331            }
 3332            // Construct URL
 23333            var _baseUrl = BaseUri;
 23334            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "tag";
 23335            _url = _url.Replace("{Endpoint}", Endpoint);
 23336            List<string> _queryParameters = new List<string>();
 23337            if (language != null)
 3338            {
 23339                _queryParameters.Add(string.Format("language={0}", System.Uri.EscapeDataString(SafeJsonConvert.Serialize
 3340            }
 23341            if (_queryParameters.Count > 0)
 3342            {
 23343                _url += "?" + string.Join("&", _queryParameters);
 3344            }
 3345            // Create HTTP transport objects
 23346            var _httpRequest = new HttpRequestMessage();
 23347            HttpResponseMessage _httpResponse = null;
 23348            _httpRequest.Method = new HttpMethod("POST");
 23349            _httpRequest.RequestUri = new System.Uri(_url);
 3350            // Set Headers
 3351
 3352
 23353            if (customHeaders != null)
 3354            {
 03355                foreach(var _header in customHeaders)
 3356                {
 03357                    if (_httpRequest.Headers.Contains(_header.Key))
 3358                    {
 03359                        _httpRequest.Headers.Remove(_header.Key);
 3360                    }
 03361                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 3362                }
 3363            }
 3364
 3365            // Serialize Request
 23366            string _requestContent = null;
 23367            if(image == null)
 3368            {
 03369              throw new System.ArgumentNullException("image");
 3370            }
 23371            if (image != null && image != Stream.Null)
 3372            {
 23373                _httpRequest.Content = new StreamContent(image);
 23374                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 3375            }
 3376            // Set Credentials
 23377            if (Credentials != null)
 3378            {
 23379                cancellationToken.ThrowIfCancellationRequested();
 23380                await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 3381            }
 3382            // Send Request
 23383            if (_shouldTrace)
 3384            {
 03385                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 3386            }
 23387            cancellationToken.ThrowIfCancellationRequested();
 23388            _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 23389            if (_shouldTrace)
 3390            {
 03391                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 3392            }
 23393            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 23394            cancellationToken.ThrowIfCancellationRequested();
 23395            string _responseContent = null;
 23396            if ((int)_statusCode != 200)
 3397            {
 03398                var ex = new ComputerVisionErrorException(string.Format("Operation returned an invalid status code '{0}'
 3399                try
 3400                {
 03401                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 03402                    ComputerVisionError _errorBody =  SafeJsonConvert.DeserializeObject<ComputerVisionError>(_responseCo
 03403                    if (_errorBody != null)
 3404                    {
 03405                        ex.Body = _errorBody;
 3406                    }
 03407                }
 03408                catch (JsonException)
 3409                {
 3410                    // Ignore the exception
 03411                }
 03412                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 03413                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 03414                if (_shouldTrace)
 3415                {
 03416                    ServiceClientTracing.Error(_invocationId, ex);
 3417                }
 03418                _httpRequest.Dispose();
 03419                if (_httpResponse != null)
 3420                {
 03421                    _httpResponse.Dispose();
 3422                }
 03423                throw ex;
 3424            }
 3425            // Create Result
 23426            var _result = new HttpOperationResponse<TagResult>();
 23427            _result.Request = _httpRequest;
 23428            _result.Response = _httpResponse;
 3429            // Deserialize Response
 23430            if ((int)_statusCode == 200)
 3431            {
 23432                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 3433                try
 3434                {
 23435                    _result.Body = SafeJsonConvert.DeserializeObject<TagResult>(_responseContent, DeserializationSetting
 23436                }
 03437                catch (JsonException ex)
 3438                {
 03439                    _httpRequest.Dispose();
 03440                    if (_httpResponse != null)
 3441                    {
 03442                        _httpResponse.Dispose();
 3443                    }
 03444                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 3445                }
 3446            }
 23447            if (_shouldTrace)
 3448            {
 03449                ServiceClientTracing.Exit(_invocationId, _result);
 3450            }
 23451            return _result;
 23452        }
 3453
 3454        /// <summary>
 3455        /// Use this interface to get the result of a Read operation, employing the
 3456        /// state-of-the-art Optical Character Recognition (OCR) algorithms optimized
 3457        /// for text-heavy documents. When you use the Read interface, the response
 3458        /// contains a field called 'Operation-Location'. The 'Operation-Location'
 3459        /// field contains the URL that you must use for your 'GetReadResult' operation
 3460        /// to access OCR results.​
 3461        /// </summary>
 3462        /// <param name='url'>
 3463        /// Publicly reachable URL of an image.
 3464        /// </param>
 3465        /// <param name='language'>
 3466        /// The BCP-47 language code of the text in the document. Currently, only
 3467        /// English ('en'), Dutch (‘nl’), French (‘fr’), German (‘de’), Italian (‘it’),
 3468        /// Portuguese (‘pt), and Spanish ('es') are supported. Read supports auto
 3469        /// language identification and multilanguage documents, so only provide a
 3470        /// language code if you would like to force the documented to be processed as
 3471        /// that specific language. Possible values include: 'en', 'es', 'fr', 'de',
 3472        /// 'it', 'nl', 'pt'
 3473        /// </param>
 3474        /// <param name='customHeaders'>
 3475        /// Headers that will be added to request.
 3476        /// </param>
 3477        /// <param name='cancellationToken'>
 3478        /// The cancellation token.
 3479        /// </param>
 3480        /// <exception cref="ComputerVisionErrorException">
 3481        /// Thrown when the operation returned an invalid status code
 3482        /// </exception>
 3483        /// <exception cref="ValidationException">
 3484        /// Thrown when a required parameter is null
 3485        /// </exception>
 3486        /// <exception cref="System.ArgumentNullException">
 3487        /// Thrown when a required parameter is null
 3488        /// </exception>
 3489        /// <return>
 3490        /// A response object containing the response body and response headers.
 3491        /// </return>
 3492        public async Task<HttpOperationHeaderResponse<ReadHeaders>> ReadWithHttpMessagesAsync(string url, string languag
 3493        {
 03494            if (Endpoint == null)
 3495            {
 03496                throw new ValidationException(ValidationRules.CannotBeNull, "this.Endpoint");
 3497            }
 03498            if (url == null)
 3499            {
 03500                throw new ValidationException(ValidationRules.CannotBeNull, "url");
 3501            }
 03502            ImageUrl imageUrl = new ImageUrl();
 03503            if (url != null)
 3504            {
 03505                imageUrl.Url = url;
 3506            }
 3507            // Tracing
 03508            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 03509            string _invocationId = null;
 03510            if (_shouldTrace)
 3511            {
 03512                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 03513                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 03514                tracingParameters.Add("language", language);
 03515                tracingParameters.Add("imageUrl", imageUrl);
 03516                tracingParameters.Add("cancellationToken", cancellationToken);
 03517                ServiceClientTracing.Enter(_invocationId, this, "Read", tracingParameters);
 3518            }
 3519            // Construct URL
 03520            var _baseUrl = BaseUri;
 03521            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "read/analyze";
 03522            _url = _url.Replace("{Endpoint}", Endpoint);
 03523            List<string> _queryParameters = new List<string>();
 03524            if (language != null)
 3525            {
 03526                _queryParameters.Add(string.Format("language={0}", System.Uri.EscapeDataString(language)));
 3527            }
 03528            if (_queryParameters.Count > 0)
 3529            {
 03530                _url += "?" + string.Join("&", _queryParameters);
 3531            }
 3532            // Create HTTP transport objects
 03533            var _httpRequest = new HttpRequestMessage();
 03534            HttpResponseMessage _httpResponse = null;
 03535            _httpRequest.Method = new HttpMethod("POST");
 03536            _httpRequest.RequestUri = new System.Uri(_url);
 3537            // Set Headers
 3538
 3539
 03540            if (customHeaders != null)
 3541            {
 03542                foreach(var _header in customHeaders)
 3543                {
 03544                    if (_httpRequest.Headers.Contains(_header.Key))
 3545                    {
 03546                        _httpRequest.Headers.Remove(_header.Key);
 3547                    }
 03548                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 3549                }
 3550            }
 3551
 3552            // Serialize Request
 03553            string _requestContent = null;
 03554            if(imageUrl != null)
 3555            {
 03556                _requestContent = SafeJsonConvert.SerializeObject(imageUrl, SerializationSettings);
 03557                _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
 03558                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 3559            }
 3560            // Set Credentials
 03561            if (Credentials != null)
 3562            {
 03563                cancellationToken.ThrowIfCancellationRequested();
 03564                await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 3565            }
 3566            // Send Request
 03567            if (_shouldTrace)
 3568            {
 03569                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 3570            }
 03571            cancellationToken.ThrowIfCancellationRequested();
 03572            _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 03573            if (_shouldTrace)
 3574            {
 03575                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 3576            }
 03577            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 03578            cancellationToken.ThrowIfCancellationRequested();
 03579            string _responseContent = null;
 03580            if ((int)_statusCode != 202)
 3581            {
 03582                var ex = new ComputerVisionErrorException(string.Format("Operation returned an invalid status code '{0}'
 3583                try
 3584                {
 03585                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 03586                    ComputerVisionError _errorBody =  SafeJsonConvert.DeserializeObject<ComputerVisionError>(_responseCo
 03587                    if (_errorBody != null)
 3588                    {
 03589                        ex.Body = _errorBody;
 3590                    }
 03591                }
 03592                catch (JsonException)
 3593                {
 3594                    // Ignore the exception
 03595                }
 03596                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 03597                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 03598                if (_shouldTrace)
 3599                {
 03600                    ServiceClientTracing.Error(_invocationId, ex);
 3601                }
 03602                _httpRequest.Dispose();
 03603                if (_httpResponse != null)
 3604                {
 03605                    _httpResponse.Dispose();
 3606                }
 03607                throw ex;
 3608            }
 3609            // Create Result
 03610            var _result = new HttpOperationHeaderResponse<ReadHeaders>();
 03611            _result.Request = _httpRequest;
 03612            _result.Response = _httpResponse;
 3613            try
 3614            {
 03615                _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<ReadHeaders>(JsonSerializer.Create(Deseriali
 03616            }
 03617            catch (JsonException ex)
 3618            {
 03619                _httpRequest.Dispose();
 03620                if (_httpResponse != null)
 3621                {
 03622                    _httpResponse.Dispose();
 3623                }
 03624                throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson().
 3625            }
 03626            if (_shouldTrace)
 3627            {
 03628                ServiceClientTracing.Exit(_invocationId, _result);
 3629            }
 03630            return _result;
 03631        }
 3632
 3633        /// <summary>
 3634        /// This interface is used for getting OCR results of Read operation. The URL
 3635        /// to this interface should be retrieved from 'Operation-Location' field
 3636        /// returned from Read interface.
 3637        /// </summary>
 3638        /// <param name='operationId'>
 3639        /// Id of read operation returned in the response of the 'Read' interface.
 3640        /// </param>
 3641        /// <param name='customHeaders'>
 3642        /// Headers that will be added to request.
 3643        /// </param>
 3644        /// <param name='cancellationToken'>
 3645        /// The cancellation token.
 3646        /// </param>
 3647        /// <exception cref="ComputerVisionErrorException">
 3648        /// Thrown when the operation returned an invalid status code
 3649        /// </exception>
 3650        /// <exception cref="SerializationException">
 3651        /// Thrown when unable to deserialize the response
 3652        /// </exception>
 3653        /// <exception cref="ValidationException">
 3654        /// Thrown when a required parameter is null
 3655        /// </exception>
 3656        /// <exception cref="System.ArgumentNullException">
 3657        /// Thrown when a required parameter is null
 3658        /// </exception>
 3659        /// <return>
 3660        /// A response object containing the response body and response headers.
 3661        /// </return>
 3662        public async Task<HttpOperationResponse<ReadOperationResult>> GetReadResultWithHttpMessagesAsync(System.Guid ope
 3663        {
 03664            if (Endpoint == null)
 3665            {
 03666                throw new ValidationException(ValidationRules.CannotBeNull, "this.Endpoint");
 3667            }
 3668            // Tracing
 03669            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 03670            string _invocationId = null;
 03671            if (_shouldTrace)
 3672            {
 03673                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 03674                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 03675                tracingParameters.Add("operationId", operationId);
 03676                tracingParameters.Add("cancellationToken", cancellationToken);
 03677                ServiceClientTracing.Enter(_invocationId, this, "GetReadResult", tracingParameters);
 3678            }
 3679            // Construct URL
 03680            var _baseUrl = BaseUri;
 03681            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "read/analyzeResults/{operationId}";
 03682            _url = _url.Replace("{Endpoint}", Endpoint);
 03683            _url = _url.Replace("{operationId}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeObject(operationId
 3684            // Create HTTP transport objects
 03685            var _httpRequest = new HttpRequestMessage();
 03686            HttpResponseMessage _httpResponse = null;
 03687            _httpRequest.Method = new HttpMethod("GET");
 03688            _httpRequest.RequestUri = new System.Uri(_url);
 3689            // Set Headers
 3690
 3691
 03692            if (customHeaders != null)
 3693            {
 03694                foreach(var _header in customHeaders)
 3695                {
 03696                    if (_httpRequest.Headers.Contains(_header.Key))
 3697                    {
 03698                        _httpRequest.Headers.Remove(_header.Key);
 3699                    }
 03700                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 3701                }
 3702            }
 3703
 3704            // Serialize Request
 03705            string _requestContent = null;
 3706            // Set Credentials
 03707            if (Credentials != null)
 3708            {
 03709                cancellationToken.ThrowIfCancellationRequested();
 03710                await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 3711            }
 3712            // Send Request
 03713            if (_shouldTrace)
 3714            {
 03715                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 3716            }
 03717            cancellationToken.ThrowIfCancellationRequested();
 03718            _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 03719            if (_shouldTrace)
 3720            {
 03721                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 3722            }
 03723            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 03724            cancellationToken.ThrowIfCancellationRequested();
 03725            string _responseContent = null;
 03726            if ((int)_statusCode != 200)
 3727            {
 03728                var ex = new ComputerVisionErrorException(string.Format("Operation returned an invalid status code '{0}'
 3729                try
 3730                {
 03731                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 03732                    ComputerVisionError _errorBody =  SafeJsonConvert.DeserializeObject<ComputerVisionError>(_responseCo
 03733                    if (_errorBody != null)
 3734                    {
 03735                        ex.Body = _errorBody;
 3736                    }
 03737                }
 03738                catch (JsonException)
 3739                {
 3740                    // Ignore the exception
 03741                }
 03742                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 03743                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 03744                if (_shouldTrace)
 3745                {
 03746                    ServiceClientTracing.Error(_invocationId, ex);
 3747                }
 03748                _httpRequest.Dispose();
 03749                if (_httpResponse != null)
 3750                {
 03751                    _httpResponse.Dispose();
 3752                }
 03753                throw ex;
 3754            }
 3755            // Create Result
 03756            var _result = new HttpOperationResponse<ReadOperationResult>();
 03757            _result.Request = _httpRequest;
 03758            _result.Response = _httpResponse;
 3759            // Deserialize Response
 03760            if ((int)_statusCode == 200)
 3761            {
 03762                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 3763                try
 3764                {
 03765                    _result.Body = SafeJsonConvert.DeserializeObject<ReadOperationResult>(_responseContent, Deserializat
 03766                }
 03767                catch (JsonException ex)
 3768                {
 03769                    _httpRequest.Dispose();
 03770                    if (_httpResponse != null)
 3771                    {
 03772                        _httpResponse.Dispose();
 3773                    }
 03774                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 3775                }
 3776            }
 03777            if (_shouldTrace)
 3778            {
 03779                ServiceClientTracing.Exit(_invocationId, _result);
 3780            }
 03781            return _result;
 03782        }
 3783
 3784        /// <summary>
 3785        /// Use this interface to get the result of a Read operation, employing the
 3786        /// state-of-the-art Optical Character Recognition (OCR) algorithms optimized
 3787        /// for text-heavy documents. When you use the Read interface, the response
 3788        /// contains a field called 'Operation-Location'. The 'Operation-Location'
 3789        /// field contains the URL that you must use for your 'GetReadResult' operation
 3790        /// to access OCR results.​
 3791        /// </summary>
 3792        /// <param name='image'>
 3793        /// An image stream.
 3794        /// </param>
 3795        /// <param name='language'>
 3796        /// The BCP-47 language code of the text in the document. Currently, only
 3797        /// English ('en'), Dutch (‘nl’), French (‘fr’), German (‘de’), Italian (‘it’),
 3798        /// Portuguese (‘pt), and Spanish ('es') are supported. Read supports auto
 3799        /// language identification and multilanguage documents, so only provide a
 3800        /// language code if you would like to force the documented to be processed as
 3801        /// that specific language. Possible values include: 'en', 'es', 'fr', 'de',
 3802        /// 'it', 'nl', 'pt'
 3803        /// </param>
 3804        /// <param name='customHeaders'>
 3805        /// Headers that will be added to request.
 3806        /// </param>
 3807        /// <param name='cancellationToken'>
 3808        /// The cancellation token.
 3809        /// </param>
 3810        /// <exception cref="ComputerVisionErrorException">
 3811        /// Thrown when the operation returned an invalid status code
 3812        /// </exception>
 3813        /// <exception cref="ValidationException">
 3814        /// Thrown when a required parameter is null
 3815        /// </exception>
 3816        /// <exception cref="System.ArgumentNullException">
 3817        /// Thrown when a required parameter is null
 3818        /// </exception>
 3819        /// <return>
 3820        /// A response object containing the response body and response headers.
 3821        /// </return>
 3822        public async Task<HttpOperationHeaderResponse<ReadInStreamHeaders>> ReadInStreamWithHttpMessagesAsync(Stream ima
 3823        {
 03824            if (Endpoint == null)
 3825            {
 03826                throw new ValidationException(ValidationRules.CannotBeNull, "this.Endpoint");
 3827            }
 03828            if (image == null)
 3829            {
 03830                throw new ValidationException(ValidationRules.CannotBeNull, "image");
 3831            }
 3832            // Tracing
 03833            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 03834            string _invocationId = null;
 03835            if (_shouldTrace)
 3836            {
 03837                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 03838                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 03839                tracingParameters.Add("language", language);
 03840                tracingParameters.Add("image", image);
 03841                tracingParameters.Add("cancellationToken", cancellationToken);
 03842                ServiceClientTracing.Enter(_invocationId, this, "ReadInStream", tracingParameters);
 3843            }
 3844            // Construct URL
 03845            var _baseUrl = BaseUri;
 03846            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "read/analyze";
 03847            _url = _url.Replace("{Endpoint}", Endpoint);
 03848            List<string> _queryParameters = new List<string>();
 03849            if (language != null)
 3850            {
 03851                _queryParameters.Add(string.Format("language={0}", System.Uri.EscapeDataString(language)));
 3852            }
 03853            if (_queryParameters.Count > 0)
 3854            {
 03855                _url += "?" + string.Join("&", _queryParameters);
 3856            }
 3857            // Create HTTP transport objects
 03858            var _httpRequest = new HttpRequestMessage();
 03859            HttpResponseMessage _httpResponse = null;
 03860            _httpRequest.Method = new HttpMethod("POST");
 03861            _httpRequest.RequestUri = new System.Uri(_url);
 3862            // Set Headers
 3863
 3864
 03865            if (customHeaders != null)
 3866            {
 03867                foreach(var _header in customHeaders)
 3868                {
 03869                    if (_httpRequest.Headers.Contains(_header.Key))
 3870                    {
 03871                        _httpRequest.Headers.Remove(_header.Key);
 3872                    }
 03873                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 3874                }
 3875            }
 3876
 3877            // Serialize Request
 03878            string _requestContent = null;
 03879            if(image == null)
 3880            {
 03881              throw new System.ArgumentNullException("image");
 3882            }
 03883            if (image != null && image != Stream.Null)
 3884            {
 03885                _httpRequest.Content = new StreamContent(image);
 03886                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 3887            }
 3888            // Set Credentials
 03889            if (Credentials != null)
 3890            {
 03891                cancellationToken.ThrowIfCancellationRequested();
 03892                await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 3893            }
 3894            // Send Request
 03895            if (_shouldTrace)
 3896            {
 03897                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 3898            }
 03899            cancellationToken.ThrowIfCancellationRequested();
 03900            _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 03901            if (_shouldTrace)
 3902            {
 03903                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 3904            }
 03905            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 03906            cancellationToken.ThrowIfCancellationRequested();
 03907            string _responseContent = null;
 03908            if ((int)_statusCode != 202)
 3909            {
 03910                var ex = new ComputerVisionErrorException(string.Format("Operation returned an invalid status code '{0}'
 3911                try
 3912                {
 03913                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 03914                    ComputerVisionError _errorBody =  SafeJsonConvert.DeserializeObject<ComputerVisionError>(_responseCo
 03915                    if (_errorBody != null)
 3916                    {
 03917                        ex.Body = _errorBody;
 3918                    }
 03919                }
 03920                catch (JsonException)
 3921                {
 3922                    // Ignore the exception
 03923                }
 03924                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 03925                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 03926                if (_shouldTrace)
 3927                {
 03928                    ServiceClientTracing.Error(_invocationId, ex);
 3929                }
 03930                _httpRequest.Dispose();
 03931                if (_httpResponse != null)
 3932                {
 03933                    _httpResponse.Dispose();
 3934                }
 03935                throw ex;
 3936            }
 3937            // Create Result
 03938            var _result = new HttpOperationHeaderResponse<ReadInStreamHeaders>();
 03939            _result.Request = _httpRequest;
 03940            _result.Response = _httpResponse;
 3941            try
 3942            {
 03943                _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<ReadInStreamHeaders>(JsonSerializer.Create(D
 03944            }
 03945            catch (JsonException ex)
 3946            {
 03947                _httpRequest.Dispose();
 03948                if (_httpResponse != null)
 3949                {
 03950                    _httpResponse.Dispose();
 3951                }
 03952                throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson().
 3953            }
 03954            if (_shouldTrace)
 3955            {
 03956                ServiceClientTracing.Exit(_invocationId, _result);
 3957            }
 03958            return _result;
 03959        }
 3960
 3961    }
 3962}