简体   繁体   English

构建Service Fabric Web Api时,获取错误无法从Fabric.StatelessServiceContext转换为Fabric.ServiceInitializationParameters

[英]Getting error cannot convert from Fabric.StatelessServiceContext to Fabric.ServiceInitializationParameters while building Service Fabric Web Api

I'm getting error while following this tutorial 我在学习本教程时遇到错误

cannot convert from 'System.Fabric.StatelessServiceContext' to 'System.Fabric.ServiceInitializationParameters' 

while trying to create the Service Fabric Web Api explained in it. 在尝试创建Service Fabric Web Api时,在其中进行了解释。

Specifically, I'm getting it in this next line: 具体来说,我将在下一行中得到它:

 return new[] {
            new ServiceInstanceListener(initParams =>
            new OwinCommunicationListener("api",new Startup(),initParams) )
        };

I haven't tried much, since Azure's Service Fabric is pretty new stuff, so there isn't much out there in terms of other Web Api examples. 我没有尝试太多,因为Azure的Service Fabric是一个非常新的东西,所以在其他Web Api示例方面没有太多的东西。 The tutorial above itself is not even finished yet. 上面的教程本身甚至还没有完成。

Has anyone got any ideas? 有没有人有任何想法?

Thanks 谢谢

So the problem is that there is a typo in the tutorial. 所以问题在于教程中存在拼写错误。

The solution is that _parameters in class OwinCommunicationListener should be declared as StatelessServiceContext , not as ServiceInitializationParameters . 解决方案是, _parameters类中的OwinCommunicationListener 应声明为StatelessServiceContext ,而不是ServiceInitializationParameters The solution is kind of suggested by Visual Studio's potential fixes. 解决方案是Visual Studio的潜在修复建议的一种解决方案。

Just to be clear, the original code of the tutorial throwing the error reads: 为了清楚起见,抛出错误的教程的原始代码如下:

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;
    }

And the correct code is this next one, note the differences in line 3 and 11: 正确的代码是下一个,注意第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;
    }

The call remains the same: 电话保持不变:

return new[] {
            new ServiceInstanceListener(initParams =>
            new OwinCommunicationListener("api",new Startup(),initParams) )
        };

I hope this helps. 我希望这有帮助。

For the same tutorial if someone wondering about missing references , here is the list : 对于同一个教程,如果有人想知道缺少引用,这里是列表:

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;

For installed Nuget packages : (Go to References in project explorer right click > Nuget Package explorer and install following if not there ) 对于已安装的Nuget软件包:(转到项目资源管理器中的参考资料,右键单击> Nuget软件包资源管理器,如果不存在,则安装如下)

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM