.NET 6에서 CoreWCF를 사용하도록 WCF 서버 쪽 프로젝트 업그레이드

Important

이 문서는 Visual Studio용 업그레이드 도우미 확장이 릴리스되기 전에 작성되었으며 레거시 CLI 도구를 사용합니다. 자세한 내용은 레거시 .NET 업그레이드 도우미 사용을 참조하세요.

.NET 업그레이드 도우미는 .NET 6에서 CoreWCF 서비스를 사용하도록 .NET Framework의 기존 WCF 서버 쪽 프로젝트를 업그레이드하는 데 도움이 되는 명령줄 도구입니다. 이 문서는 다음을 제공합니다.

  • 시작하기 전에 알아야 할 사항.
  • .NET Framework의 WCF 서버 쪽 프로젝트에 대해 도구를 실행하는 방법을 보여주는 데모.
  • 문제 해결 팁.

도구를 설치하는 방법에 대한 자세한 내용은 레거시 .NET 업그레이드 도우미 사용을 참조하세요.

시작하기 전에 알아야 할 사항

이 도구는 현재 C# 프로젝트를 지원하며 CoreWCF를 사용하여 자체 호스팅 WCF 서버 쪽 프로젝트를 .NET 6으로 이식합니다.

이 업그레이드에 WCF 프로젝트를 적용하려면 다음 요구 사항을 충족해야 합니다.

  1. System.ServiceModel을 참조하고 새 ServiceHost를 만드는 .cs 파일을 포함합니다.

    WCF 프로젝트에 여러 ServiceHost가 있는 경우 모든 호스트를 동일한 메서드에 만들어야 합니다.

  2. System.ServiceModel 속성을 저장하는 .config 파일을 포함합니다.

도구의 현재 버전은 .svc 파일을 통해 호스트되는 WCF 프로젝트를 지원하지 않습니다.

참고

이 도구에 프로젝트를 적용할 수 없는 경우 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를 선택하여 서비스 프로젝트를 진입점으로 선택합니다.

프로젝트 업그레이드

프로젝트를 선택하면 도구에서 수행할 업그레이드 단계 목록이 나열됩니다.

중요

업그레이드 중인 프로젝트에 따라 이 예제에 나열된 모든 단계가 표시될 수도 있고 표시되지 않을 수도 있습니다.

다음 출력에서는 프로젝트 업그레이드와 관련된 단계를 설명합니다.

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

참고

이 문서의 나머지 부분에는 호출해야 할 중요한 사항이 없는 한, 업그레이드 단계가 명시적으로 표시되지 않습니다. 각 단계의 결과는 계속 표시됩니다.

백업 만들기

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을 선택합니다. 기본 경로 대신 사용자 지정 경로를 선택할 수 있습니다. 업그레이드된 각 프로젝트에 대해 프로젝트의 폴더가 백업 폴더에 복사됩니다. 이 예제에서 CalculatorService 폴더는 백업 단계 중에 CalculatorSample\CalculatorService에서 CalculatorSample.backup\CalculatorService로 복사됩니다.

[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.config 파일 내 system.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 업데이트 프로그램 확장은 미리 보기 릴리스로 제공됩니다. 미리 보기 버전에 대한 피드백이 있는 경우 area:WCF 태그가 있는 업그레이드 도우미 GitHub 리포지토리에서 문제를 엽니다.

업그레이드 도우미는 먼저 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를 사용하지 않거나 문서 시작 부분에 명시된 요구 사항을 충족하지 않음) 로깅 메시지는 적용할 수 없는 파일과 누락된 파일을 설명합니다. 그런 다음, 해당 단계를 건너뛰고 그 다음 단계가 자동으로 시작됩니다.

이 샘플에서는 WCF 업데이트에 CalculatorSample을 적용할 수 있으며, 명령 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 호스트 및 CoreWCF 패키지 참조를 사용하도록 SDK를 Microsoft.NET.Sdk.Web으로 업데이트했습니다.

  <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 리포지토리에는 더 많은 문제 해결 팁과 알려진 문제가 있습니다.

참고 항목