Microsoft MVP성태의 닷넷 이야기
.NET Framework: 74.6. IIS 6.0: 다중 Endpoint 제공 [링크 복사], [링크+제목 복사],
조회: 24977
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
부모글 보이기/감추기
(연관된 글이 2개 있습니다.)

6. IIS 6.0: 다중 Endpoint 제공


일반 EXE 프로세스에서 netTcpBinding과 basicHttpBinding을 제공한 것처럼, IIS 호스팅 환경에서도 그와 동일한 환경을 제공해 줄 수 있습니다. 일단은 WCF의 높은 이상은 그러하지만, 현실적으로 그에 맞는 환경을 제공해 줄 수 있는 것은 IIS 7.0만이 유일합니다. IIS 6.0같은 경우에는 부분적으로 다중 endpoint를 제공해 줄 뿐입니다. 이번 토픽에서는 그에 대해 알아보겠습니다.

IIS 6.0이 지원하는 바인딩 유형은 "Transport" 유형이 "HTTP"인 것만 (따라서, "basicHttpBinding", "wsHttpBinding", "wsDualHttpBinding") 해당이 됩니다. ("Predefined WCF Bindings"를 참고하십시오.) 만약 이에 속하지 않은 - 예를 들어, netTcpBinding 유형 같은 - 바인딩을 IIS 6.0에서 설정하게 되면 다음과 같은 오류 메시지가 발생하게 됩니다.

Could not find a base address that matches scheme net.tcp for the endpoint with binding NetTcpBinding. 
Registered base address schemes are [http,https].

즉, 현재 등록된 주소 형식은 http, https인데, netTcpBinding 유형은 그와 다른 "net.tcp" 주소 형식을 사용하기 때문입니다. IIS 6.0은 이를 지원하지 않지만, IIS 7.0은 새롭게 "Windows Activation Service"라 하여 IIS에서도 다양한 유형의 주소 형식에 대한 바인딩을 제공해 주고 있습니다. 이에 대해서는 다음 토픽에서 좀 더 자세히 알아보도록 하겠습니다.

자... 그럼 아쉬운 대로 이번은 HTTP Transport에 해당하는 Endpoint만을 서비스에 추가하는 예를 들어보겠습니다.



[서버 변경 사항]

1. 예제 코드는 "[WCF 06] WCF 서비스를 IIS에서 호스팅하는 방법" 토픽에 첨부한 WcfSvcHost.zip 것으로 시작하겠습니다.

2. 아래와 같이 Web.config 파일에 wsHttpBinding, wsDualHttpBinding을 추가해 줍니다. 이때, 같은 HTTP Transport를 사용하기 때문에 이에 대한 호출을 구분하기 위해 "address" 속성을 주고 경로를 구분할 수 있는 임의의 값을 줍니다.

<?xml version="1.0"?>

<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
  <system.serviceModel>
    <services>
      <service name="MyService" behaviorConfiguration="returnFaults">
        <endpoint contract="IMyService" binding="basicHttpBinding"/>
        <endpoint contract="IMyService" binding="wsHttpBinding" address="/wsHttp" />
        <endpoint contract="IMyService" binding="wsDualHttpBinding" address="/wsDualHttp" />
        <endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
      </service>
    </services>

    <behaviors>
      <serviceBehaviors>
        <behavior name="returnFaults" >
          <serviceDebug includeExceptionDetailInFaults="true" />
          <serviceMetadata httpGetEnabled="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    
  </system.serviceModel>

  <system.web>
    <compilation debug="true"/>
  </system.web>

</configuration>

3. 마지막으로 확인하기 위해 빌드하고 "http://localhost:7400/WcfSite/Service.svc"로 방문을 해보고 에러가 없는지 확인합니다.




[클라이언트 변경 사항]

1. "basicHttpBinding"의 경우에는 "웹 참조"를 통해서 서비스를 사용할 수 있지만, "wsHttpBinding", "wsDualHttpBinding" 바인딩으로 서비스를 이용하기 위해서는 서비스 프록시 코드를 생성해야 합니다. 따라서, "WebSiteConsumer" 프로젝트를 마우스 오른쪽 버튼으로 누르고 "Add Service Reference..." 메뉴를 선택하여 나오는 창에서 다음과 같이 입력합니다.

서비스 참조 추가

2. 위와 같이 해주면, "WebSiteConsumer" 프로젝트에 "Service References" 폴더가 추가되어 그 하위에 서비스 프록시 코드 파일들이 생성되며, "app.config" 파일에는 다음과 같이 상당한 분량의 환경 설정값이 들어가 있게 됩니다.

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>
        <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
            <section name="WebSiteConsumer.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
        </sectionGroup>
    </configSections>

    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicHttpBinding_IMyService1" ...> </binding>
            </basicHttpBinding>
            <wsDualHttpBinding>
                <binding name="WSDualHttpBinding_IMyService" ...> </binding>
            </wsDualHttpBinding>
            <wsHttpBinding>
                <binding name="WSHttpBinding_IMyService" ...> </binding>
            </wsHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://localhost:7400/WcfSite/Service.svc"
                binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IMyService1"
                contract="WebSiteConsumer.SecureSvc.IMyService" name="BasicHttpBinding_IMyService1" />
            <endpoint address="http://localhost:7400/WcfSite/Service.svc/wsHttp"
                binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IMyService"
                contract="WebSiteConsumer.SecureSvc.IMyService" name="WSHttpBinding_IMyService">
                <identity> ...  </identity>
            </endpoint>
            <endpoint address="http://localhost:7400/WcfSite/Service.svc/wsDualHttp"
                binding="wsDualHttpBinding" bindingConfiguration="WSDualHttpBinding_IMyService"
                contract="WebSiteConsumer.SecureSvc.IMyService" name="WSDualHttpBinding_IMyService">
                <identity> ...  </identity>
            </endpoint>
        </client>
    </system.serviceModel>
    <applicationSettings>
        <WebSiteConsumer.Properties.Settings>
            <setting name="WebSiteConsumer_MySvc_MyService" serializeAs="String">
                <value>http://localhost:7400/WcfSite/Service.svc</value>
            </setting>
        </WebSiteConsumer.Properties.Settings>
    </applicationSettings>
</configuration>

3. 자, 이젠 자동 생성된 프록시 코드를 이용하여 서비스를 사용하는 코드를 작성해야 하는데요. 현재의 "Program.cs" 파일을 보면, "[WCF 06] WCF 서비스를 IIS에서 호스팅하는 방법"을 설명하면서 작성된 아래와 같은 코드가 들어 있을 것입니다.

static void Main(string[] args)
{
  using (MySvc.MyService normalSvc = new WebSiteConsumer.MySvc.MyService())
  {
    Console.WriteLine(normalSvc.MyOperation1("World!"));
  }
}

여기에 서비스 호출 프록시 코드를 이용하여 다음과 같이 코드를 만들 수 있습니다.

  using (SecureSvc.MyServiceClient clnt = new WebSiteConsumer.SecureSvc.MyServiceClient())
  {
    Console.WriteLine(clnt.MyOperation1("test"));
  }   

아쉽게도, 위의 코드로 실행시켜 보면 아래와 같이 오류가 나는 것을 확인할 수 있습니다.

An unhandled exception of type 'System.InvalidOperationException' occurred in System.ServiceModel.dll

Additional information: Could not find endpoint element with name '' 
and contract 'WebSiteConsumer.SecureSvc.IMyService' in the ServiceModel client configuration section. 
This might be because no configuration file was found for your application, 
or because no endpoint element matching this name could be found in the client element.

즉, "basicHttpBinding", "wsDualHttpBinding", "wsHttpBinding" 3가지 바인딩 중에서 어떤 것을 사용해서 서비스를 호출해야 할지 판단할 수 있는 근거가 없어서 위와 같은 오류가 발생하는 것입니다. 이때 특정 바인딩 유형을 지정하기 위해 아래와 같은 app.config 파일의 endpoint 요소의 name 값을 사용할 수 있습니다.

<client>
	<endpoint address="http://localhost:7400/WcfSite/Service.svc"
		... name="BasicHttpBinding_IMyService1" />
	<endpoint address="http://localhost:7400/WcfSite/Service.svc/wsHttp"
		... name="WSHttpBinding_IMyService">
		<identity> ...  </identity>
	</endpoint>
	<endpoint address="http://localhost:7400/WcfSite/Service.svc/wsDualHttp"
		... name="WSDualHttpBinding_IMyService">
		<identity> ...  </identity>
	</endpoint>
</client>

예를 들어, "wsHttpBinding"을 사용해서 서비스에 연결하고 싶다면, 코드에서 "MyServiceClient" 클래스의 생성자에 다음과 같이 줄 수 있습니다.

using (SecureSvc.MyServiceClient clnt = new WebSiteConsumer.SecureSvc.MyServiceClient("WSHttpBinding_IMyService"))
{
	Console.WriteLine(clnt.MyOperation1("test"));
}  

4. 마지막으로 빌드하고, 실행시켜 보면 정상적으로 실행되는 것을 확인할 수 있습니다.



다중 endpoint를 노출하는 서비스에서 특정 바인딩을 지정해서 사용하는 것을 이제서야 살펴보게 되었는데요. 이런 코딩 방법은 "[WCF 03] 웹 서비스와 닷넷 리모팅으로써의 WCF 구현"에서도 동일하게 적용될 수 있습니다.



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

[연관 글]






[최초 등록일: ]
[최종 수정일: 6/22/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)
13613정성태5/1/2024102닷넷: 2253. C# - Video Capture 장치(Camera) 열거 및 지원 포맷 조회파일 다운로드1
13612정성태4/30/202488오류 유형: 902. Visual Studio - error MSB3021: Unable to copy file
13611정성태4/29/2024239닷넷: 2252. C# - GUID 타입 전용의 UnmanagedType.LPStruct - 두 번째 이야기파일 다운로드1
13610정성태4/28/2024354닷넷: 2251. C# - 제네릭 인자를 가진 타입을 생성하는 방법 - 두 번째 이야기
13609정성태4/27/2024479닷넷: 2250. PInvoke 호출 시 참조 타입(class)을 마샬링하는 [IN], [OUT] 특성파일 다운로드1
13608정성태4/26/2024858닷넷: 2249. C# - 부모의 필드/프로퍼티에 대해 서로 다른 자식 클래스 간에 Reflection 접근이 동작할까요?파일 다운로드1
13607정성태4/25/2024978닷넷: 2248. C# - 인터페이스 타입의 다중 포인터를 인자로 갖는 C/C++ 함수 연동
13606정성태4/24/2024967닷넷: 2247. C# - tensorflow 연동 (MNIST 예제)파일 다운로드1
13605정성태4/23/2024960닷넷: 2246. C# - Python.NET을 이용한 파이썬 소스코드 연동파일 다운로드1
13604정성태4/22/2024966오류 유형: 901. Visual Studio - Unable to set the next statement. Set next statement cannot be used in '[Exception]' call stack frames.
13603정성태4/21/20241012닷넷: 2245. C# - IronPython을 이용한 파이썬 소스코드 연동파일 다운로드1
13602정성태4/20/20241003닷넷: 2244. C# - PCM 오디오 데이터를 연속(Streaming) 재생 (Windows Multimedia)파일 다운로드1
13601정성태4/19/20241018닷넷: 2243. C# - PCM 사운드 재생(NAudio)파일 다운로드1
13600정성태4/18/20241035닷넷: 2242. C# - 관리 스레드와 비관리 스레드
13599정성태4/17/2024959닷넷: 2241. C# - WAV 파일의 PCM 사운드 재생(Windows Multimedia)파일 다운로드1
13598정성태4/16/20241006닷넷: 2240. C# - WAV 파일 포맷 + LIST 헤더파일 다운로드2
13597정성태4/15/20241019닷넷: 2239. C# - WAV 파일의 PCM 데이터 생성 및 출력파일 다운로드1
13596정성태4/14/20241129닷넷: 2238. C# - WAV 기본 파일 포맷파일 다운로드1
13595정성태4/13/20241082닷넷: 2237. C# - Audio 장치 열기 (Windows Multimedia, NAudio)파일 다운로드1
13594정성태4/12/20241105닷넷: 2236. C# - Audio 장치 열람 (Windows Multimedia, NAudio)파일 다운로드1
13593정성태4/8/20241104닷넷: 2235. MSBuild - AccelerateBuildsInVisualStudio 옵션
13592정성태4/2/20241257C/C++: 165. CLion으로 만든 Rust Win32 DLL을 C#과 연동
13591정성태4/2/20241226닷넷: 2234. C# - WPF 응용 프로그램에 Blazor App 통합파일 다운로드1
13590정성태3/31/20241095Linux: 70. Python - uwsgi 응용 프로그램이 k8s 환경에서 OOM 발생하는 문제
13589정성태3/29/20241205닷넷: 2233. C# - 프로세스 CPU 사용량을 나타내는 성능 카운터와 Win32 API파일 다운로드1
[1]  2  3  4  5  6  7  8  9  10  11  12  13  14  15  ...