Azure / azure-sdk-for-net

This repository is for active development of the Azure SDK for .NET. For consumers of the SDK we recommend visiting our public developer docs at https://learn.microsoft.com/dotnet/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-net.
MIT License
5.47k stars 4.8k forks source link

[BUG][BingLocalSearch] Search method URL is malformed #10574

Closed fsharpn00b closed 2 years ago

fsharpn00b commented 4 years ago

Describe the bug https://github.com/Azure/azure-sdk-for-net/blob/6944bd8761b5d89e28d3e57f8261ae49971b7459/sdk/cognitiveservices/Search.BingLocalSearch/src/Generated/LocalSearch/Local.cs#L302 This appends "localbusinesses/v7.0/search" to the base URL. Per the docs, it should instead append "bing/v7.0/localbusinesses/search". When I call the search method, I get a 404. I am able to call the Search method as expected if I do the following.

  1. Clone the Azure SDK for .NET repo locally.
  2. Change the line in question to:
    var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "bing/v7.0/localbusinesses/search").ToString();
  3. Compile the BingLocalSearch solution.
  4. Edit the reference in my client project to point to the new Microsoft.Azure.CognitiveServices.Search.BingLocalSearch.dll I just created.

Expected behavior I am able to call the search method with base URI "https://api.cognitive.microsoft.com" and it works.

Actual behavior (include Exception or Stack Trace)

System.AggregateException
  HResult=0x80131500
  Message=One or more errors occurred.
  Source=mscorlib
  StackTrace:
   at System.Threading.Tasks.Task.WaitAll(Task[] tasks, Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at System.Threading.Tasks.Task.WaitAll(Task[] tasks, Int32 millisecondsTimeout)
   at System.Threading.Tasks.Task.WaitAll(Task[] tasks)
   at BingLocalCS.Program.Main(String[] args) in C:\Users\<user>\Documents\Quickstarts20190604\BingLocalCS\BingLocalCS\Program.cs:line 78

  This exception was originally thrown at this call stack:
    Microsoft.Azure.CognitiveServices.Search.LocalSearch.Local.SearchWithHttpMessagesAsync(string, string, string, string, string, string, string, string, string, string, string, string, string, string, System.Collections.Generic.IList<string>, string, string, System.Collections.Generic.Dictionary<string, System.Collections.Generic.List<string>>, System.Threading.CancellationToken)
    System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(System.Threading.Tasks.Task)
    System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task)
    Microsoft.Azure.CognitiveServices.Search.LocalSearch.LocalExtensions.SearchAsync(Microsoft.Azure.CognitiveServices.Search.LocalSearch.ILocal, string, string, string, string, string, string, string, string, string, string, string, string, string, string, System.Collections.Generic.IList<string>, string, string, System.Threading.CancellationToken)
    System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(System.Threading.Tasks.Task)
    System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task)
    System.Runtime.CompilerServices.TaskAwaiter<TResult>.GetResult()
    BingLocalCS.Program.RunQuickstart() in Program.cs

Inner Exception 1:
ErrorResponseException: Operation returned an invalid status code 'NotFound'

To Reproduce

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Azure.CognitiveServices.Search.LocalSearch;
using Microsoft.Azure.CognitiveServices.Search.LocalSearch.Models;

/*
 * To run this sample:
 * 1. Install the following NuGet packages.
 * - Microsoft.Azure.CognitiveServices.Search.LocalSearch
 * Notes:
 * - Be sure to enable prerelease packages.
 * - Be sure to update all installed packages to their latest versions.
 * 2. Create environment variables BING_LOCAL_SUBSCRIPTION_KEY and
 * BING_LOCAL_ENDPOINT. You might need to restart your development
 * environment after creating these variables for them to take effect.
 */

namespace BingLocalCS
{
    class Program
    {
        private const string key_var = "BING_LOCAL_SUBSCRIPTION_KEY";
        private static readonly string subscription_key = Environment.GetEnvironmentVariable(key_var);

        // Note you must use the same region as you used to get your subscription key.
        private const string endpoint_var = "BING_LOCAL_ENDPOINT";
        //        private static readonly string endpoint = Environment.GetEnvironmentVariable(endpoint_var);
        private static readonly string endpoint = "https://api.cognitive.microsoft.com";

        static Program()
        {
            if (null == subscription_key)
            {
                throw new Exception("Please set/export the environment variable: " + key_var);
            }
            if (null == endpoint)
            {
                throw new Exception("Please set/export the environment variable: " + endpoint_var);
            }
        }

        async static Task RunQuickstart()
        {
            // Generate the credentials and create the client.
            var credentials = new Microsoft.Azure.CognitiveServices.Search.LocalSearch.ApiKeyServiceClientCredentials(subscription_key);
            var client = new LocalSearchClient(new Uri(endpoint), credentials, new System.Net.Http.DelegatingHandler[] { });

            var result = await client.Local.SearchAsync("party");
        }

        static void Main(string[] args)
        {
            Task.WaitAll(RunQuickstart());
            Console.WriteLine("Press any key to exit.");
            Console.Read();
        }
    }
}

Environment:

ghost commented 4 years ago

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @dfulcer.

SaurabhSharma-MSFT commented 3 years ago

@fsharpn00b Apologies for the delayed response. I see that this issue is opened long time ago and no further activity had taken place. So wanted to check if you are still looking for assistance on this query? Please let us know .

SaurabhSharma-MSFT commented 3 years ago

@fsharpn00b Following up again to know if you still need help on this issue.

ghost commented 3 years ago

Hi, we're sending this friendly reminder because we haven't heard back from you in 7 days. We need more information about this issue to help address it. Please be sure to give us your input. If we don't hear back from you within 14 days of this comment the issue will be automatically closed. Thank you!