0

I'm trying to test sending a request to Document AI using .NET framework. I didn't see any info specific to .NET on the formal Google explanations for using client libraries. So far this is what I came up with:

public void Test()
{
    var documentProcessorServiceClient = new DocumentProcessorServiceClientBuilder
    {
        Endpoint = "us-documentai.googleapis.com"
    }.Build();

    ProcessRequest request = new ProcessRequest
    {
        SkipHumanReview = false,
        RawDocument = new RawDocument
        {
            MimeType = "application/pdf",
            Content = ByteString.CopyFrom(bytesArray); // bytesArray of some file
        }
    };

    try
    {
        ProcessResponse response = documentProcessorServiceClient.ProcessDocument(request);

        Document docResponse = response.Document;

        Console.WriteLine(docResponse.Text);
    }
    catch (Exception ex)
     {

        throw;
    }
}

My questions are:

  1. Why I always get the following exception: "Error starting gRPC call. HttpRequestException: Unable to get subchannel from HttpRequestMessage."

  2. How do I authenticate using a key instead of using OAuth2?

Thanks.

Successfully send the request with authentication.

burnsi
  • 6,194
  • 13
  • 17
  • 27
ornh
  • 1
  • 1
  • Please restrict your posts to *one* question per post. I'm currently trying to reproduce the problem in the first question - I suggest you edit your question to remove the second question (and the "Thanks"). In terms of documentation, see https://cloud.google.com/dotnet/docs/reference/help/getting-started for general client library help, and https://cloud.google.com/dotnet/docs/reference/Google.Cloud.DocumentAI.V1/latest for the API reference documentation for the DocumentAI client library. – Jon Skeet Jan 17 '23 at 12:02
  • Additionally, could you include which version of the library you're using, which version of .NET you're using, and what kind of authentication you're using for the default credentials? – Jon Skeet Jan 17 '23 at 12:07
  • I've just tried to reproduce this, and received an entirely different error that's due to the `Name` property not being set in the request. (It should be set to the processor name.) But it sounds like your request isn't getting through to the server, so we really need more contextual information. – Jon Skeet Jan 17 '23 at 12:11
  • There is also a pull request open to add a Quickstart example for Document AI in C# https://github.com/GoogleCloudPlatform/dotnet-docs-samples/pull/2019 – Holt Skinner Jan 27 '23 at 18:34

1 Answers1

0

This page in the documentation has been updated to include a Quickstart Sample for C#/.NET.

https://cloud.google.com/document-ai/docs/libraries#client-libraries-install-csharp

Here is the full API Documentation for C#

https://cloud.google.com/dotnet/docs/reference/Google.Cloud.DocumentAI.V1/latest

Holt Skinner
  • 1,692
  • 1
  • 8
  • 21