我的REST服务(在Azure上作为AppService运行的ASP.NET)运行得很好,直到最近的一个最小的变化。如果我转到https://update.windward.net/,它会返回正常。但在https://update.windward.net/Service/version上发布会返回400。
我99%确定我的服务没有被调用,它发生在那之前。以下是服务入口点:
[WebGet(UriTemplate = "")]
public string GetTest()
{
return $"Windward update REST service version {AssmVersion}; " +
$"Newest AutoTag version: {ConfigurationManager.AppSettings["AutoTagVersion"]}; " +
$"Most recent exception {mostRecentTime:G} : {mostRecentError}";
}
[WebInvoke(UriTemplate = "Service/version", Method = "POST", RequestFormat = WebMessageFormat.Xml,
ResponseFormat = WebMessageFormat.Xml, BodyStyle = WebMessageBodyStyle.Bare)]
public XmlElement GetVersion(XmlElement root)
{
try
{
//...
}
catch (Exception ex)
{
log.Error("GetVersion", ex);
mostRecentError = $"GetVersion({root.Name}): {ex.Message}";
mostRecentTime = DateTime.UtcNow;
throw;
}
}我很难让日志正常工作,所以我只有mostRecentError字符串可以调试。
发布于 2019-01-16 05:38:26
对于那些有类似问题的人来说,更有趣的是我是如何发现这个问题的。
我使用了the Azure diagnostic tool described here (including how to use it)。由此,我发现我的服务方法正在被调用,并且在该代码中抛出了一个异常。
因此,第1项-获得400可能意味着您的服务正在被调用,但却抛出了异常。
第二项,日志可以工作,但Azure工具要好得多(至少在我的例子中是这样)。
发布于 2019-01-13 19:27:23
我建议您从属性中去掉RequestFormat、ResponseFormat和BodyStyle,并将root方法参数更改为string,以查看请求是否到达该方法。
一旦确定了这一点,请尝试重新添加已删除/更改的代码(一次添加一个),看看是什么影响了对该方法的调用。
希望它能帮上忙!
https://stackoverflow.com/questions/54154229
复制相似问题