【发布时间】:2020-01-09 13:13:05
【问题描述】:
我遇到了一个奇怪的问题,即对 Web 服务器的 api 调用给出了错误消息。并非每台调用 api 的计算机都发生这种情况,只有少数计算机会发生这种情况。
奇怪的是,我可以拉下数据库和数据文件,但这里没有收到消息。另一个奇怪的事情是,我可以从同一台计算机调用 api,但调用不同的方法,它工作正常。这让我相信这是该方法的问题,即使我可以使用相同的设置从这里运行它。
我在我的 api 方法中添加了日志记录,它表明它正在执行该过程,没有任何异常:
public IEnumerable<OfficeMessage> Get30DaysOfOfficeMessages(Guid corporationId)
{
var sb = new StringBuilder();
try
{
sb.AppendLine("************* FRED *************");
sb.AppendLine("Starting Get30DaysOfOfficeMessages");
sb.AppendLine($"CorporationId: {corporationId}");
var getdate = DateTime.Now.AddDays(-30);
sb.AppendLine($"GetDate: {getdate}");
var qry = (from g in _entities.OfficeMessages
where g.CorporationId == corporationId &&
g.MessageDateTime > getdate
orderby g.MessageDateTime descending
select g).ToList();
sb.AppendLine($"Records found: {qry.Count}");
return qry;
}
catch (Exception ex)
{
sb.AppendLine(GetFullExceptionMessage(ex));
Logging2.WriteException(System.Reflection.MethodBase.GetCurrentMethod().Name, ex);
return new List<OfficeMessage>();
}
finally
{
sb.AppendLine("Finished Get30DaysOfOfficeMessages");
Logging2.WriteLog(sb.ToString());
}
}
我的任何日志都显示了这一点:
==============================================================
9/6/2019 10:52:26 AM
************* FRED *************
Starting Get30DaysOfOfficeMessages
CorporationId: 5d6bf36b-3fb8-425f-9c0c-4b2b609cf7f1
GetDate: 8/7/2019 10:52:26 AM
Records found: 6
Finished Get30DaysOfOfficeMessages
==============================================================
我添加了 wcf 跟踪,日志显示以下消息:
这是给像我这样的盲人的信息:
我不确定我是否理解该消息或它发生的原因。
大家有什么建议吗?
***** 更新 *****
我正在添加信息,看看是否有帮助。
我引用的方法的任何服务掩码:
[Inspector]
[FaultContract(typeof(DataAccessFaultContract))]
[WebInvoke(BodyStyle = WebMessageBodyStyle.Wrapped)]
[OperationContract(Name = "Get30DaysOfOfficeMessages")]
IEnumerable<OfficeMessage> Get30DaysOfOfficeMessages(Guid corporationId);
【问题讨论】:
-
该 IEnumerable 中未使用该 DTO ReturnMessage。您是否缺少该 OfficeMessage 类型和 ReturnMessage 类型之间的映射?
-
@rene 我当时一定认为它正在被使用。显然,它在这里没有任何功能。
-
出现故障的机器是否安装了(稍微)不同版本的 Office?从错误日志看,可能是 Office 互操作程序集版本不匹配。
-
我的服务器上没有安装office,从来没有。这是一次没有问题的工作。它似乎与一些公司合作,但不是全部。我无法指出是什么导致特定公司无法运作。
-
这被否决并不让我感到惊讶。我对 SO 的期望丝毫不减。