TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Ms_ Dev
NA
236
93.3k
Getting this Error on BOT EMULATION
Mar 2 2017 2:16 AM
Hi,
I am tring to simulate a bot with Microsoft Bot Emulator. I am getting this error.
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:3978
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.
d__50.MoveNext()
The codebase is -
[BotAuthentication]
public
class
MessagesController : ApiController
{
///
/// POST: api/Messages
/// Receive a message from a user and reply to it
///
public
async Task
Post([FromBody]Activity activity)
{
if
(activity.Type ==
"Message"
)
{
//ConnectorClient connector = new ConnectorClient(new Uri(activity.ServiceUrl));
// calculate something for us to return
//int length = (activity.Text ?? string.Empty).Length;
// return our reply to the user
//Activity reply = activity.CreateReply($"You sent {activity.Text} which was {length} characters");
//await connector.Conversations.ReplyToActivityAsync(reply);
string
StockRateString;
StockLUIS StLUIS = await GetEntityFromLUIS(activity.Text);
if
(StLUIS.intents.Count() > 0)
{
switch
(StLUIS.intents[0].intent)
{
case
"StockPrice"
:
StockRateString = await GetStock(StLUIS.entities[0].entity);
break
;
case
"StockPrice2"
:
StockRateString = await GetStock(StLUIS.entities[0].entity);
break
;
default
:
StockRateString =
"Sorry, I am not getting you..."
;
break
;
}
}
else
{
StockRateString =
"Sorry, I am not getting you..."
;
}
//return activity.CreateReply(StockRateString);
}
else
{
HandleSystemMessage(activity);
}
var response = Request.CreateResponse(HttpStatusCode.OK);
return
response;
}
private
Activity HandleSystemMessage(Activity message)
{
if
(message.Type == ActivityTypes.DeleteUserData)
{
// Implement user deletion here
// If we handle user deletion, return a real message
}
else
if
(message.Type == ActivityTypes.ConversationUpdate)
{
// Handle conversation state changes, like members being added and removed
// Use Activity.MembersAdded and Activity.MembersRemoved and Activity.Action for info
// Not available in all channels
}
else
if
(message.Type == ActivityTypes.ContactRelationUpdate)
{
// Handle add/remove from contact lists
// Activity.From + Activity.Action represent what happened
}
else
if
(message.Type == ActivityTypes.Typing)
{
// Handle knowing tha the user is typing
}
else
if
(message.Type == ActivityTypes.Ping)
{
}
return
null
;
}
private
async Task<
string
> GetStock(
string
StockSymbol)
{
double
? dblStockValue = await StockBot.GetStockRateAsync(StockSymbol);
if
(dblStockValue ==
null
)
{
return
string
.Format(
"This \"{0}\" is not a valid Stock Symbol"
, StockSymbol);
}
else
{
return
string
.Format(
"Stock price of {0} is {1}"
, StockSymbol, dblStockValue);
}
}
private
static
async Task
GetEntityFromLUIS(
string
Query)
{
Query = Uri.EscapeDataString(Query);
StockLUIS Data =
new
StockLUIS();
using
(HttpClient client =
new
HttpClient())
{
client.DefaultRequestHeaders.ExpectContinue =
false
;
string
RequestURI =
"https://westus.api.cognitive.microsoft.com/luis/v2.0/apps/27e3147e-21c9-4a11-ae26-3ea3a1dbf421?subscription-key=bb0397455aa54d9ca92c3f3f097420b9&q="
+ Query;
HttpResponseMessage msg = await client.GetAsync(RequestURI);
if
(msg.IsSuccessStatusCode)
{
var JsonDataResponse = await msg.Content.ReadAsStringAsync();
Data = JsonConvert.DeserializeObject
(JsonDataResponse);
}
}
return
Data;
}
}
Reply
Answers (
1
)
voice recognition using raspberry pi
Any thing related to Programming and IOT