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

비밀번호

댓글 작성자
 




... 16  17  18  19  20  21  22  23  24  25  26  27  28  29  [30]  ...
NoWriterDateCnt.TitleFile(s)
12881정성태12/17/20217271개발 환경 구성: 618. WSL Ubuntu 20.04에서 파이썬을 위한 uwsgi 설치 방법 (2)
12880정성태12/16/20217062VS.NET IDE: 170. Visual Studio에서 .NET Core/5+ 역어셈블 소스코드 확인하는 방법
12879정성태12/16/202113302오류 유형: 774. Windows Server 2022 + docker desktop 설치 시 WSL 2로 선택한 경우 "Failed to deploy distro docker-desktop to ..." 오류 발생
12878정성태12/15/20218359개발 환경 구성: 617. 윈도우 WSL 환경에서 같은 종류의 리눅스를 다중으로 설치하는 방법
12877정성태12/15/20217036스크립트: 36. 파이썬 - pymysql 기본 예제 코드
12876정성태12/14/20216844개발 환경 구성: 616. Custom Sources를 이용한 Azure Monitor Metric 만들기
12875정성태12/13/20216557스크립트: 35. python - time.sleep(...) 호출 시 hang이 걸리는 듯한 문제
12874정성태12/13/20216573오류 유형: 773. shell script 실행 시 "$'\r': command not found" 오류
12873정성태12/12/20217693오류 유형: 772. 리눅스 - PATH에 등록했는데도 "command not found"가 나온다면?
12872정성태12/12/20217505개발 환경 구성: 615. GoLang과 Python 빌드가 모두 가능한 docker 이미지 만들기
12871정성태12/12/20217616오류 유형: 771. docker: Error response from daemon: OCI runtime create failed
12870정성태12/9/20216174개발 환경 구성: 614. 파이썬 - PyPI 패키지 만들기 (4) package_data 옵션
12869정성태12/8/20218448개발 환경 구성: 613. git clone 실행 시 fingerprint 묻는 단계를 생략하는 방법
12868정성태12/7/20217019오류 유형: 770. twine 업로드 시 "HTTPError: 400 Bad Request ..." 오류 [1]
12867정성태12/7/20216702개발 환경 구성: 612. 파이썬 - PyPI 패키지 만들기 (3) entry_points 옵션
12866정성태12/7/202114076오류 유형: 769. "docker build ..." 시 "failed to solve with frontend dockerfile.v0: failed to read dockerfile ..." 오류
12865정성태12/6/20216761개발 환경 구성: 611. 파이썬 - PyPI 패키지 만들기 (2) long_description, cmdclass 옵션
12864정성태12/6/20215227Linux: 46. WSL 환경에서 find 명령을 사용해 파일을 찾는 방법
12863정성태12/4/20217145개발 환경 구성: 610. 파이썬 - PyPI 패키지 만들기
12862정성태12/3/20215884오류 유형: 768. Golang - 빌드 시 "cmd/go: unsupported GOOS/GOARCH pair linux /amd64" 오류
12861정성태12/3/20218117개발 환경 구성: 609. 파이썬 - "Windows embeddable package"로 개발 환경 구성하는 방법
12860정성태12/1/20216215오류 유형: 767. SQL Server - 127.0.0.1로 접속하는 경우 "Access is denied"가 발생한다면?
12859정성태12/1/202112393개발 환경 구성: 608. Hyper-V 가상 머신에 Console 모드로 로그인하는 방법
12858정성태11/30/20219653개발 환경 구성: 607. 로컬의 USB 장치를 원격 머신에 제공하는 방법 - usbip-win
12857정성태11/24/20217083개발 환경 구성: 606. WSL Ubuntu 20.04에서 파이썬을 위한 uwsgi 설치 방법
12856정성태11/23/20218900.NET Framework: 1121. C# - 동일한 IP:Port로 바인딩 가능한 서버 소켓 [2]
... 16  17  18  19  20  21  22  23  24  25  26  27  28  29  [30]  ...