【发布时间】:2020-11-05 11:48:09
【问题描述】:
我有一个 WCF C# Rest API 应用程序,主要希望可以通过 HTTP 访问以通过设备执行扫描文档。我已经配置了 CORS 并使用 ProjectInstaller 来生成应该用于安装为 Windows 服务的包。当我在没有 ProjectInstaller 功能的开发模式下运行此应用程序时,一切正常。当我尝试执行扫描操作时,问题就出现了 - 然后 CORS 选项请求失败。这很好奇,特别是因为检查扫描仪可用性的 GET 方法在执行时没有任何 CORS 问题。我尝试了多种差异来解决这个问题,从谷歌搜索结果中应用了 CORS 实现并且它有效,但仅限于开发模式。最后我使用了WebHttpBehaviorExtensions,但问题仍然存在。
清除 - ProjectInstaller 嵌入在与 WCF 应用程序链接的 ConsoleApplication 中。
我的 app.config 是 here。
我的合同如下:
[ServiceContract]
public interface IScanService
{
[OperationContract]
[WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped,
RequestFormat = WebMessageFormat.Json, UriTemplate = "ScanDocument")]
Task ScanDocument(int userId, Guid caseId, string fileName);
[OperationContract]
[WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped,
RequestFormat = WebMessageFormat.Json, UriTemplate = "IsAlive")]
bool IsAlive();
}
我应该怎么做才能允许在启用 CORS 的情况下发送 POST 请求?
提前感谢您的任何回复。
【问题讨论】:
标签: c# wcf windows-services rest