POST IIS 托管 Bot 的 500 错误 Bot Emulator Localhost

POST 500 Error Bot Emulator Localhost for IIS hosted Bot

我已经使用 IIS 在本地托管我的机器人,如下所示:https: //localhost/MyBot。目前,当我尝试在机器人模拟器中连接到我的机器人时,出现 POST 500 错误,并且无法发送消息。我对此很陌生,大多数用于将机器人发布到本地服务器的文档都是有限的。但是我可以从我的浏览器成功打开这个link。

我遇到此错误是因为我没有 https: //localhost/Bridget/api/messages directory/url 吗?我尝试在 IIS 中创建虚拟目录,但这无助于解决我的问题。我需要隧道软件吗?是否有使用 IIS 在本地部署机器人并通过机器人模拟器连接到它的简单教程?

这是我在模拟器中看到的错误:

Bot Emulator Error

使用 ngrok 隧道软件,这是我看到的:

NGROK Bot Emulator Error

这是处理传入 POST 消息的代码:

/// <summary>
/// POST: api/Messages
/// Receive a message from a user and reply to it
/// </summary>
public async Task<HttpResponseMessage> Post([FromBody]Activity activity)
{
    if (activity.Type == ActivityTypes.Message)
    {
        // Strip any @mentions
        Mention[] m = activity.GetMentions();
        for (int x = 0; x < m.Length; x++)
        {
            if (m[x].Mentioned.Id == activity.Recipient.Id)
            {
                if (m[x].Text != null)
                {
                    activity.Text = activity.Text.Replace(m[x].Text, "");
                }
            }
        }

        await stateClient.BotState.SetUserDataAsync(activity.ChannelId, activity.From.Id, userData);

        await Conversation.SendAsync(activity, () => new Dialogs.RootDialog());
    }
    else if (activity.Type == ActivityTypes.Invoke)
    {
            // Some Code...
    }
    else
    {
        HandleSystemMessage(activity);
    }
    var response = Request.CreateResponse(HttpStatusCode.OK);
    return response;
}

Am I experiencing this error because I don't have the https: //localhost/Bridget/api/messages directory/url?

你的两个屏幕截图都显示你试图连接到 /api/messages,但你说你没有,所以自然会出现错误。

请 post 您的 bot 代码部分显示您正在收听消息的位置。例如,一个 NodeJS 机器人会像这样:

var server = restify.createServer();
server.listen(process.env.port || process.env.PORT || 3978, () => {
    console.log('%s listening to %s', server.name, server.url); 
});

var connector = new builder.ChatConnector({
    appId: process.env.MICROSOFT_APP_ID,
    appPassword: process.env.MICROSOFT_APP_PASSWORD
});
var bot = new builder.UniversalBot(connector);
server.post('/api/messages', connector.listen());

最后一行显示了在当前应用程序中 /api/messages 处的连接侦听消息(NodeJS 使用 restify 库 运行)。你有什么?

我解决了这个问题,这是因为 IIS 不允许 POST 请求。我所做的只是转到请求过滤并添加动词 POST:

IIS POST Fix