microsoft / BotFramework-DirectLine-DotNet

C# client library for Microsoft Bot Framework's Direct Line protocol
MIT License
27 stars 38 forks source link

.NET Client to Connect to Direct Line App Service extension results in 403 exception #38

Open breakingram opened 1 year ago

breakingram commented 1 year ago

Version

What package version of the SDK are you using. Microsoft.Bot.Builder.Integration.AspNet.Core:4.21.0

Describe the bug

After creating a .NET Client to Connect to Direct Line App Service extension, a 403 error is thrown. Documentation for creating DLASE Client in .NET: https://learn.microsoft.com/en-us/azure/bot-service/bot-service-channel-directline-extension-net-client?view=azure-bot-service-4.0

To Reproduce

Steps to reproduce the behavior:

  1. Configure a .NET bot for Direct Line App Service extension from this documentation a. Important: Please make sure to include MicrosoftAppTenantId in app service configuration after deployment
  2. Create .NET Client to Connect to Direct Line App Service extension, by following this documentation 
  3. Cloned the BotFramework-DirectLine-DotNet project locally. Do not use NuGet or any external third-party package manager for this BotFramework-DirectLine-DotNet library. Once cloned, add a project reference from your C# client app to the BotFramework-DirectLine-DotNet project.
  4. Run the .NET DLASE Client and observe the error

Expected behavior

Run .NET Client to Connect to Direct Line App Service extension without errors.

Error details

System.AggregateException: "One or more errors occurred. (The server returned status code '403' when status code '101' was expected.)" ---> System.Net.WebSockets.WebSocketException: "The server returned status code '403' when status code '101' was expected." at System.Net.WebSockets.WebSocketHandle.d13.MoveNext()\n at System.Net.WebSockets.ClientWebSocket.d15.MoveNext()\n at Microsoft.Bot.Streaming.Transport.WebSockets.WebSocketClient.d21.MoveNext()\n at Microsoft.Bot.Streaming.Transport.WebSockets.WebSocketClient.d20.MoveNext()\n at Microsoft.Bot.Connector.DirectLine.StreamingConversations.d15.MoveNext() in /Users/ram/Documents/bot/BF/directline_bots/Csharp/CSharpDLASEClient/BotFramework-DirectLine-DotNet/libraries/Streaming/StreamingConversations.cs:line 77\n at CustomerDLASE_ConsoleApp.DirectLineInterface.d7.MoveNext() in /Users/ram/Documents/bot/BF/directline_bots/Csharp/CSharpDLASEClient/CustomerDLASE_ConsoleApp/Directline.cs:69 --- End of inner exception stack trace --- at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)\n at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)\n at System.Threading.Tasks.Task.Wait()\n at Program.

$(String[] args) in /Users/ram/Documents/bot/BF/directline_bots/Csharp/CSharpDLASEClient/CustomerDLASE_ConsoleApp/Program.cs:24

[bug]

sw-joelmut commented 1 year ago

Hi @ramfattah,

We were able to reproduce the issue with the provided information. Analyzing why the HTTP 403 error happens in the DLASE Client, we proceed to investigate about how it's created and configured, by following the provided guide in this issue. We noticed there was a misconfiguration when instantiating the DirectLineClient (step 5 of the guide), causing this error. imagen

Additionally, after fixing the 403 error, an HTTP 502 error appeared, it was due to a misconfiguration in the UseNamedPipes method in the bot. When using MultiTenant, this is not required. For SingleTenant the audience could be the TenantId as shown in the following image. imagen

Thanks, Joel

breakingram commented 1 year ago

Thank you for you effort in solving this issue @sw-joelmut.

Indeed fixing the misconfigurations helped solved the problem from my end aswell. image

Much appreciated, @sw-joelmut. Informing the customer now.