我有用C#編寫的用於Windows的服務。我需要讓它在Linux上運行。我已經研究過使用Java或C++重寫代碼的可能性,我可能會這樣做,但作爲一箇中間解決方案,我正在考慮將項目移植到Mono或.NET Core。關鍵是它是一個相當小的應用程序,因此進行必要的代碼更改不應該太多。C#端口到Linux單聲道或.NET核心
服務偵聽特定的URL端點來執行任務。
例如基於下面的代碼示例:
http://localhost:5000/checkStatus?configId=1234
事實上,我幾乎把它編譯期待本節。這一節將產生我所有剩餘的構建錯誤。我知道WCF服務在.NET Core中尚不可用。所以我一直在探索替代方案,但我很難在.NET Core的Linux上工作。我也想避免實現一些相當於在整個NGINX或Apache服務器中重寫整個事物或鞋楦的事情。
namespace CheckService
{
[ServiceContract]
interface IService
{
[OperationContract]
[WebGet(ResponseFormat = WebMessageFormat.Json)]
string checkStatus(string configId);
[OperationContract]
[WebGet(ResponseFormat = WebMessageFormat.Json)]
string echo(string value);
[OperationContract]
[WebGet(ResponseFormat = WebMessageFormat.Json)]
string version();
}
}
我不完全熟悉WCF,因爲我從來沒有用過它,而且這個項目最初是由別人編寫的。
這是我的project.json。我知道我可能有一些不必要或不正確的項目。我一直在測試很多:
{
"buildOptions": {
"emitEntryPoint": true,
"debugType": "portable"
},
"dependencies" : {
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
"ServiceStack": "4.5.4",
"System": "4.1.311.2",
"System.IO": "4.3.0",
"System.IO.Pipes": "4.0.0",
"System.Collections": "4.0.11",
"System.Data.Common": "4.0.0",
"System.Data.SQLite": "1.0.0",
"System.ServiceModel": "1.0.0",
"System.ServiceModel.Web": "1.0.0",
"System.ServiceModel.Primitives": "4.3.0",
"System.ServiceModel.Security": "3.9.0",
"System.ServiceModel.Http": "4.0.0",
"slf4net.log4net": "0.1.32.1"
},
"frameworks": {
"net461": {
"frameworkAssemblies": {
"System.Runtime.Serialization": "4.0.0.0",
"System.ServiceModel": "4.0.0"
}
}
},
"tools": {
"Microsoft.AspNetCore.Server.IISIntegration.Tools": {
"version": "1.0.0-preview2-final"
}
},
"scripts": {
"postpublish": "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%"
}
}
有沒有另一種方法可以做到這一點?
謝謝,我認爲這可能是最好的解決方案。 – Chris