0

I've connected my bot application to the direct line API which is published with Azure. I am currently testing the application with a command line client application, the bot framework emulator, and the dev.botframework.com homepage for my bot.

Everything works correctly until I attempt to submit a GET request to a REST API. I've tested the GET API request in a separate project and it works correctly and the GET request worked prior to implementing the direct line channel. Is there anything I need to be aware of when making http requests with the direct line on the bot side?

Code in question

using (var client = new HttpClient())
            {
                client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", headerParam);
                var response = client.GetAsync(new Uri("someUrl.com/api/v1/auth")).Result;
                string content = response.Content.ReadAsStringAsync().Result;
                var jo = JObject.Parse(content);
                this.token = jo["Result"]["Token"].ToString();
            }
            await context.PostAsync(this.token);

the line that actually causes the failure is

var response = client.GetAsync(new Uri("someUrl.com/api/v1/auth")).Result;

Also is there an easier way to debug a project when it's published to azure and running direct line API?

Teragon
  • 239
  • 3
  • 13
  • Do you mean that you have deployed a webapi application to Azure which provides the custom endpoints that invoke [Direct Line REST API](https://docs.botframework.com/en-us/restapi/directline/) ? Have you tried to use [Fiddler](http://www.telerik.com/fiddler) for capturing network package on your client application, or leverage [remote debugging](https://docs.microsoft.com/en-us/azure/app-service-web/web-sites-dotnet-troubleshoot-visual-studio#a-nameremotedebugaremote-debugging-web-apps) for your .NET web application on web apps. Also, what is the detailed error message and stacktrace? – Bruce Chen Apr 10 '17 at 04:10
  • It's a bot application from MSFT's bot framework deployed to Azure. Using my client application I can send messages to talk to the "smart bot" through direct line REST API. The problem is sending a message "login with account x" the bot application then creates an httpClient to authenticate to my own REST API. Problem is calling `var response = client.GetAsync(new Uri("someUrl.com/api/v1/auth")).Result;` results in "POST request to "botendpointurl.com" failed [500] internal server error for the client application. I can't see what the state of the bot application is since its running on azure. – Teragon Apr 11 '17 at 22:49
  • Do you mean you reference bot application sample and deploy to azure web app, if so, could you provide the sample link? Per my understanding, you make a request with user info against your bot application (web app back-end) , then make a request to your custom rest api via basic authentication. Since you located the code line, you could wrap your code with `try-catch` to capture the detailed error message (inner exception, stack trace) and output to your client application, or refer to **remote debugging** link in my prior comment for debugging your bot application hosted on Azure web app. – Bruce Chen Apr 12 '17 at 10:10
  • Thanks for the help. So I've found through try-catch that the error received is `System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: An attempt was made to access a socket in a way forbidden by its access permissions ipaddress` I'm able to make the exact same call and it works in a command line program so I'm not sure how the bot framework is causing a failure – Teragon Apr 15 '17 at 01:12

1 Answers1

0

System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: An attempt was made to access a socket in a way forbidden by its access permissions ipaddress

I have tried to invoke my custom REST API within my bot application back-end, then I could leverage Remote debugging web apps to retrieve the result from my bot application hosted on Azure web app as follows:

enter image description here

After searching for the related issue, I found that there be limitation for the number of sockets of your current app service plan when creating the new outgoing connections. You could try to scale up your App Service plan or create a new web app to isolate this issue. For more details, you could refer to this similar issue and this blog.

Community
  • 1
  • 1
Bruce Chen
  • 18,207
  • 2
  • 21
  • 35