Microsoft MVP성태의 닷넷 이야기
.NET Framework: 289. WindowsFormsHost를 사용하는 XBAP 응용 프로그램 [링크 복사], [링크+제목 복사],
조회: 21767
글쓴 사람
정성태 (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)
12630정성태5/5/20219926사물인터넷: 59. NodeMCU v1 ESP8266 보드의 A0 핀 사용법 - CdS Cell(GL3526) 조도 센서 연동파일 다운로드1
12629정성태5/5/202111680.NET Framework: 1057. C# - CoAP 서버 및 클라이언트 제작 (UDP 소켓 통신) [1]파일 다운로드1
12628정성태5/4/20219641Linux: 39. Eclipse 원격 디버깅 - Cannot run program "gdb": Launching failed
12627정성태5/4/202110361Linux: 38. 라즈베리 파이 제로 용 프로그램 개발을 위한 Eclipse C/C++ 윈도우 환경 설정
12626정성태5/3/202110335.NET Framework: 1056. C# - Thread.Suspend 호출 시 응용 프로그램 hang 현상 (2)파일 다운로드1
12625정성태5/3/20219301오류 유형: 714. error CS5001: Program does not contain a static 'Main' method suitable for an entry point
12624정성태5/2/202113090.NET Framework: 1055. C# - struct/class가 스택/힙에 할당되는 사례 정리 [10]파일 다운로드1
12623정성태5/2/20219722.NET Framework: 1054. C# 9 최상위 문에 STAThread 사용 [1]파일 다운로드1
12622정성태5/2/20216526오류 유형: 713. XSD 파일을 포함한 프로젝트 - The type or namespace name 'TypedTableBase<>' does not exist in the namespace 'System.Data'
12621정성태5/1/202110180.NET Framework: 1053. C# - 특정 레지스트리 변경 시 알림을 받는 방법 [1]파일 다운로드1
12620정성태4/29/202112084.NET Framework: 1052. C# - 왜 구조체는 16 바이트의 크기가 적합한가? [1]파일 다운로드1
12619정성태4/28/202112610.NET Framework: 1051. C# - 구조체의 크기가 16바이트가 넘어가면 힙에 할당된다? [2]파일 다운로드1
12618정성태4/27/202111114사물인터넷: 58. NodeMCU v1 ESP8266 CP2102 Module을 이용한 WiFi UDP 통신 [1]파일 다운로드1
12617정성태4/26/20218831.NET Framework: 1050. C# - ETW EventListener의 Keywords별 EventId에 따른 필터링 방법파일 다운로드1
12616정성태4/26/20218804.NET Framework: 1049. C# - ETW EventListener를 상속받았을 때 초기화 순서파일 다운로드1
12615정성태4/26/20216965오류 유형: 712. Microsoft Live 로그인 - 계정을 선택하는(Pick an account) 화면에서 진행이 안 되는 문제
12614정성태4/24/20219684개발 환경 구성: 570. C# - Azure AD 인증을 지원하는 ASP.NET Core/5+ 웹 애플리케이션 예제 구성 [4]파일 다운로드1
12613정성태4/23/20218719.NET Framework: 1048. C# - ETW 이벤트의 Keywords에 속한 EventId 구하는 방법 (2) 관리 코드파일 다운로드1
12612정성태4/23/20218831.NET Framework: 1047. C# - ETW 이벤트의 Keywords에 속한 EventId 구하는 방법 (1) PInvoke파일 다운로드1
12611정성태4/22/20218060오류 유형: 711. 닷넷 EXE 실행 오류 - Mixed mode assembly is build against version 'v2.0.50727' of the runtime
12610정성태4/22/20217901.NET Framework: 1046. C# - 컴파일 시점에 참조할 수 없는 타입을 포함한 이벤트 핸들러를 Reflection을 이용해 구독하는 방법파일 다운로드1
12609정성태4/22/20219225.NET Framework: 1045. C# - 런타임 시점에 이벤트 핸들러를 만들어 Reflection을 이용해 구독하는 방법파일 다운로드1
12608정성태4/21/202110213.NET Framework: 1044. C# - Generic Host를 이용해 .NET 5로 리눅스 daemon 프로그램 만드는 방법 [9]파일 다운로드1
12607정성태4/21/20218762.NET Framework: 1043. C# - 실행 시점에 동적으로 Delegate 타입을 만드는 방법파일 다운로드1
12606정성태4/21/202112743.NET Framework: 1042. C# - enum 값을 int로 암시적(implicit) 형변환하는 방법? [2]파일 다운로드1
12605정성태4/18/20218732.NET Framework: 1041. C# - AssemblyID, ModuleID를 관리 코드에서 구하는 방법파일 다운로드1
... 31  32  33  34  35  36  37  38  39  [40]  41  42  43  44  45  ...