C# 生成服务结构Web Api时,获取错误无法从Fabric.StatelessServiceContext转换为Fabric.ServiceInitializationParameters
我在工作时出错了 在尝试创建其中解释的服务结构Web Api时 具体来说,我将在下一行中介绍:C# 生成服务结构Web Api时,获取错误无法从Fabric.StatelessServiceContext转换为Fabric.ServiceInitializationParameters,c#,azure,asp.net-web-api,asp.net-web-api2,azure-service-fabric,C#,Azure,Asp.net Web Api,Asp.net Web Api2,Azure Service Fabric,我在工作时出错了 在尝试创建其中解释的服务结构Web Api时 具体来说,我将在下一行中介绍: return new[] { new ServiceInstanceListener(initParams => new OwinCommunicationListener("api",new Startup(),initParams) ) }; 我没有做过很多尝试,因为Azure的服务结构是非常新的东西,所以在其他Web Ap
return new[] {
new ServiceInstanceListener(initParams =>
new OwinCommunicationListener("api",new Startup(),initParams) )
};
我没有做过很多尝试,因为Azure的服务结构是非常新的东西,所以在其他Web Api示例方面没有太多尝试。上面的教程本身甚至还没有完成
有人有什么想法吗
谢谢所以问题是教程中有一个打字错误 解决方案是,类中的
\u参数
OwinCommunicationListener应声明为无状态服务上下文
,而不是服务初始化参数
。这个解决方案是由VisualStudio的潜在修复建议的
为了清楚起见,抛出错误的教程的原始代码如下:
private readonly IOwinAppBuilder _startup;
private readonly string _appRoot;
private readonly ServiceInitializationParameters _parameters;
private string _listeningAddress;
private IDisposable _serverHandle;
public OwinCommunicationListener(
string appRoot,
IOwinAppBuilder startup,
ServiceInitializationParameters serviceInitializationParameters
)
{
_startup = startup;
_appRoot = appRoot;
_parameters = serviceInitializationParameters;
}
正确的代码是下一个,请注意第3行和第11行的区别:
private readonly IOwinAppBuilder _startup;
private readonly string _appRoot;
private readonly StatelessServiceContext _parameters;
private string _listeningAddress;
private IDisposable _serverHandle;
public OwinCommunicationListener(
string appRoot,
IOwinAppBuilder startup,
// Use StatelessServiceContext, NOT ServiceInitializationParameters
StatelessServiceContext serviceInitializationParameters
)
{
_startup = startup;
_appRoot = appRoot;
_parameters = serviceInitializationParameters;
}
电话保持不变:
return new[] {
new ServiceInstanceListener(initParams =>
new OwinCommunicationListener("api",new Startup(),initParams) )
};
我希望这能有所帮助。对于同一教程,如果有人想知道缺少的参考资料,以下是列表:
using System.Fabric;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Owin.Hosting;
using Microsoft.ServiceFabric.Services.Communication.Runtime;
using System.Globalization;using System.Collections.Generic;
using System.Fabric;
using Microsoft.ServiceFabric.Services.Communication.Runtime;
using Microsoft.ServiceFabric.Services.Runtime;
对于已安装的Nuget软件包:(转到项目资源管理器中的引用右键单击>Nuget软件包资源管理器,如果没有,请安装以下内容)
using System.Fabric;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Owin.Hosting;
using Microsoft.ServiceFabric.Services.Communication.Runtime;
using System.Globalization;using System.Collections.Generic;
using System.Fabric;
using Microsoft.ServiceFabric.Services.Communication.Runtime;
using Microsoft.ServiceFabric.Services.Runtime;