Microsoft MVP성태의 닷넷 이야기
.NET Framework: 289. WindowsFormsHost를 사용하는 XBAP 응용 프로그램 [링크 복사], [링크+제목 복사],
조회: 21778
글쓴 사람
정성태 (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)
13284정성태3/13/20234142Windows: 226. Win32 C/C++ - Dialog에서 값을 반환하는 방법파일 다운로드1
13283정성태3/12/20233666오류 유형: 852. 파이썬 - TypeError: coercing to Unicode: need string or buffer, NoneType found
13282정성태3/12/20233975Linux: 58. WSL - nohup 옵션이 필요한 경우
13281정성태3/12/20233928Windows: 225. 윈도우 바탕화면의 아이콘들이 넓게 퍼지는 경우 [2]
13280정성태3/9/20234702개발 환경 구성: 670. WSL 2에서 호스팅 중인 TCP 서버를 외부에서 접근하는 방법
13279정성태3/9/20234221오류 유형: 851. 파이썬 ModuleNotFoundError: No module named '_cffi_backend'
13278정성태3/8/20234196개발 환경 구성: 669. WSL 2의 (init이 아닌) systemd 지원 [1]
13277정성태3/6/20234830개발 환경 구성: 668. 코드 사인용 인증서 신청 및 적용 방법(예: Digicert)
13276정성태3/5/20234509.NET Framework: 2102. C# 11 - ref struct/ref field를 위해 새롭게 도입된 scoped 예약어
13275정성태3/3/20234822.NET Framework: 2101. C# 11의 ref 필드 설명
13274정성태3/2/20234369.NET Framework: 2100. C# - ref 필드로 ref struct 타입을 허용하지 않는 이유
13273정성태2/28/20234133.NET Framework: 2099. C# - 관리 포인터로서의 ref 예약어 의미
13272정성태2/27/20234370오류 유형: 850. SSMS - mdf 파일을 Attach 시킬 때 Operating system error 5: "5(Access is denied.)" 에러
13271정성태2/25/20234337오류 유형: 849. Sql Server Configuration Manager가 시작 메뉴에 없는 경우
13270정성태2/24/20233899.NET Framework: 2098. dotnet build에 /p 옵션을 적용 시 유의점
13269정성태2/23/20234514스크립트: 46. 파이썬 - uvicorn의 콘솔 출력을 UDP로 전송
13268정성태2/22/20235045개발 환경 구성: 667. WSL 2 내부에서 열고 있는 UDP 서버를 호스트 측에서 접속하는 방법
13267정성태2/21/20234947.NET Framework: 2097. C# - 비동기 소켓 사용 시 메모리 해제가 finalizer 단계에서 발생하는 사례파일 다운로드1
13266정성태2/20/20234574오류 유형: 848. .NET Core/5+ - Process terminated. Couldn't find a valid ICU package installed on the system
13265정성태2/18/20234486.NET Framework: 2096. .NET Core/5+ - PublishSingleFile 유형에 대한 runtimeconfig.json 설정
13264정성태2/17/20236030스크립트: 45. 파이썬 - uvicorn 사용자 정의 Logger 작성
13263정성태2/16/20234183개발 환경 구성: 666. 최신 버전의 ilasm.exe/ildasm.exe 사용하는 방법
13262정성태2/15/20235227디버깅 기술: 191. dnSpy를 이용한 (소스 코드가 없는) 닷넷 응용 프로그램 디버깅 방법 [1]
13261정성태2/15/20234512Windows: 224. Visual Studio - 영문 폰트가 Fullwidth Latin Character로 바뀌는 문제
13260정성태2/14/20234314오류 유형: 847. ilasm.exe 컴파일 오류 - error : syntax error at token '-' in ... -inf
13259정성태2/14/20234472.NET Framework: 2095. C# - .NET5부터 도입된 CollectionsMarshal
1  2  3  4  5  6  7  8  9  10  11  12  13  [14]  15  ...