Microsoft MVP성태의 닷넷 이야기
.NET Framework: 289. WindowsFormsHost를 사용하는 XBAP 응용 프로그램 [링크 복사], [링크+제목 복사]
조회: 21758
글쓴 사람
정성태 (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

비밀번호

댓글 작성자
 




[1]  2  3  4  5  6  7  8  9  10  11  12  13  14  15  ...
NoWriterDateCnt.TitleFile(s)
13607정성태4/25/2024200닷넷: 2248.C# - 인터페이스 타입의 다중 포인터를 인자로 갖는 C/C++ 함수 연동
13606정성태4/24/2024219닷넷: 2247. C# - tensorflow 연동 (MNIST 예제)파일 다운로드1
13605정성태4/23/2024481닷넷: 2246. C# - Python.NET을 이용한 파이썬 소스코드 연동파일 다운로드1
13604정성태4/22/2024540오류 유형: 901. Visual Studio - Unable to set the next statement. Set next statement cannot be used in '[Exception]' call stack frames.
13603정성태4/21/2024746닷넷: 2245. C# - IronPython을 이용한 파이썬 소스코드 연동파일 다운로드1
13602정성태4/20/2024820닷넷: 2244. C# - PCM 오디오 데이터를 연속(Streaming) 재생 (Windows Multimedia)파일 다운로드1
13601정성태4/19/2024868닷넷: 2243. C# - PCM 사운드 재생(NAudio)파일 다운로드1
13600정성태4/18/2024902닷넷: 2242. C# - 관리 스레드와 비관리 스레드
13599정성태4/17/2024877닷넷: 2241. C# - WAV 파일의 PCM 사운드 재생(Windows Multimedia)파일 다운로드1
13598정성태4/16/2024904닷넷: 2240. C# - WAV 파일 포맷 + LIST 헤더파일 다운로드2
13597정성태4/15/2024888닷넷: 2239. C# - WAV 파일의 PCM 데이터 생성 및 출력파일 다운로드1
13596정성태4/14/20241077닷넷: 2238. C# - WAV 기본 파일 포맷파일 다운로드1
13595정성태4/13/20241056닷넷: 2237. C# - Audio 장치 열기 (Windows Multimedia, NAudio)파일 다운로드1
13594정성태4/12/20241070닷넷: 2236. C# - Audio 장치 열람 (Windows Multimedia, NAudio)파일 다운로드1
13593정성태4/8/20241088닷넷: 2235. MSBuild - AccelerateBuildsInVisualStudio 옵션
13592정성태4/2/20241226C/C++: 165. CLion으로 만든 Rust Win32 DLL을 C#과 연동
13591정성태4/2/20241201닷넷: 2234. C# - WPF 응용 프로그램에 Blazor App 통합파일 다운로드1
13590정성태3/31/20241081Linux: 70. Python - uwsgi 응용 프로그램이 k8s 환경에서 OOM 발생하는 문제
13589정성태3/29/20241158닷넷: 2233. C# - 프로세스 CPU 사용량을 나타내는 성능 카운터와 Win32 API파일 다운로드1
13588정성태3/28/20241272닷넷: 2232. C# - Unity + 닷넷 App(WinForms/WPF) 간의 Named Pipe 통신 [2]파일 다운로드1
13587정성태3/27/20241172오류 유형: 900. Windows Update 오류 - 8024402C, 80070643
13586정성태3/27/20241340Windows: 263. Windows - 복구 파티션(Recovery Partition) 용량을 늘리는 방법
13585정성태3/26/20241145Windows: 262. PerformanceCounter의 InstanceName에 pid를 추가한 "Process V2"
13584정성태3/26/20241273개발 환경 구성: 708. Unity3D - C# Windows Forms / WPF Application에 통합하는 방법파일 다운로드1
13583정성태3/25/20241489Windows: 261. CPU Utilization이 100% 넘는 경우를 성능 카운터로 확인하는 방법
[1]  2  3  4  5  6  7  8  9  10  11  12  13  14  15  ...