【发布时间】:2018-06-14 23:27:24
【问题描述】:
作为https://stackoverflow.com/questions/48107646/how-to-test-apicontroller...简而言之......
我正在 VS 2013 中处理现有的 Windows 服务项目。
我添加了一个 Web API 控制器类...我将其命名为 SynchroniseFromAwsServiceController
我试图从 AWS lambda 调用中调用它,但它告诉我我没有访问权限。所以我需要在本地对其进行测试,看看它是否可以尝试诊断问题。
namespace Workflow
{
public class SynchroniseFromAwsServiceController: ApiController
{
//// POST api/<controller>
[HttpPost]
public string SapCall([FromBody]string xmlFile)
{
string responseMsg = "Failed Import User";
if (!IsNewestVersionOfXMLFile(xmlFile))
{
responseMsg = "Not latest version of file, update not performed";
}
else
{
Business.PersonnelReplicate personnelReplicate = BusinessLogic.SynchronisePersonnel.BuildFromDataContractXml<Business.PersonnelReplicate>(xmlFile);
bool result = Service.Personnel.SynchroniseCache(personnelReplicate);
if (result)
{
responseMsg = "Success Import Sap Cache User";
}
}
return "{\"response\" : \" " + responseMsg + " \" , \"isNewActiveDirectoryUser\" : \" false \"}";
}
}
}
我正在使用 PostMan 进行测试。我在 VS 中运行应用程序并在 POSTMAN ui 的 POST 字段中输入 http://127.0.0.1/SynchronisePersonnelXmlFromAwsServiceController/SapEaiCall...它返回以下内容:
“/”应用程序中的服务器错误。
未能开始监控更改 'D:\Development\Trunk\WebAppsMVC\Icon\Icon\global.asax' 因为访问 被拒绝。异常详细信息:System.Web.HttpException:失败 开始监控更改 'D:\Development\Trunk\WebAppsMVC\Icon\Icon\global.asax' 因为访问 被拒绝。
堆栈跟踪:
[HttpException (0x80070005): Failed to start monitoring changes to 'D:\Development\Trunk\WebAppsMVC\Icon\Icon\global.asax'因为访问被拒绝。] System.Web.DirectoryMonitor.AddFileMonitor(字符串文件) +9929663 System.Web.DirectoryMonitor.StartMonitoringFileWithAssert(字符串文件, FileChangeEventHandler 回调,字符串别名)+89 System.Web.FileChangesMonitor.StartMonitoringFile(字符串别名,FileChangeEventHandler 回调)+331 System.Web.HttpApplicationFactory.SetupChangesMonitor() +122 System.Web.HttpApplicationFactory.Init() +161 System.Web.HttpApplicationFactory.EnsureInited() +80 System.Web.HttpApplicationFactory.SetupFileChangeNotifications() +71 System.Web.Compilation.BuildManager.CompileGlobalAsax() +57 System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled() +260
[HttpException (0x80004005): Failed to start monitoring changes to 'D:\Development\Trunk\WebAppsMVC\Icon\Icon\global.asax'因为访问被拒绝。] System.Web.Compilation.BuildManager.ReportTopLevelCompilationException() +62 System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled() +435 System.Web.Compilation.BuildManager.CallAppInitializeMethod() +33 System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, 异常 appDomainCreationException) +563
[HttpException (0x80004005): Failed to start monitoring changes to 'D:\Development\Trunk\WebAppsMVC\Icon\Icon\global.asax'因为访问被拒绝。] System.Web.HttpRuntime.FirstRequestInit(HttpContext 上下文) +10085904 System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext 上下文)+95 System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest WR,HttpContext 上下文)+254
[HttpException]: Failed to start monitoring changes to 'D:\Development\Trunk\WebAppsMVC\Icon\Icon\global.asax'因为访问被拒绝。 在 System.Web.DirectoryMonitor.AddFileMonitor(字符串文件) 在 System.Web.DirectoryMonitor.StartMonitoringFileWithAssert(字符串文件, FileChangeEventHandler 回调,字符串别名) 在 System.Web.FileChangesMonitor.StartMonitoringFile(字符串别名,FileChangeEventHandler 回调) 在 System.Web.HttpApplicationFactory.SetupChangesMonitor() 在 System.Web.HttpApplicationFactory.Init() 在 System.Web.HttpApplicationFactory.EnsureInited() 在 System.Web.HttpApplicationFactory.SetupFileChangeNotifications() 在 System.Web.Compilation.BuildManager.CompileGlobalAsax() 在 System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled() [HttpException]:无法开始监视对“D:\Development\Trunk\WebAppsMVC\Icon\Icon\global.asax”的更改 因为访问被拒绝。 在 System.Web.Compilation.BuildManager.ReportTopLevelCompilationException() 在 System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled() 在 System.Web.Compilation.BuildManager.CallAppInitializeMethod() 在 System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, 异常 appDomainCreationException) [HttpException]:无法开始监视对“D:\Development\Trunk\WebAppsMVC\Icon\Icon\global.asax”的更改 因为访问被拒绝。 在 System.Web.HttpRuntime.FirstRequestInit(HttpContext 上下文) 在 System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext 上下文) 在 System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest WR, HttpContext 上下文)
有没有人知道我为什么会被退回<title>Failed to start monitoring changes to 'D:\Development\Trunk\WebAppsMVC\Icon\Icon\global.asax' because access is denied.</title>
更新
感谢https://stackoverflow.com/questions/4889297/failed-to-start-monitoring-changes-on-global-asax-net-3-5-web-service-using-imp
我已从文件夹中删除只读并添加了经过身份验证的用户。现在当我运行时,它给了我一个不同的错误,但仍然说访问被拒绝......我使用的是正确的 URL 吗? http://127.0.0.1/SynchronisePersonnelXmlFromAwsServiceController/SapEaiCall
不管怎样,新的错误是:
“/”应用程序中的服务器错误。访问被拒绝。说明:一个 访问提供此服务所需的资源时发生错误 要求。服务器可能未配置为访问所请求的 网址。
错误消息 401.2 未经授权:由于服务器原因登录失败 配置。
验证您是否有权查看此目录或基于页面的 在您提供的凭据和启用的身份验证方法上 在 Web 服务器上。请与 Web 服务器的管理员联系以获取 额外的帮助。
any help would be much appreciated thank you
更新 感谢 George Vovos 的回复,我已将 http 移至方法上方,并将签名更改为包含控制器。
在邮递员中,我还包含了用于授权的基本值标签。
现在当我在本地运行 VS 应用程序并尝试通过邮递员与http://localhost/WebServices.Workflow/SynchroniseFromAwsServiceController/SapCall 连接时
(WebServices.Workflow 是应用程序名称)
我收到以下消息:
Could not get any response
There was an error connecting to http://localhost/WebServices.Workflow/SynchroniseFromAwsServiceController/SapEaiCall
Why this might have happened:
The server couldn't send a response:
Ensure that the backend is working properly
Self-signed SSL certificates are being blocked:
Fix this by turning off 'SSL certificate verification' in Settings > General
Proxy configured incorrectly
Ensure that proxy is configured correctly in Settings > Proxy
Request timeout:
Change request timeout in Settings > General
我已尝试关闭 SSL...还有其他想法吗?
新更新
从一个帖子开始,我发现我重新启动 PostMan 并再次运行 POST,现在消息返回 There is a duplicate 'exceptionless' section defined,这是我尝试从 Visual Studio 运行应用程序时得到的。所以至少这是朝着正确方向迈出的一步(我认为)...我已经为此写了一个新的 Q...
config file flagging as duplicate Exceptionless package
注意如果有人能帮我回答这个延续Q,我会奖励他们这个Q的赏金。注意
感谢您的回复
【问题讨论】:
-
我能问一下为什么是 -1 和为什么是 close 吗?我不知道为什么我的访问被拒绝,我正在寻求帮助不是重点吗?
-
John,您能粘贴一个工作示例吗?HttpPost 仅对方法有效。您的类的名称不以 'Controller' 结尾,您的请求 url 不应包含 'Controller' 后缀。除此之外应该没有任何问题,请遵循约定,如果您仍有问题,请告诉我们
-
感谢回复,请看帖子更新
-
您是否尝试连接到
http://localhost/WebServices.SapEai.Workflow/SynchroniseFromAwsService/SapEaiCall? -
嘿@JohnEphraimTugado 是的,我有,抱歉我砍掉并更改了应该是localhost/WebServices.Workflow/…的URL
标签: c# asp.net-web-api postman