---
title: "Common code to open and close DocumentConverterServiceClient | Nutrient Document Converter Services"
canonical_url: "https://www.nutrient.io/guides/document-converter/document-converter-services/knowledge-base/open-and-close-documentconverterserviceclient/"
md_url: "https://www.nutrient.io/guides/document-converter/document-converter-services/knowledge-base/open-and-close-documentconverterserviceclient.md"
last_updated: "2026-05-30T02:20:01.197Z"
description: "Learn how to open and close DocumentConverterServiceClient in Nutrient Document Converter Services (DCS), including configuration of bindings, timeouts, and endpoint settings for secure communication."
---

# Common code to open and close DocumentConverterServiceClient

Below is the common code used to open and close a `DocumentConverterServiceClient`:

```csharp

        /// <summary>
        /// Configure the bindings and endpoints and open the service using the specified address.
        /// </summary>
        /// <param name="address">URL of the endpoint.</param>
        /// <returns>An instance of the web service.</returns>
        public static DocumentConverterServiceClient OpenService(string address)
        {
            DocumentConverterServiceClient client = null;
            try
            {
                BasicHttpBinding binding = new BasicHttpBinding();
                // Use standard Windows security.
                binding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
                binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows;

                // Increase the client timeout to deal with (very) long running requests.
                binding.SendTimeout = TimeSpan.FromMinutes(120);
                binding.ReceiveTimeout = TimeSpan.FromMinutes(120);
                // Set the maximum document size to 50MB.
                binding.MaxReceivedMessageSize = 50 * 1024 * 1024;
                binding.ReaderQuotas.MaxArrayLength = 50 * 1024 * 1024;
                binding.ReaderQuotas.MaxStringContentLength = 50 * 1024 * 1024;
                EndpointAddress epa = new EndpointAddress(new Uri(address));
                client = new DocumentConverterServiceClient(binding, epa);
                client.OpenAsync();
                return client;
            }
            catch (Exception)
            {
                CloseService(client);
                throw;
            }

        }
        /// <summary>
        /// Check if the client is open and then close it.
        /// </summary>
        /// <param name="client">The client to close.</param>
        public static void CloseService(DocumentConverterServiceClient client)
        {
            if (client!= null && client.State == CommunicationState.Opened)
                client.CloseAsync().GetAwaiter().GetResult();
        }

```

---

## Related pages

- [How to make HTML-to-PDF conversion more secure?](/guides/document-converter/document-converter-services/knowledge-base/make-html-to-pdf-conversion-more-secure.md)
- [How does Document Converter handle InfoPath attachments?](/guides/document-converter/document-converter-services/knowledge-base/how-does-the-pdf-converter-deal-with-infopath-attachments.md)
- [How to use GdPicture in your code?](/guides/document-converter/document-converter-services/knowledge-base/how-to-use-gdpicture-from-the-code.md)
- [How to specify which InfoPath view to convert from your code?](/guides/document-converter/document-converter-services/knowledge-base/how-can-i-specify-which-infopath-view-to-convert-from-my-own-code.md)
- [Using Document Converter from PowerShell](/guides/document-converter/document-converter-services/knowledge-base/using-the-pdf-converter-from-powershell.md)
- [How does the Conversion Service handle concurrency and how can it be adjusted?](/guides/document-converter/document-converter-services/knowledge-base/how-does-the-conversion-service-deal-with-concurrency-and-how-to-tweak-it.md)
- [Do you have sample code for KVP Extraction functionality?](/guides/document-converter/document-converter-services/knowledge-base/sample-code-for-kvp-extraction.md)
- [Do you have sample code for Text Extraction functionality?](/guides/document-converter/document-converter-services/knowledge-base/sample-code-for-text-extraction.md)
- [Knowledge base: SharePoint Document Converter](/guides/document-converter/document-converter-services/knowledge-base.md)

