Microsoft MVP성태의 닷넷 이야기
.NET Framework: 74.6. IIS 6.0: 다중 Endpoint 제공 [링크 복사], [링크+제목 복사],
조회: 25053
글쓴 사람
정성태 (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)
13348정성태5/10/20234035.NET Framework: 2119. C# - Semantic Kernel의 "Basic Loading of the Kernel" 예제
13347정성태5/10/20234400.NET Framework: 2118. C# - Semantic Kernel의 Prompt chaining 예제파일 다운로드1
13346정성태5/10/20234246오류 유형: 858. RDP 원격 환경과 로컬 PC 간의 Ctrl+C, Ctrl+V 복사가 안 되는 문제
13345정성태5/9/20235696.NET Framework: 2117. C# - (OpenAI 기반의) Microsoft Semantic Kernel을 이용한 자연어 처리 [1]파일 다운로드1
13344정성태5/9/20236810.NET Framework: 2116. C# - OpenAI API 사용 - 지원 모델 목록 [1]파일 다운로드1
13343정성태5/9/20234700디버깅 기술: 192. Windbg - Hyper-V VM으로 이더넷 원격 디버깅 연결하는 방법
13342정성태5/8/20234561.NET Framework: 2115. System.Text.Json의 역직렬화 시 필드/속성 주의
13341정성태5/8/20234312닷넷: 2114. C# 12 - 모든 형식의 별칭(Using aliases for any type)
13340정성태5/8/20234436오류 유형: 857. Microsoft.Data.SqlClient.SqlException - 0x80131904
13339정성태5/6/20235230닷넷: 2113. C# 12 - 기본 생성자(Primary Constructors)
13338정성태5/6/20234610닷넷: 2112. C# 12 - 기본 람다 매개 변수파일 다운로드1
13337정성태5/5/20235092Linux: 59. dockerfile - docker exec로 container에 접속 시 자동으로 실행되는 코드 적용
13336정성태5/4/20234909.NET Framework: 2111. C# - 바이너리 출력 디렉터리와 연관된 csproj 설정
13335정성태4/30/20234965.NET Framework: 2110. C# - FFmpeg.AutoGen 라이브러리를 이용한 기본 프로젝트 구성 - Windows Forms파일 다운로드1
13334정성태4/29/20234573Windows: 250. Win32 C/C++ - Modal 메시지 루프 내에서 SetWindowsHookEx를 이용한 Thread 메시지 처리 방법
13333정성태4/28/20234068Windows: 249. Win32 C/C++ - 대화창 템플릿을 런타임에 코딩해서 사용파일 다운로드1
13332정성태4/27/20234111Windows: 248. Win32 C/C++ - 대화창을 위한 메시지 루프 사용자 정의파일 다운로드1
13331정성태4/27/20234072오류 유형: 856. dockerfile - 구 버전의 .NET Core 이미지 사용 시 apt update 오류
13330정성태4/26/20233765Windows: 247. Win32 C/C++ - CS_GLOBALCLASS 설명
13329정성태4/24/20234048Windows: 246. Win32 C/C++ - 직접 띄운 대화창 템플릿을 위한 Modal 메시지 루프 생성파일 다운로드1
13328정성태4/19/20233665VS.NET IDE: 184. Visual Studio - Fine Code Coverage에서 동작하지 않는 Fake/Shim 테스트
13327정성태4/19/20234041VS.NET IDE: 183. C# - .NET Core/5+ 환경에서 Fakes를 이용한 단위 테스트 방법
13326정성태4/18/20235560.NET Framework: 2109. C# - 닷넷 응용 프로그램에서 SQLite 사용 (System.Data.SQLite) [1]파일 다운로드1
13325정성태4/18/20234776스크립트: 48. 파이썬 - PostgreSQL의 with 문을 사용한 경우 연결 개체 누수
13324정성태4/17/20234604.NET Framework: 2108. C# - Octave의 "save -binary ..."로 생성한 바이너리 파일 분석파일 다운로드1
13323정성태4/16/20234564개발 환경 구성: 677. Octave에서 Excel read/write를 위한 io 패키지 설치
1  2  3  4  5  6  7  8  9  10  11  [12]  13  14  15  ...