Botframework-sdk: "An error occurred while sending the request" from emulator

Created on 8 Jun 2016  路  16Comments  路  Source: microsoft/botframework-sdk

Is there a problem with Microsoft.Bot.builder v1.2.3?

I did the following:

  • installed VS2015 Community Edition
  • installed Microsoft Bot Emulator
  • downloaded and installed the template for bots
  • Created a new project based on the bot template
  • Updated the Bot.Connector
  • Copied and pasted the full example of the alarm bot to MessageController.cs

At that, trying to build fails. If I install the bot.builder v1.2.3, it builds, and I get the webpage:

Describe your bot here and your terms of use etc.

Visit Bot Framework to register your bot. When you register it, remember to set your bot's endpoint to 
https://your_bots_hostname/api/messages

I cannot connect though. I connect the emulator to either https://localhost/api/messages or http://localhost/api/messages, but both give me the error above.

The JSON in the window after the emulator returns "an error occurred while sending the request" is

System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it 127.0.0.1:443
   at System.Net.Sockets.Socket.EndConnect(IAsyncResult asyncResult)
   at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception)
   --- End of inner exception stack trace ---
   at System.Net.HttpWebRequest.EndGetRequestStream(IAsyncResult asyncResult, TransportContext& context)
   at System.Net.Http.HttpClientHandler.GetRequestStreamCallback(IAsyncResult ar)
   --- End of inner exception stack trace ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
   at Microsoft.Bot.Connector.Emulator.ConversationModel.<SendMessageAsync>d__50.MoveNext()

Most helpful comment

Argh, this was totally my fault. I added the ability to change the port and inadvertently pushed a version which never started the service! I will have a new build pushed out within an our (as soon as I can get the binaries signed.)

The good news is that I have added the ability for people to change port, and I also detect the corrupted file problem and robustly handle that.

I am sooo sorry for wasting your time on this...If I could I would buy you a beer to make up for it!

All 16 comments

I don't remember the default port number the project template uses (3978 or 3798) but it does use one. Can you check if your project is using a port number and update the url in the emulator to match it?

Thanks for the fast reply. So on https://localhost:3978/api/messages, I get the same error "An error occurred while sending the request.", but a different underlying reason. The JSON data is:

System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a send. ---> System.IO.IOException: The handshake failed due to an unexpected packet format.
   at System.Net.TlsStream.EndWrite(IAsyncResult asyncResult)
   at System.Net.PooledStream.EndWrite(IAsyncResult asyncResult)
   at System.Net.ConnectStream.WriteHeadersCallback(IAsyncResult ar)
   --- End of inner exception stack trace ---
   at System.Net.HttpWebRequest.EndGetRequestStream(IAsyncResult asyncResult, TransportContext& context)
   at System.Net.Http.HttpClientHandler.GetRequestStreamCallback(IAsyncResult ar)
   --- End of inner exception stack trace ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
   at Microsoft.Bot.Connector.Emulator.ConversationModel.<SendMessageAsync>d__50.MoveNext()

So that is a different error at least!

Can you use http instead of https?

I did try that as well, it just gives a "404 Not Found", and

``````
{
"message": "No HTTP resource was found that matches the request URI 'http://localhost:3978/api/messages'.",
"messageDetail": "No type was found that matches the controller named 'messages'."

```}
``````

I think https://localhost:3978/api/messages is the right URL - is there something else running on the port?

No, definitely not being used by anything else. If I run netstat -a before, there is nothing listed on that port. When I start the application from VS, I can see 3978 listed as listening.

By the way, if I just choose to create a brand new bot project, and click to build, I can connect with the emulator on http://localhost:3978/api/messages (HTTP not HTTPS). If I send "adsadsa", I get 2You sent 7 characters" back, so that works.
If I then go to the NuGet Package Manager, update "Microsoft.Bot.Connector" from 1.0 to 1.1, comment out the utilities, build, it still works, and I can connect from the emulator.
If I go back to the NuGet Package Manager, install "Microsoft.Bot.Builder" from 1.2.3, build, it still works, and I can connect from the emulator.
if I cut and paste the sample code form the alarm bot (the full example, link at the top), I get the original error. So is problem with the LUIS interface? Has there been changes that stop that working in the same way (as that is a major difference between the supplied code in the project template, and the alarm bot sample)?

Same here, also in combination with LUIS. The problem seems to be in the connector back to the emulator, stacktrace reveals this inner exception:

No connection could be made because the target machine actively refused it 127.0.0.1:9000

Could maybe not be the bot framework, but the emulator instead. But I have no clue on how to revert back to a previous version since that comes from online?

Having the same problem here all of the sudden. Code that was working before the emulator update now fails with a message similar to the issue reported above. "No connection could be made because the target machine actively refused it 127.0.0.1:9000". I rolled the emulator back to 1.0.0.66 through Control Panel, Programs and Features and the issue no longer occurs.

wjvii, were using LUIS in your code too? My emulator is 1.0.0.66.

The same happed to me as @wjvii and @jsiegmund described well. All code was working, but while coding after updating the emulator, THEN code stop working.
The error is "No connection could be made because the target machine actively refused it 127.0.0.1:9000" as mentioned by other guys.
I tried to figure out the root of this bug, to do so I removed below code from StartAsync function, and it get back to work! (but my bot has no job to do anymore!):
await context.PostAsync("welcome")

I guess there is a problem with start talking to the client at the first place.
Here is the code:

[Serializable] public class GreetingDialog : IDialog<Message> { public async Task StartAsync(IDialogContext context) { await context.PostAsync("welcome!"); // <<< this line of code produce the error context.Wait(MessageReceivedAsync); } }

I can't roll back the emulator to it previous version, because I reinstall it! and this time this option is not available anymore (please find attached image for your reference).
emulator

Argh, this was totally my fault. I added the ability to change the port and inadvertently pushed a version which never started the service! I will have a new build pushed out within an our (as soon as I can get the binaries signed.)

The good news is that I have added the ability for people to change port, and I also detect the corrupted file problem and robustly handle that.

I am sooo sorry for wasting your time on this...If I could I would buy you a beer to make up for it!

Thanks Tomlm, sounds promising. Which component should I be looking out for?

V70 was just published and fixes this issue.

I hate to say this, but I think there are different issues here. I have updated the emulator to 1.0.0.70, but I still get the error in my initial post on https://localhost:3978/api/messages, and the 404 on http://localhost:3978/api/messages when using the Alarm Bot sample, as detailed in my first post.

My issues was fixed by @tomlm 's push. Thanks for that!

Simply restart or close your IIS express from the right bottom corner. This will close the running application and then you can run your bot.

Was this page helpful?
0 / 5 - 0 ratings