.NET 6 上の CoreWCF を使うように WCF サーバー側プロジェクトをアップグレードする

重要

この記事は、Visual Studio 用アップグレード アシスタント拡張機能のリリース前に作成されたため、レガシ CLI ツールが使用されています。 詳しくは、「レガシ .NET アップグレード アシスタントを使用する」を参照してください。

.NET アップグレード アシスタントはコマンドライン ツールです。.NET 6 上の CoreWCF サービスを使うように .NET Framework 上の既存の WCF サーバー側プロジェクトをアップグレードするときに役立ちます。 この記事では、次の内容について説明します。

  • 開始する前に知っておくべきこと。
  • .NET Framework 上の WCF サーバー側プロジェクトに対して、このツールを実行する方法のデモ。
  • トラブルシューティングのヒント

ツールのインストール方法について詳しくは、「レガシ .NET アップグレード アシスタントを使用する」を参照してください。

開始前に理解しておくべきこと

現在、このツールは、C# プロジェクトをサポートしており、セルフホステッド WCF サーバー側プロジェクトを .NET 6 に移植するために CoreWCF を使用しています。

WCF プロジェクトをこのアップグレードに適用するには、次の要件を満たす必要があります。

  1. System.ServiceModel を参照し、新しい ServiceHost を作成する .cs ファイルを含めます。

    WCF プロジェクトに複数の ServiceHost がある場合、同じメソッドですべてのホストを作成する必要があります。

  2. System.ServiceModel プロパティを格納する .config ファイルを含めます。

このツールの最新バージョンは、.svc ファイルを介してホストされる WCF プロジェクトをサポートしていません。

Note

プロジェクトをこのツールに適用できない場合、CoreWCF のチュートリアル ガイドBeanTrader サンプル デモの記事を確認して、プロジェクトを手動で更新することをお勧めします。

デモ アプリ

基本の計算機サンプル プロジェクトを使って、アップグレード アシスタントによるアップグレードをテストできます。このドキュメントで使われているデモもこれです。

さらに複雑なサンプルを試したい場合は、Mike Rousos が作成した BeanTrader サンプルを確認してください。

upgrade-assistant の実行

ターミナルを開き、ターゲット プロジェクトまたはソリューションが配置されているフォルダーに移動します。 アップグレードするプロジェクトまたはソリューションの名前を指定して、upgrade-assistant upgrade コマンドを実行します。

プロジェクトを指定した場合は、そのプロジェクトですぐにアップグレード プロセスが開始されます。 ソリューションを指定した場合は、通常実行するプロジェクト (アップグレード エントリポイントという) を選択します。 そのプロジェクトに基づいて、依存関係グラフが作成され、プロジェクトをアップグレードする順序に関する提案が表示されます。

upgrade-assistant upgrade .\CalculatorSample.sln

ツールが実行され、実行されるステップの一覧が表示されます。 ステップが完了するたびに、一連のコマンドがツールに表示されます。これらのコマンドを使用すると、次のステップを適用またはスキップしたり、次のような他のオプションを適用またはスキップしたりできます。

  • ステップの詳細を確認する。
  • プロジェクトを変更する。
  • ログ設定を調整する。
  • アップグレードを停止して終了する。

数字を選択せずに Enter キーを押すと、一覧の最初の項目が選択されます。

各ステップの初期化時に、そのステップを適用するとどうなるかに関する情報が提供される場合があります。

アップグレードするエントリ ポイントとプロジェクトを選択する

基本的な計算機サンプルをアップグレードする最初のステップは、ソリューション内でエントリポイント プロジェクトとして機能するプロジェクトを選ぶことです。

Upgrade Steps

1. [Next step] Select an entrypoint
2. Select project to upgrade

Choose a command:
   1. Apply next step (Select an entrypoint)
   2. Skip next step (Select an entrypoint)
   3. See more step details
   4. Configure logging
   5. Exit

コマンド 1 を選択して、そのステップを開始します。 次のような結果が表示されます。

[10:25:42 INF] Applying upgrade step Select an entrypoint
Please select the project you run. We will then analyze the dependencies and identify the recommended order to upgrade projects.
   1. CalculatorClient
   2. CalculatorService

2 つのプロジェクトが一覧表示されます。 このツールによってサーバー側プロジェクトがアップグレードされるので、コマンド 2 を選び、エントリ ポイントとしてサービス プロジェクトを選択します。

プロジェクトのアップグレード

プロジェクトを選択すると、ツールで実行されるアップグレード ステップの一覧が表示されます。

重要

アップグレードするプロジェクトに応じて、この例のすべてのステップが表示される場合と表示されない場合があります。

次の出力は、プロジェクトのアップグレードに関連するステップを示しています。

Upgrade Steps

Entrypoint: C:\Users\Desktop\CalculatorSample\CalculatorService\CalculatorService.csproj
Current Project: C:\Users\Desktop\CalculatorSample\CalculatorService\CalculatorService.csproj

1. [Next step] Back up project
2. Convert project file to SDK style
3. Clean up NuGet package references
    a. Duplicate reference analyzer
    b. Package map reference analyzer
    c. Target compatibility reference analyzer
    d. Upgrade assistant reference analyzer
    e. Windows Compatibility Pack Analyzer
    f. MyDotAnalyzer reference analyzer
    g. Newtonsoft.Json reference analyzer
    h. Windows App SDK package analysis
    i. Transitive reference analyzer
4. Update TFM
5. Update NuGet Packages
    a. Duplicate reference analyzer
    b. Package map reference analyzer
    c. Target compatibility reference analyzer
    d. Upgrade assistant reference analyzer
    e. Windows Compatibility Pack Analyzer
    f. MyDotAnalyzer reference analyzer
    g. Newtonsoft.Json reference analyzer
    h. Windows App SDK package analysis
    i. Transitive reference analyzer
6. Add template files
7. Update WCF service to CoreWCF (Preview)
8. Upgrade app config files
    a. Convert Application Settings
    b. Convert Connection Strings
    c. Disable unsupported configuration sections
9. Update source code
    a. Apply fix for UA0002: Types should be upgraded
    b. Apply fix for UA0012: 'UnsafeDeserialize()' does not exist
    c. Apply fix for UA0014: .NET MAUI projects should not reference Xamarin.Forms namespaces
    d. Apply fix for UA0015: .NET MAUI projects should not reference Xamarin.Essentials namespaces
10. Move to next project

Choose a command:
   1. Apply next step (Back up project)
   2. Skip next step (Back up project)
   3. See more step details
   4. Select different project
   5. Configure logging
   6. Exit

Note

この記事の残りの部分では、指摘すべき重要なポイントがない限り、アップグレード ステップを省略します。各ステップの結果は表示されます。

バックアップの作成

CalculatorService プロジェクトをアップグレードするこの例では、各ステップを適用します。 最初のステップであるコマンド 1 は、プロジェクトのバックアップです。

[10:25:52 INF] Applying upgrade step Back up project
Please choose a backup path
   1. Use default path [C:\Users\Desktop\CalculatorSample.backup]
   2. Enter custom path

ツールは、現在のフォルダーの後ろに .backup が付加された既定のバックアップ パスを選択します。 既定のパスの代わりにカスタム パスを選択することもできます。 アップグレードするプロジェクトごとに、プロジェクトのフォルダーがバックアップ フォルダーにコピーされます。 この例では、バックアップ ステップ中に CalculatorSample\CalculatorService から CalculatorSample.backup\CalculatorServiceCalculatorService フォルダーがコピーされます。

[10:25:53 INF] Backing up C:\Users\Desktop\CalculatorSample\CalculatorService to C:\Users\t-simonaliao\OneDrive - Microsoft\Desktop\CalculatorSample.backup\CalculatorService
[10:25:53 INF] Project backed up to C:\Users\Desktop\CalculatorSample.backup\CalculatorService
[10:25:53 INF] Upgrade step Back up project applied successfully
Please press enter to continue...

プロジェクト ファイルのアップグレード

プロジェクトは、.NET Framework プロジェクト形式から .NET SDK プロジェクト形式にアップグレードされます。

[10:25:56 INF] Applying upgrade step Convert project file to SDK style
[10:25:56 INF] Converting project file format with try-convert, version 0.4.0-dev
[10:25:56 INF] Recommending executable TFM net6.0 because the project builds to an executable
C:\Users\Desktop\CalculatorSample\CalculatorService\CalculatorService.csproj contains an App.config file. App.config is replaced by appsettings.json in .NET Core. You will need to delete App.config and migrate to appsettings.json if it's applicable to your project.
[10:25:58 INF] Converting project C:\Users\CalculatorSample\CalculatorService\CalculatorService.csproj to SDK style
[10:25:58 INF] Project file converted successfully! The project may require additional changes to build successfully against the new .NET target.
[10:26:00 INF] Upgrade step Convert project file to SDK style applied successfully

各ステップの出力に注目してください。 出力例は、アップグレード後に手動で完了すべき手順を示していることに注意してください。

App.config は、.NET Core の appsettings.json に置き換えられます。 プロジェクトに該当する場合は、App.config アプリを削除し、appsettings.json に移行する必要があります。

このサンプルでは、WCF の更新ステップで App.configsystem.serviceModel セクションに基づいて新しい wcf.config が作成されます。appsettings.json に移行する必要はありません。

NuGet 参照のクリーンアップ

プロジェクト形式が更新されたら、次のステップは NuGet パッケージ参照をクリーンアップすることです。

アプリによって参照されるパッケージに加えて、packages.config ファイルには、それらのパッケージの依存関係への参照が含まれています。 たとえば、パッケージ B に依存しているパッケージ A への参照を追加した場合は、両方のパッケージが packages.config ファイルで参照されます。 新しいプロジェクト システムでは、パッケージ A への参照だけが必要です。 このステップでは、パッケージ参照を分析し、不要な参照を削除します。

[10:26:01 INF] Initializing upgrade step Clean up NuGet package references
[10:26:01 INF] Initializing upgrade step Duplicate reference analyzer
[10:26:01 INF] No package updates needed
[10:26:01 INF] Initializing upgrade step Package map reference analyzer
[10:26:01 INF] Marking assembly reference System.configuration for removal based on package mapping configuration System.Configuration
[10:26:01 INF] Adding package System.Configuration.ConfigurationManager based on package mapping configuration System.Configuration
[10:26:01 INF] Marking assembly reference System.ServiceModel for removal based on package mapping configuration System.ServiceModel
[10:26:01 INF] Adding package System.ServiceModel.Primitives based on package mapping configuration System.ServiceModel
[10:26:01 INF] Adding package System.ServiceModel.Http based on package mapping configuration System.ServiceModel
[10:26:01 INF] Adding package System.ServiceModel.Duplex based on package mapping configuration System.ServiceModel
[10:26:01 INF] Adding package System.ServiceModel.NetTcp based on package mapping configuration System.ServiceModel
[10:26:01 INF] Adding package System.ServiceModel.Security based on package mapping configuration System.ServiceModel
[10:26:01 INF] Adding package System.ServiceModel.Federation based on package mapping configuration System.ServiceModel

[10:26:01 INF] Initializing upgrade step Remove reference 'System.configuration'
[10:26:03 INF] Applying upgrade step Remove reference 'System.configuration'
[10:26:03 INF] Removing outdated assembly reference: System.configuration
[10:26:03 INF] Upgrade step Remove reference 'System.configuration' applied successfully

[10:26:05 INF] Initializing upgrade step Remove reference 'System.ServiceModel'
[10:26:06 INF] Applying upgrade step Remove reference 'System.ServiceModel'
[10:26:06 INF] Removing outdated assembly reference: System.ServiceModel
[10:26:06 INF] Upgrade step Remove reference 'System.ServiceModel' applied successfully

[10:26:07 INF] Initializing upgrade step Add package 'System.Configuration.ConfigurationManager'
[10:26:09 INF] Applying upgrade step Add package 'System.Configuration.ConfigurationManager'
[10:26:09 INF] Adding package reference: System.Configuration.ConfigurationManager, Version=5.0.0
[10:26:09 INF] Upgrade step Add package 'System.Configuration.ConfigurationManager' applied successfully
[10:26:09 INF] Applying upgrade step Package map reference analyzer
[10:26:09 INF] Upgrade step Package map reference analyzer applied successfully

[10:26:10 INF] Initializing upgrade step Target compatibility reference analyzer
[10:26:10 INF] No package updates needed
[10:26:10 INF] Initializing upgrade step Upgrade assistant reference analyzer
[10:26:11 INF] Reference to .NET Upgrade Assistant analyzer package (Microsoft.DotNet.UpgradeAssistant.Extensions.Default.Analyzers, version 0.4.336902) needs to be added
[10:26:11 INF] Initializing upgrade step Add package 'Microsoft.DotNet.UpgradeAssistant.Extensions.Default.Analyzers'
[10:26:13 INF] Applying upgrade step Add package 'Microsoft.DotNet.UpgradeAssistant.Extensions.Default.Analyzers'
[10:26:13 INF] Adding package reference: Microsoft.DotNet.UpgradeAssistant.Extensions.Default.Analyzers, Version=0.4.336902
[10:26:13 INF] Upgrade step Add package 'Microsoft.DotNet.UpgradeAssistant.Extensions.Default.Analyzers' applied successfully
[10:26:13 INF] Applying upgrade step Upgrade assistant reference analyzer
[10:26:14 INF] Upgrade step Upgrade assistant reference analyzer applied successfully

[10:26:15 INF] Initializing upgrade step Windows Compatibility Pack Analyzer
[10:26:15 INF] No package updates needed
[10:26:15 INF] Initializing upgrade step MyDotAnalyzer reference analyzer
[10:26:15 INF] No package updates needed
[10:26:15 INF] Initializing upgrade step Newtonsoft.Json reference analyzer
[10:26:15 INF] No package updates needed
[10:26:15 INF] Initializing upgrade step Windows App SDK package analysis
[10:26:15 INF] No package updates needed
[10:26:15 INF] Initializing upgrade step Transitive reference analyzer
[10:26:15 INF] No package updates needed
[10:26:15 INF] Applying upgrade step Clean up NuGet package references
[10:26:15 INF] Upgrade step Clean up NuGet package references applied successfully

アプリは引き続き .NET Framework アセンブリを参照しています。 これらのアセンブリの一部は、NuGet パッケージとして利用できます。 このステップでは、これらのアセンブリを分析し、該当する NuGet パッケージを参照します。

この例では、パッケージ アップデーターによって CalculatorService がサーバー専用プロジェクトとして検出されます。System.ServiceModel パッケージを追加する必要はありません。 パッケージ マッピングの構成に基づいてリストに追加した場合でも、それらのステップは適用されませんでした。

TFM の処理

次に、ツールは、TFM を .NET Framework から提案された SDK に変更します。 この例では net6.0-windows です。

[10:26:17 INF] Applying upgrade step Update TFM
[10:26:17 INF] Recommending executable TFM net6.0 because the project builds to an executable
[10:26:19 INF] Updated TFM to net6.0
[10:26:19 INF] Upgrade step Update TFM applied successfully

NuGet パッケージのアップグレード

次に、ツールは、プロジェクトの NuGet パッケージを、更新された TFM (net6.0-windows) をサポートするバージョンに更新します。

[10:26:20 INF] Initializing upgrade step Update NuGet Packages
[10:26:20 INF] Initializing upgrade step Duplicate reference analyzer
[10:26:20 INF] No package updates needed
[10:26:20 INF] Initializing upgrade step Package map reference analyzer
[10:26:20 INF] No package updates needed
[10:26:20 INF] Initializing upgrade step Target compatibility reference analyzer
[10:26:20 INF] No package updates needed
[10:26:20 INF] Initializing upgrade step Upgrade assistant reference analyzer
[10:26:20 INF] No package updates needed
[10:26:20 INF] Initializing upgrade step Windows Compatibility Pack Analyzer
[10:26:20 INF] No package updates needed
[10:26:20 INF] Initializing upgrade step MyDotAnalyzer reference analyzer
[10:26:20 INF] No package updates needed
[10:26:20 INF] Initializing upgrade step Newtonsoft.Json reference analyzer
[10:26:20 INF] No package updates needed
[10:26:20 INF] Initializing upgrade step Windows App SDK package analysis
[10:26:20 INF] No package updates needed
[10:26:20 INF] Initializing upgrade step Transitive reference analyzer
[10:26:20 INF] No package updates needed
[10:26:20 INF] Applying upgrade step Update NuGet Packages
[10:26:20 INF] Upgrade step Update NuGet Packages applied successfully

テンプレート ファイルを追加します

パッケージが更新されたら、次のステップはテンプレート ファイルを更新することです。 この例では、更新またはプロジェクトに追加する必要があるテンプレート ファイルはありません。 このステップはスキップされ、次のステップが自動的に開始されます。

[10:26:20 INF] Initializing upgrade step Add template files
[10:26:20 INF] 0 expected template items needed

WCF サービスを CoreWCF に更新します (プレビュー)

注: このドキュメントの執筆時点で、WCF アップデーター拡張機能はプレビュー リリースとして提供されています。 プレビュー バージョンについてフィードバックがある場合は、アップグレード アシスタント GitHub リポジトリarea:WCF タグを付けて issue を開いてください。

アップグレード アシスタントにより、まず WCF アップデーター ステップが初期化され、プロジェクトを WCF の更新に適用できるかどうかが確認されます。

[10:26:20 INF] Initializing upgrade step Update WCF service to CoreWCF (Preview)
[10:26:20 INF] This config file is applicable for upgrade: C:\Users\Desktop\CalculatorSample\CalculatorService\App.config. System.serviceModel/services elements were found.
[10:26:20 INF] This  file is applicable for upgrade: C:\Users\Desktop\CalculatorSample\CalculatorService\service.cs. ServiceHost object was found.
[10:26:20 INF] This project file is applicable for upgrade: C:\Users\Desktop\CalculatorSample\CalculatorService\CalculatorService.csproj. Reference to System.serviceModel was found.
[10:26:20 INF] This project is applicable for updating to CoreWCF. Initializing the update step...
[10:26:20 INF] Updaters are successfully constructed. Ready to start update.

Choose a command:
   1. Apply next step (Update WCF service to CoreWCF (Preview))
   2. Skip next step (Update WCF service to CoreWCF (Preview))
   3. See more step details
   4. Select different project
   5. Configure logging
   6. Exit

このステップでは、構成ファイル、ソース コード、プロジェクト ファイルを個別に確認し、プロジェクトが WCF の更新に適用できるかどうかを判断します。 プロジェクトを適用できない場合 (WCF を使っていない、この記事の冒頭で説明した要件を満たしていないなど)、適用できなかったファイル、不足していたものがログ メッセージに記述されます。 次に、そのステップはスキップされ、次のステップが自動的に開始されます。

このサンプルでは、CalculatorSample を WCF の更新に適用できるので、コマンド 1 を選び、ステップを適用します。

[10:26:23 INF] Applying upgrade step Update WCF service to CoreWCF (Preview)
[10:26:23 INF] Finish updating project file.
[10:26:23 WRN] The mex endpoint is removed from .config file, and service metadata behavior is configured in the source code instead.
[10:26:23 INF] Finish updating configuration files.
[10:26:23 WRN] Changing void Main() to async Task Main() to enable awaiting starting and stopping the ASP.NET Core host.
[10:26:23 INF] Finish updating source code.
[10:26:23 INF] Finish writing changes to project file.
[10:26:23 INF] Finish writing changes to configuration files.
[10:26:23 INF] Finish writing changes to the source code to replace the ServiceHost instance(s).
[10:26:23 INF] Project was successfully updated to use CoreWCF services. Please review changes.
[10:26:23 INF] Upgrade step Update WCF service to CoreWCF (Preview) applied successfully

このステップでは、更新内容を作成し、元のファイルに個別に書き込みます。 出力には注意してください。元のファイルからの削除や、アップグレード後に完了する手動の更新について記載されている場合があります。

構成ファイルとコード ファイルの更新

ツールがプロジェクトに対して行う必要がないと判断した場合、これらのステップは自動的にスキップされることがあります。

WCF の更新が完了したら、次のステップはアプリ構成ファイルの更新です。 この例では、アプリ構成ファイル内にアップグレードが必要なものはありません。 WCF のステップで構成ファイルは更新済みなので、このステップではサポートされていない system.serviceModel の使用について愚痴をこぼす必要はありません。 このステップはスキップされ、次のステップが自動的に開始されます。

[10:26:43 INF] Initializing upgrade step Upgrade app config files
[10:26:43 INF] Found 0 app settings for upgrade:
[10:26:43 INF] Found 0 connection strings for upgrade:
[10:26:43 INF] 0 web page namespace imports need upgraded:

このプロジェクトのアップグレードが完了する前の最後のステップは、古いコード参照を更新することです。 このステップでは、アップグレードするプロジェクトの種類に基づいて、既知のコード修正の一覧が表示されます。 修正プログラムの一部がプロジェクトに該当しない場合があります。

9. Update source code
    a. Apply fix for UA0002: Types should be upgraded
    b. Apply fix for UA0012: 'UnsafeDeserialize()' does not exist
    c. Apply fix for UA0014: .NET MAUI projects should not reference Xamarin.Forms namespaces
    d. Apply fix for UA0015: .NET MAUI projects should not reference Xamarin.Essentials namespaces

その場合は、提案された修正プログラムのすべてがサンプル プロジェクトに適用されません。このステップは、前のステップが完了した直後に自動的に終了します。

[10:26:44 INF] Initializing upgrade step Update source code
[10:26:44 INF] Running analyzers on CalculatorService
[10:26:48 INF] Identified 0 diagnostics in project CalculatorService
[10:26:51 INF] Initializing upgrade step Move to next project

アップグレードの完了

移行するプロジェクトがまだある場合は、次にアップグレードするプロジェクトを選択するように促されます。 アップグレードするプロジェクトがこれ以上ない場合は、"アップグレードの最終処理" ステップに誘導されます。

1. [Next step] Finalize upgrade

Choose a command:
   1. Apply next step (Finalize upgrade)
   2. Skip next step (Finalize upgrade)
   3. See more step details
   4. Configure logging
   5. Exit
>
[10:27:15 INF] Applying upgrade step Finalize upgrade
[10:27:15 INF] Upgrade step Finalize upgrade applied successfully

理想的には、ツールを正常に実行した後、これらの変更が元のファイルに表示されます。

service.cs ファイル内の using System.ServiceModel は CoreWCF への参照に置き換えられました。 ServiceHost インスタンスも削除され、サービスは ASP.NET Core 上でホストされるようになりました。

using System;
using System.Threading.Tasks;
using CoreWCF;
using CoreWCF.Configuration;
using CoreWCF.Description;
using CoreWCF.Security;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
    public static async Task Main()
    {
        var builder = WebApplication.CreateBuilder();

        // Set up port (previously this was done in configuration,
        // but CoreWCF requires it be done in code)
        builder.WebHost.UseNetTcp(8090);
        builder.WebHost.ConfigureKestrel(options =>
        {
            options.ListenAnyIP(8080);
        });

        // Add CoreWCF services to the ASP.NET Core app's DI container
        builder.Services.AddServiceModelServices()
                        .AddServiceModelConfigurationManagerFile("wcf.config")
                        .AddServiceModelMetadata()
                        .AddTransient<CalculatorSample.CalculatorService>();

        var app = builder.Build();

        // Enable getting metadata/wsdl
        var serviceMetadataBehavior = app.Services.GetRequiredService<ServiceMetadataBehavior>();
        serviceMetadataBehavior.HttpGetEnabled = true;
        serviceMetadataBehavior.HttpGetUrl = new Uri("http://localhost:8080/CalculatorSample/metadata");

        // Configure CoreWCF endpoints in the ASP.NET Core hosts
        app.UseServiceModel(serviceBuilder =>
        {
            serviceBuilder.AddService<CalculatorSample.CalculatorService>(serviceOptions => 
            {
                serviceOptions.DebugBehavior.IncludeExceptionDetailInFaults = true;
            });

            serviceBuilder.ConfigureServiceHostBase<CalculatorSample.CalculatorService>(serviceHost =>
            {

            });
        });
            
        await app.StartAsync();
        Console.WriteLine("The service is ready.");
        Console.WriteLine("Press <ENTER> to terminate service.");
        Console.WriteLine();
        Console.ReadLine();
        await app.StopAsync();
    }

構成ファイルについては、App.configsystem.serviceModel セクションは、更新中に生成された新しい構成ファイル wcf.config に移動されました。

App.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <!-- system.serviceModel section is moved to a separate wcf.config file located at the same directory as this file.-->
</configuration>

wcf.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.serviceModel>
    <services>
      <service name="CalculatorSample.CalculatorService" behaviorConfiguration="CalculatorServiceBehavior">
        <!--The host element is not supported in configuration in CoreWCF. The port that endpoints listen on is instead configured in the source code.-->
        <!--<host>
  <baseAddresses>
    <add baseAddress="net.tcp://localhost:8090/CalculatorSample/service" />
    <add baseAddress="http://localhost:8080/CalculatorSample/service" />
  </baseAddresses>
</host>-->
        <!-- this endpoint is exposed at the base address provided by host: net.tcp://localhost:8090/CalculatorSample/service  -->
        <endpoint address="/CalculatorSample/service" binding="netTcpBinding" contract="CalculatorSample.ICalculator" />
        <!-- the mex endpoint is exposed at http://localhost:8080/CalculatorSample/service/ -->
        <!--The mex endpoint is removed because it's not support in CoreWCF. Instead, the metadata service is enabled in the source code.-->
      </service>
    </services>
    <!--For debugging purposes set the includeExceptionDetailInFaults attribute to true-->
    <!--The behavior element is not supported in configuration in CoreWCF. Some service behaviors, such as metadata, are configured in the source code.-->
    <!--<behaviors>
  <serviceBehaviors>
    <behavior name="CalculatorServiceBehavior">
      <serviceMetadata httpGetEnabled="True" />
      <serviceDebug includeExceptionDetailInFaults="True" />
    </behavior>
  </serviceBehaviors>
</behaviors>-->
  </system.serviceModel>
</configuration>

最後に、プロジェクト ファイル CalculatorService.csproj では、ASP.NET Core ホストを有効にするために SDK が Microsoft.NET.Sdk.Web に更新され、CoreWCF パッケージ参照が追加されました。

  <ItemGroup>
    <PackageReference Include="System.Configuration.ConfigurationManager" Version="5.0.0" />
    <PackageReference Include="Microsoft.DotNet.UpgradeAssistant.Extensions.Default.Analyzers" Version="0.4.336902">
      <PrivateAssets>all</PrivateAssets>
    </PackageReference>
    <PackageReference Include="CoreWCF.NetTcp" Version="1.1.0" />
    <PackageReference Include="CoreWCF.Primitives" Version="1.1.0" />
    <PackageReference Include="CoreWCF.ConfigurationManager" Version="1.1.0" />
    <PackageReference Include="CoreWCF.Http" Version="1.1.0" />
    <PackageReference Include="CoreWCF.WebHttp" Version="1.1.0" />
  </ItemGroup>

CalculatorSample では、プロジェクト間の依存関係がなくなり、CalculatorService を更新するだけで正常にサンプルを実行できるようになったことに注目してください。 ただし、依存関係が異なる他のケースでは、必要に応じて、同じソリューション内の他のプロジェクトも同様に更新します。

アップグレード後

プロジェクトをアップグレードしたら、それらをコンパイルしてテストする必要があります。 アップグレード アシスタントはできる限りのことを実行しますが、プロジェクト アップグレードの一部としてすべての非互換性を解決できるわけではありません。 たとえば、アプリの .NET Framework バージョンに、プロジェクトで実際に使用されていないライブラリ参照が含まれている可能性があります。 各参照を分析し、それが必要かどうかを判断する必要があります。 また、ツールが、NuGet パッケージ参照を間違ったバージョンに追加またはアップグレードしている可能性もあります。

トラブルシューティングのヒント

.NET アップグレード アシスタントの使用時に発生するおそれがある既知の問題がいくつかあります。 場合によっては、.NET アップグレード アシスタントで内部的に使用される try-convert ツールに問題が発生することがあります。

その他のトラブルシューティングのヒントと既知の問題については、ツールの GitHub リポジトリを参照してください。

関連項目