Microsoft MVP성태의 닷넷 이야기
.NET Framework: 289. WindowsFormsHost를 사용하는 XBAP 응용 프로그램 [링크 복사], [링크+제목 복사],
조회: 21770
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
(연관된 글이 1개 있습니다.)

WindowsFormsHost를 사용하는 XBAP 응용 프로그램

질문해 주신 분도 있고 해서, 직접 한번 해보았습니다.

smart client와 xbop, silverlight
; https://www.sysnet.pe.kr/3/0/1017

Visual Studio에서 "WPF Browser Application" 유형의 프로젝트 하나와, "Windows Forms Control Library" 유형의 프로젝트 하나를 각각 생성했습니다. 윈폼 예제 컨트롤은 단순하게 '버튼' 하나만을 담고 있도록 했고, WPF 측에서는 WindowsFormsHost를 이용해서 연결해 두었습니다.

xbap_winform_host_1.png

자... 이렇게 설정하고 "F5" 키를 눌러 디버깅을 시작하면 다음과 같은 오류 메시지가 발생합니다.

System.Windows.Markup.XamlParseException occurred
  Message='The invocation of the constructor on type 'System.Windows.Forms.Integration.WindowsFormsHost' that matches the specified binding constraints threw an exception.' Line number '6' and line position '7'.
  Source=PresentationFramework
  LineNumber=6
  LinePosition=7
  StackTrace:
...[생략]...
  InnerException: System.MethodAccessException
       Message=Attempt by security transparent method 'System.Xaml.Schema.XamlTypeInvoker.CreateInstance(System.Object[])' to access security critical method 'System.Windows.Forms.Integration.WindowsFormsHost..ctor()' failed.

Assembly 'System.Xaml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' is marked with the AllowPartiallyTrustedCallersAttribute, and uses the level 2 security transparency model.  Level 2 transparency causes all methods in AllowPartiallyTrustedCallers assemblies to become security transparent by default, which may be the cause of this exception.
       Source=mscorlib
       StackTrace:
...[생략]...
       InnerException: System.Security.SecurityException
            Message=Request failed.
            Source=mscorlib
            StackTrace:
...[생략]...
            InnerException: 

영락 없이 보안 오류라는 것을 알 수 있는데요. 이를 피하기 위해 WPF 프로젝트의 설정 창에서 "Full trust"를 설정해 줍니다.

xbap_winform_host_2.png

이제 다시 빌드해 주고 "F5" 키를 누르면 일단 개발 상황에서는 정상적으로 실행이 되는 것을 볼 수 있습니다.

자... 그럼 배포까지 마저 해볼까요? 간단하게 Visual Studio 프로젝트 설정에서 "Publish" 메뉴를 이용하면 웹 사이트에 배포해 줄 수 있습니다. 여러분들이 테스트를 할 수 있도록 다음의 경로에 복사를 했으니 직접 실행해 볼 수 있습니다.

XBAP 예제 응용 프로그램
; https://www.sysnet.pe.kr/temp/xbap/example1/WpfBrowserApplication1.xbap

위의 링크를 클릭하면, 다음과 같은 보안 확인 대화상자가 뜨고,

xbap_winform_host_3.png

"Run" 버튼을 클릭해 주니... 제 경우에 다음과 같이 오류 화면이 떴습니다.

xbap_winform_host_4.png

다행히 로그 파일을 확인해 보면 큰 오류는 아닌데요.

Below is a summary of the errors, details of these errors are listed later in the log.
* An exception occurred while downloading the application. Following failure messages were detected:
    + Downloading http://...[URL 경로].../WpfBrowserApplication1.exe did not succeed.
    + The remote server returned an error: (404) Not Found.

확장자 .exe 파일에 대해서 다운로드가 안되도록 보안 설정이 되어 있기 때문인데, 컴퓨터에 URLScan 도구가 설치되어 있어서 그런 오류가 발생한 것입니다. "C:\Windows\System32\inetsrv\urlscan\UrlScan.ini" 파일을 '관리자 권한'으로 실행한 메모장에서 열어 다음의 설정을 주석 처리해 주는 것으로 해결했습니다.

[DenyExtensions]
; Deny executables that could run on the server
; .exe
.bat
.cmd
.com

재차 웹 브라우저로 시도를 해보면... 이번에는 다음과 같은 오류 메시지가 발생하면서 실행이 안됩니다.

xbap_winform_host_5.png

Startup URI: http://...[URL 경로].../WpfBrowserApplication1.xbap
Application Identity: http://...[URL 경로].../WpfBrowserApplication1.xbap#WpfBrowserApplication1.xbap, Version=1.0.0.0, Culture=neutral, PublicKeyToken=ff017c926826c0e1, processorArchitecture=msil/WpfBrowserApplication1.exe, Version=1.0.0.0, Culture=neutral, PublicKeyToken=ff017c926826c0e1, processorArchitecture=msil, type=win32

This application type has been disabled.

이것이 우리가 넘어야 할 마지막 고비입니다. ^^




아래의 글에도 나오지만, "This application type has been disabled."를 해결하는 방법은 다양합니다.

IE9 - XBAPs Disabled in the Internet Zone
; http://blogs.msdn.com/b/ieinternals/archive/2011/03/09/internet-explorer-9-xbap-disabled-in-the-internet-zone.aspx

일단, 위의 메시지는 마이크로소프트가 'Internet Zone'에 해당하는 URL로부터 내려받은 XBAP 응용 프로그램을 '기본적으로' 실행이 안되도록 변경했기 때문입니다.

따라서, XBAP을 호스팅 하는 웹 사이트를 사용자 PC에 "Local intranet" 또는 "Trusted Sites" 중의 하나로 등록을 해주어야 합니다. 가령 아래의 화면은 제 웹 사이트를 "Local intranet"에 등록해 주는 방법을 보여주고 있습니다.

xbap_winform_host_6.png

변경 후, IE를 재시작할 필요 없이 곧바로 다시 방문하면 XBAP 응용 프로그램이 활성화됩니다.

xbap_winform_host_7.png

물론, 실제 환경에서 이런 식으로 사용자로 하여금 등록 과정을 거치도록 하는 것은 꽤나 비현실적인데요. 이런 과정을 프로그램으로 처리하려면 IInternetZoneManager COM 개체에서 제공되는 SetZoneMapping 함수를 사용해 주시면 됩니다.

// From http://www.codeguru.com/forum/showthread.php?t=368335
int _tmain(int argc, _TCHAR* argv[])
{
HRESULT hr;
    IInternetSecurityManager *pSecurityMgr;
    IInternetZoneManager *pZoneMgr;
    LPCWSTR site1 = SysAllocString(L"https://www.sysnet.pe.kr");

    hr = CoCreateInstance(CLSID_InternetSecurityManager, NULL, CLSCTX_INPROC_SERVER, IID_IInternetSecurityManager, (void**)&pSecurityMgr);
    pSecurityMgr->SetZoneMapping((DWORD)2, site1, (DWORD)0); // 2 = Trusted Site, site1 is the URL to add, and 0 is to create the entry.
}

어쩔 수 없습니다. 위와 같은 기능을 포함한 ActiveX를 웹 페이지의 <OBJECT />를 이용해서 미리 실행해 주거나 '관리자 권한'의 클릭원스 프로그램을 실행해서 미리 설정해 주어야만 합니다.

참고로, XBAP 응용 프로그램을 인증서로 서명한 것만으로는 Internet Zone의 웹 사이트에서 활성화시키는 것과는 아무런 관련이 없었습니다. 테스트를 해보면, 응용 프로그램을 다운로드 받기 전에 이미 XBAP을 제한시키기 때문입니다.

그나저나... 직접 해보고 나니, 제목과는 달리 왠지 XBAP 배포 테스트가 주요 내용이 되어 버렸습니다. ^^ (IE 8에서도 역시 위와 같은 방법으로 정상 동작하는 것을 확인했습니다.)

첨부된 파일은 위의 코드를 포함한 예제 프로젝트입니다.




후기 차원에서 기록을 남기면, 개발자 PC에서 이리저리 테스트하다 보면 오류 유형이 다음과 같이 나올 때가 있는데요.

Below is a summary of the errors, details of these errors are listed later in the log.
* An exception occurred while downloading the application. Following failure messages were detected:
+ Unable to install this application because an application with the same identity is already installed. To install this application, either modify the manifest version for this application or uninstall the preexisting application.


아래의 문서에서 소개된 데로,

Clearing the ClickOnce App Cache
; http://www.nerdfurio.us/blog/post.aspx?id=004f104e-da73-df11-949e-001143eed2d5

캐시를 지워주는 것이 필요합니다. 관리자 권한도 필요 없고 그냥 명령행 창에서 rundll32를 실행해 주면 됩니다.

rundll32 dfshim CleanOnlineAppCache




[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]

[연관 글]






[최초 등록일: ]
[최종 수정일: 6/23/2021]

Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
by SeongTae Jeong, mailto:techsharer at outlook.com

비밀번호

댓글 작성자
 




... 31  32  33  34  35  36  37  38  39  40  41  42  [43]  44  45  ...
NoWriterDateCnt.TitleFile(s)
12555정성태3/8/20218961Windows: 190. C# - 레지스트리에 등록된 DigitalProductId로부터 라이선스 키(Product Key)를 알아내는 방법파일 다운로드2
12554정성태3/8/20218785.NET Framework: 1027. 닷넷 응용 프로그램을 위한 PDB 옵션 - full, pdbonly, portable, embedded
12553정성태3/5/20219255개발 환경 구성: 548. 기존 .NET Framework 프로젝트를 .NET Core/5+ 용으로 변환해 주는 upgrade-assistant, try-convert 도구 소개 [4]
12552정성태3/5/20218524개발 환경 구성: 547. github workflow/actions에서 Visual Studio Marketplace 패키지 등록하는 방법
12551정성태3/5/20217427오류 유형: 702. 비주얼 스튜디오 - The 'CascadePackage' package did not load correctly. (2)
12550정성태3/5/20217087오류 유형: 701. Live Share 1.0.3713.0 버전을 1.0.3884.0으로 업데이트 이후 ContactServiceModelPackage 오류 발생하는 문제
12549정성태3/4/20217580오류 유형: 700. VsixPublisher를 이용한 등록 시 다양한 오류 유형 해결책
12548정성태3/4/20218341개발 환경 구성: 546. github workflow/actions에서 nuget 패키지 등록하는 방법
12547정성태3/3/20218896오류 유형: 699. 비주얼 스튜디오 - The 'CascadePackage' package did not load correctly.
12546정성태3/3/20218488개발 환경 구성: 545. github workflow/actions에서 빌드시 snk 파일 다루는 방법 - Encrypted secrets
12545정성태3/2/202111245.NET Framework: 1026. 닷넷 5에 추가된 POH (Pinned Object Heap) [10]
12544정성태2/26/202111466.NET Framework: 1025. C# - Control의 Invalidate, Update, Refresh 차이점 [2]
12543정성태2/26/20219809VS.NET IDE: 158. C# - 디자인 타임(design-time)과 런타임(runtime)의 코드 실행 구분
12542정성태2/20/202112150개발 환경 구성: 544. github repo의 Release 활성화 및 Actions를 이용한 자동화 방법 [1]
12541정성태2/18/20219368개발 환경 구성: 543. 애저듣보잡 - Github Workflow/Actions 소개
12540정성태2/17/20219693.NET Framework: 1024. C# - Win32 API에 대한 P/Invoke를 대신하는 Microsoft.Windows.CsWin32 패키지
12539정성태2/16/20219614Windows: 189. WM_TIMER의 동작 방식 개요파일 다운로드1
12538정성태2/15/20219990.NET Framework: 1023. C# - GC 힙이 아닌 Native 힙에 인스턴스 생성 - 0SuperComicLib.LowLevel 라이브러리 소개 [2]
12537정성태2/11/202111026.NET Framework: 1022. UI 요소의 접근은 반드시 그 UI를 만든 스레드에서! - 두 번째 이야기 [2]
12536정성태2/9/202110024개발 환경 구성: 542. BDP(Bandwidth-delay product)와 TCP Receive Window
12535정성태2/9/20219138개발 환경 구성: 541. Wireshark로 확인하는 LSO(Large Send Offload), RSC(Receive Segment Coalescing) 옵션
12534정성태2/8/20219756개발 환경 구성: 540. Wireshark + C/C++로 확인하는 TCP 연결에서의 closesocket 동작 [1]파일 다운로드1
12533정성태2/8/20219373개발 환경 구성: 539. Wireshark + C/C++로 확인하는 TCP 연결에서의 shutdown 동작파일 다운로드1
12532정성태2/6/20219889개발 환경 구성: 538. Wireshark + C#으로 확인하는 ReceiveBufferSize(SO_RCVBUF), SendBufferSize(SO_SNDBUF) [3]
12531정성태2/5/20218884개발 환경 구성: 537. Wireshark + C#으로 확인하는 PSH flag와 Nagle 알고리듬파일 다운로드1
12530정성태2/4/202113047개발 환경 구성: 536. Wireshark + C#으로 확인하는 TCP 통신의 Receive Window
... 31  32  33  34  35  36  37  38  39  40  41  42  [43]  44  45  ...