Getting MethodNotAllowed exception in Bot Framework
I have registered basic echo microsoft bot template into Azure portal but I am getting following error "Operation returned an invalid status code ‘MethodNotAllowed" in the response.
Note: Same piece of code is working fine in local and old registered bots into azure portal. But facing above issue with newly registered Bot and i have verified messaging endpoints, app id and credentials etc.
Has anyone run into the same problem?
I am also facing the same issue, same bot is working in local but deployed to azure it is not working.
.Net - 4.6 Bot Framework- 3.14.1.1 MicrosoftAppId - 2f045ac3-8714-4b9b-8703-effcae78d92e Channel - WebChat ConversationId - 7d9ce26f24c246cc9bca7d70daeaa5b0 -UTC timestamp Wed 08/01/2018 20:32:09.37 UTC
Here is my MessageController
`
[BotAuthentication]
public class MessagesController : ApiController
{
public async Task<HttpResponseMessage> Post([FromBody]Activity activity)
{
if (activity.Type == ActivityTypes.Message)
{
await Conversation.SendAsync(activity, () => new Dialogs.RootDialog());
}
else
{
await HandleSystemMessage(activity);
}
var response = Request.CreateResponse(HttpStatusCode.OK);
return response;
}`
and here is my RootDialog
`
[Serializable]
public class RootDialog : IDialog<object>
{
public Task StartAsync(IDialogContext context)
{
context.Wait(MessageReceivedAsync);
}
private async Task MessageReceivedAsync(IDialogContext context, IAwaitable<object> result)
{
await result;
List<string> lstHomeOptions = new List<string>();
lstHomeOptions.Add("Drone");
lstHomeOptions.Add("Computers");
lstHomeOptions.Add("Other");
PromptDialog.Choice(context, onHomeOptionSelected, lstHomeOptions, "Please choose an option", "Not a valid option, try again", 3);
}`
@fj4870 Was this a node bot or .net bot? Is it a Web App bot, or an Azure Functions bot? Did you create the bot in the portal, and it immediately did not respond? Or, did you make any modifications to it?
@bhasker412 It looks like your bot is using the default state service, which has been retired. Please implement a custom state service, or use one of the Azure Extensions. More information can be found here: https://blog.botframework.com/2017/12/19/bot-state-service-will-soon-retired-march-31st-2018/
@EricDahlvang It's an .net web App bot. Yes yesterday I have created 3 Bot's but always I am getting same error. No I haven't made any modifications and please note same piece of code works fine with the Bot which i have registered 2 weeks back. I am facing above issue with new bots so i suspect might be something wrong at microsoft end.
I just created a new basic .net web app bot on Azure, and tested it in Web Chat without issue. What data center are you creating the bot in? Can you share the code you're using?
I am pointing to Central US and using basic echo bot template from microsoft given below
MessageController
[BotAuthentication]
public class MessagesController : ApiController
{
///
RootDialog
[Serializable] public class RootDialog : IDialog
return Task.CompletedTask;
}
private async Task MessageReceivedAsync(IDialogContext context, IAwaitable<object> result)
{
var activity = await result as Activity;
// calculate something for us to return
int length = (activity.Text ?? string.Empty).Length;
// return our reply to the user
await context.PostAsync($"You sent {activity.Text} which was {length} characters");
context.Wait(MessageReceivedAsync);
}
}
Global.asax
protected void Application_Start() { GlobalConfiguration.Configure(WebApiConfig.Register); }
@fj4870 Are you on a trial, or paid azure subscription?
Please share the BotHandle and MicrosoftAppId for the bot.
@EricDahlvang I am still facing the same issue even after migrating. I deleted existing app and created new web app bot in azure. I update the bot framework to 3.15.3 and tested in local it is working fine and deployed the same code to azure it dint.
.Net - 4.6 Bot Framework- 3.15.3 MicrosoftAppId - 2f2d259f-897d-411e-9d9a-35f2d67a2f60 Channel - WebChat ConversationId - 25e43e8911544b1d9f2afa72939eaed7 -UTC timestamp - 2018-08-12T17:45:42.4132176Z

@bhasker412 Is your bot using a custom state client? The default state service has been deprecated: https://blog.botframework.com/2017/12/19/bot-state-service-will-soon-retired-march-31st-2018/
@EricDahlvang I haven't explicitly configured any custom state client in my app. Do i need to change it any where in my app? i just created the app using bot template and using.
@bhasker412 Depending on which client side bot template you used to create the bot, yes... you might need to manually add a custom state client. This code adds an in memory state client:
Conversation.UpdateContainer(
builder =>
{
builder.RegisterModule(new AzureModule(Assembly.GetExecutingAssembly()));
// Bot Storage: Here we register the state storage for your bot.
// Default store: volatile in-memory store - Only for prototyping!
// We provide adapters for Azure Table, CosmosDb, SQL Azure, or you can implement your own!
// For samples and documentation, see: https://github.com/Microsoft/BotBuilder-Azure
var store = new InMemoryDataStore();
// Other storage options
// var store = new TableBotDataStore("...DataStorageConnectionString..."); // requires Microsoft.BotBuilder.Azure Nuget package
// var store = new DocumentDbBotDataStore("cosmos db uri", "cosmos db key"); // requires Microsoft.BotBuilder.Azure Nuget package
builder.Register(c => store)
.Keyed<IBotDataStore<BotData>>(AzureModule.Key_DataStore)
.AsSelf()
.SingleInstance();
});
reference: https://github.com/Microsoft/BotBuilder-Samples/blob/master/CSharp/cards-CarouselCards/Global.asax.cs
@EricDahlvang below files are of my application which is running in local(BOT Emulator) not on Azure Web App BOT. I followed the cards-CarouselsCards Sample you provided but no luck.
Below is my global.asax.cs `
public class WebApiApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
Conversation.UpdateContainer(builder =>
{
builder.RegisterModule(new AzureModule(Assembly.GetExecutingAssembly()));
// var store = new TableBotDataStore(ConfigurationManager.AppSettings["BotStateEndpoint"]);
var store = new InMemoryDataStore();
builder.Register(c => store)
.Keyed<IBotDataStore<BotData>>(AzureModule.Key_DataStore)
.AsSelf()
.SingleInstance();
//builder.Register(c => new CachingBotDataStore(store,
// CachingBotDataStoreConsistencyPolicy
// .ETagBasedConsistency))
// .As<IBotDataStore<BotData>>()
// .AsSelf()
// .InstancePerLifetimeScope();
});
GlobalConfiguration.Configure(WebApiConfig.Register);
}
}
`
Below is my MessageController `
[BotAuthentication]
public class MessagesController : ApiController
{
/// <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)
{
await Conversation.SendAsync(activity, () => new Dialogs.RootDialog());
}
else
{
await HandleSystemMessage(activity);
}
var response = Request.CreateResponse(HttpStatusCode.OK);
return response;
}
private async Task HandleSystemMessage(Activity message)
{
switch (message.Type)
{
case ActivityTypes.DeleteUserData:
// Implement user deletion here
// If we handle user deletion, return a real message
break;
case 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
if (message.MembersAdded.Any(m => m.Id == message.Recipient.Id))
{
ConnectorClient connector = new ConnectorClient(new Uri(message.ServiceUrl));
var welcomeMsg = message.CreateReply("Welcome to the Bot...!");
await connector.Conversations.ReplyToActivityAsync(welcomeMsg);
}
break;
case ActivityTypes.ContactRelationUpdate:
// Handle add/remove from contact lists
// Activity.From + Activity.Action represent what happened
break;
case ActivityTypes.Typing:
// Handle knowing tha the user is typing
break;
case ActivityTypes.Ping:
break;
}
}
}
Below is my RootDialog `
[Serializable]
public class RootDialog : IDialog<object>
{
public Task StartAsync(IDialogContext context)
{
context.Wait(MessageReceivedAsync);
return Task.CompletedTask;
}
private async Task MessageReceivedAsync(IDialogContext context, IAwaitable<object> result)
{
await result;
List<string> lstHomeOptions = new List<string>();
lstHomeOptions.Add("Drone");
lstHomeOptions.Add("Computers");
lstHomeOptions.Add("Other");
PromptDialog.Choice(context, onHomeOptionSelected, lstHomeOptions, "Please choose an option", "Not a valid option, try again", 3);
}
private async Task onHomeOptionSelected(IDialogContext context, IAwaitable<string> result)
{
string selectedOption = await result;
switch (selectedOption)
{
case "Drone":
context.Call(new DroneDialog(), onResumeDroneDialog);
break;
case "Computers":
case "Other":
default:
await context.SayAsync("This feature is under development");
await MessageReceivedAsync(context, result);
break;
}
}
private async Task onResumeDroneDialog(IDialogContext context, IAwaitable<object> result)
{
await MessageReceivedAsync(context, result);
}
}
Snapshot of working BOT emulator

Same code deployed to azure but not working

Below are the appSettings added automatically to my bot web app

Enabled remote debugging on azure and got below exception for the message i sent to bot.

Exception details
Autofac.Core.DependencyResolutionException occurred
HResult=0x80131500
Message=An error occurred during the activation of a particular registration. See the inner exception for details. Registration: Activator = IPostToBot (DelegateActivator), Services = [Microsoft.Bot.Builder.Dialogs.Internals.IPostToBot], Lifetime = Autofac.Core.Lifetime.CurrentScopeLifetime, Sharing = Shared, Ownership = OwnedByLifetimeScope
Source=
Inner Exception 1: DependencyResolutionException: An error occurred during the activation of a particular registration. See the inner exception for details. Registration: Activator = QueueDrainingDialogTask (ReflectionActivator), Services = [Microsoft.Bot.Builder.Dialogs.Internals.QueueDrainingDialogTask (Microsoft.Bot.Builder.Dialogs.Internals.IPostToBot)], Lifetime = Autofac.Core.Lifetime.CurrentScopeLifetime, Sharing = Shared, Ownership = OwnedByLifetimeScope
Inner Exception 2: DependencyResolutionException: An error occurred during the activation of a particular registration. See the inner exception for details. Registration: Activator = IBotToUser (DelegateActivator), Services = [Microsoft.Bot.Builder.Dialogs.Internals.IBotToUser], Lifetime = Autofac.Core.Lifetime.CurrentScopeLifetime, Sharing = Shared, Ownership = OwnedByLifetimeScope
Inner Exception 3: DependencyResolutionException: An error occurred during the activation of a particular registration. See the inner exception for details. Registration: Activator = AlwaysSendDirect_BotToUser (ReflectionActivator), Services = [Microsoft.Bot.Builder.Dialogs.Internals.AlwaysSendDirect_BotToUser (Microsoft.Bot.Builder.Dialogs.Internals.IBotToUser), Microsoft.Bot.Builder.Dialogs.Internals.AlwaysSendDirect_BotToUser], Lifetime = Autofac.Core.Lifetime.CurrentScopeLifetime, Sharing = Shared, Ownership = OwnedByLifetimeScope
Inner Exception 4: DependencyResolutionException: An error occurred during the activation of a particular registration. See the inner exception for details. Registration: Activator = IConnectorClient (DelegateActivator), Services = [Microsoft.Bot.Connector.IConnectorClient], Lifetime = Autofac.Core.Lifetime.CurrentScopeLifetime, Sharing = None, Ownership = ExternallyOwned
Inner Exception 5: DependencyResolutionException: An error occurred during the activation of a particular registration. See the inner exception for details. Registration: Activator = ConnectorClientFactory (DelegateActivator), Services = [Microsoft.Bot.Builder.Dialogs.Internals.IConnectorClientFactory], Lifetime = Autofac.Core.Lifetime.CurrentScopeLifetime, Sharing = None, Ownership = ExternallyOwned
Inner Exception 6: UriFormatException: Invalid URI: The format of the URI could not be determined.
@bhasker412 I'm unable to repeat the issue you're experiencing. Can you add the entire application to a repository, or .zip it somewhere, so I can take a look?
@EricDahlvang Not sure what is the issue but i deleted all the appsettings from Azure portal App service and my bot started working. I have deployed the Echo bot to my azure subscription and which was working without any issues so checked everything and found that in app service there were no appsettings configured in portal. So followed the same in my app also it started working.
@fj4870 Have you also been able to resolve your issue?
Hi,
I'have the same issues. When i deploy my bot on a New Azure Web App with the use of Bot Chanel Registration.
But i haven't isue when i use old Web App. It's a regresion due to upgrade of Azure platform ?
Have you a solution ?
Sincerely, Pascal
I'have
Hi All,
I am able to fix the issue by upgrading botbuilder framework and replacing default state service by inmemory data store.
Please let me know if you need further information on the same.
Thanks & Regards, Girish Mani
@fj4870 Hi, i have all off thoses.
Bot framework Microsoft.Bot.Builder : v3.15.3 Microsoft.Bot.Builder.Azure: v3.15.2.2 Microsoft.Bot.Builder.History: v3.15.3 Microsoft.Bot.Connector: v3.15.3 Microsoft.Bot.Connector.Teams: v0.9.0
But i it doesn't work with new Azure Web App but it work on old (1 month) Azure Web App.
@sanpas Please implement a custom state client using the Azure Extensions. More information and links can be found here: https://blog.botframework.com/2017/12/19/bot-state-service-will-soon-retired-march-31st-2018/
Hi,
I’have already implemented custom state with the use of default inmemorydatastate like it was implemented on sample.
Le mer. 22 août 2018 à 20:45, Eric Dahlvang [email protected] a écrit :
@sanpas https://github.com/sanpas Please implement a custom state client using the Azure Extensions. More information and links can be found here: https://blog.botframework.com/2017/12/19/bot-state-service-will-soon-retired-march-31st-2018/
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Microsoft/BotBuilder/issues/4953#issuecomment-415137854, or mute the thread https://github.com/notifications/unsubscribe-auth/AFWt0cQkRXsW7PczTZF6tPusgUlgtzCIks5uTaaygaJpZM4V1suY .
-- Pascal-Pierre Sanchez Carrion Ingénieur Informatique / Ingénieur en développement informatique / Computer Science and Engineering 0699574134 0492789853 sanchezcarrion.pascalpierre(at)gmail.com CV : http://www.doyoubuzz.com/pascal-pierre-sanchez-carrion
http://www.doyoubuzz.com/pascal-pierre-sanchez-carrion Mes liens : https://fr.linkedin.com/in/pascalpierresanchezcarrion http://www.viadeo.com/profile/0022e67imo9e584b/
@sanpas Please share your botid, microsoft app id, and the code, so we can take a look.