Page tree
Skip to end of metadata
Go to start of metadata

1.描述

6.1版本之前的活字格服务器基于Katana框架,从6.1版本开始,活字格服务器从Katana迁移到ASP.NET Core,因此您需要迁移服务端的Web API。

如果Web API没有使用ForguncyApi类的Context属性,则无需升级Web API即可以正常工作。

2.升级服务端Web API

操作步骤

  检查项目属性,确认项目的Framework框架为.NET Framework 4.7.2。

  在解决方案资源管理器下,移除“GrapeCity.Forguncy.ServerApi.dll”和“Microsoft.Owin.dll”文件,并重新在活字格的安装目录下找到“GrapeCity.Forguncy.ServerApi.dll”文件,将其添加为该工程的引用。

  •   如果安装活字格服务端时,安装目录为默认目录,则此文件的路径为:
    • Windows系统为32位操作系统:C:\Program Files\ForguncyServer\Website\bin。 
    • Windows系统为64位操作系统:C:\Program Files (x86)\ForguncyServer\Website\bin。
  • 如果安装活字格服务端时,安装目录为自定义路径,则此文件的路径为“自定义路径\ForguncyServer\Website\bin”。

  在解决方案资源管理器中,选中“MyAPI”,右击,选择“管理NuGet程序包”。

在NuGet管理器中,搜索并安装“Microsoft.AspNetCore.Http.Abstractions”。

如果要使用WriteAsync方法,请添加"using Microsoft.AspNetCore.Http;" 。

如果Web API中使用了以下的方法,请更新为新的写法。

方法

Write ResponseContext.Response.Write(result)Context.Response.WriteAsync(result).Wait()
ReadRequestStringnew StreamReader(base.Context.Request.Body).ReadToEnd()new StreamReader(base.Context.Request.Body).ReadToEndAsync().Result
Context.Request.Userthis.Context.Request.Userthis.Context.User

异步支持。同步与异步两种方式的功能相同,异步方式的性能在较大的并发访问时表现更好。

同步

异步

[Get]
public void TestApi2()
{
    this.Context.Response.WriteAsync().Wait()
}
[Get]
public async Task TestApi2()
{
      await this.Context.Response.WriteAsync();
}

  在解决方案资源管理器中,右击解决方案,在右键菜单中选择“重新生成”。

  重新上传生成的dll文件。在设计器中,选择“文件->设置->自定义Web Api”,单击“上传Web Api Assembly”,上传生成的dll文件。


回到顶部

  • No labels