[英]Web api working locally but not when deployed to Azure
I have a Web Api that I have developed which works perfectly fine when run locally, but when I publish it on Azure, I get a 500 Internal Sever Error
. 我有一个我开发的Web Api,它在本地运行时工作得非常好,但是当我在Azure上发布它时,我得到
500 Internal Sever Error
。
I have 3 tables in the Database - "Messages", "Users", "Conversations" 我在数据库中有3个表 - “消息”,“用户”,“对话”
The error only happens when I make a call to "Conversations" or "Users". 只有在我调用“对话”或“用户”时才会出现错误。 (Conversations contains a list of Users and Users contains a list of conversations.)
(对话包含用户和用户列表,其中包含对话列表。)
I am not sure what is causing this and I don't know how to get more information from this error. 我不确定是什么导致这种情况,我不知道如何从这个错误中获取更多信息。
I have tried changing the entity framework connection string, although I didn't really know what I was doing with it. 我试过更改实体框架连接字符串,虽然我真的不知道我在做什么。 The other connection strings in my web.config seem to be fine.
我的web.config中的其他连接字符串似乎没问题。
Is this a database problem or a code first problem? 这是数据库问题还是代码问题?
Web.confg: Web.confg:
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=tcp:uqq5j22p7m.database.windows.net,1433;Initial Catalog=AA_db;Persist Security Info=True;User ID=KENH@uqq5j22p7m;Password=Password;Connect Timeout=30;Encrypt=True;MultipleActiveResultSets=True;"
providerName="System.Data.SqlClient" />
<add name="AcademicAssistantContext" connectionString="Data Source=tcp:uqq5j22p7m.database.windows.net,1433;Initial Catalog=AA_db;Persist Security Info=True;User ID=KENH@uqq5j22p7m;Password=Password;Connect Timeout=30;Encrypt=True;MultipleActiveResultSets=True;"
providerName="System.Data.SqlClient" />
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="Data Source=.; Integrated Security=True; MultipleActiveResultSets=True" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
It's hard to say what is the error without debugging. 没有调试就很难说出错误是什么。
You can use any logger like log4net or sirilog and then logs errors in the action or method that return HTTP 500 or you can live debug your code in azure . 您可以使用log4net或sirilog等任何记录器,然后在返回HTTP 500的操作或方法中记录错误,或者您可以在azure中实时调试代码 。
Also if the over all web API application didn't run (returns internal server error) it seems to be a configuration error ( wrong ConnectionString for example) but if some of your actions returns 200 and others returns 500 you should debug your code or log your errors to know the exact exception for that. 此外,如果整个Web API应用程序没有运行(返回内部服务器错误),它似乎是一个配置错误(例如,错误的ConnectionString),但如果您的某些操作返回200而其他操作返回500,您应该调试您的代码或日志你的错误,知道确切的例外。
I have found a solution just now! 我刚刚找到了解决方案! I was doing:
我在做:
public IQueryable<Conversation> GetConversations()
{
return db.Conversations;
}
This must have been causing a serialization problem because it works when changed to: 这一定是导致序列化问题,因为它在更改为时有效:
public IEnumerable<Conversation> GetConversations()
{
return db.Conversations.ToList();
}
Couple of days wasted on something so small! 几天浪费在如此小的东西上!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.