Microsoft MVP성태의 닷넷 이야기
.NET Framework: 74.6. IIS 6.0: 다중 Endpoint 제공 [링크 복사], [링크+제목 복사],
조회: 25047
글쓴 사람
정성태 (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

비밀번호

댓글 작성자
 




... [16]  17  18  19  20  21  22  23  24  25  26  27  28  29  30  ...
NoWriterDateCnt.TitleFile(s)
13248정성태2/7/20234378오류 유형: 841. 리눅스 - [사용자 계정] is not in the sudoers file. This incident will be reported.
13247정성태2/7/20235274VS.NET IDE: 180. Visual Studio - 닷넷 소스 코드 디버깅 중 "Decompile source code"가 동작하는 않는 문제
13246정성태2/6/20234463개발 환경 구성: 664. Hyper-V에 설치한 리눅스 VM의 VHD 크기 늘리는 방법 - 두 번째 이야기
13245정성태2/6/20235075.NET Framework: 2093. C# - PEM 파일을 이용한 RSA 개인키/공개키 설정 방법파일 다운로드1
13244정성태2/5/20234458VS.NET IDE: 179. Visual Studio - External Tools에 Shell 내장 명령어 등록
13243정성태2/5/20235283디버깅 기술: 190. windbg - Win32 API 호출 시점에 BP 거는 방법 [1]
13242정성태2/4/20234730디버깅 기술: 189. ASP.NET Web Application (.NET Framework) 프로젝트의 숨겨진 예외 - System.UnauthorizedAccessException
13241정성태2/3/20234122디버깅 기술: 188. ASP.NET Web Application (.NET Framework) 프로젝트의 숨겨진 예외 - System.IO.FileNotFoundException
13240정성태2/1/20234295디버깅 기술: 187. ASP.NET Web Application (.NET Framework) 프로젝트의 숨겨진 예외 - System.Web.HttpException
13239정성태2/1/20233978디버깅 기술: 186. C# - CacheDependency의 숨겨진 예외 - System.Web.HttpException
13238정성태1/31/20236136.NET Framework: 2092. IIS 웹 사이트를 TLS 1.2 또는 TLS 1.3 프로토콜로만 운영하는 방법
13237정성태1/30/20235842.NET Framework: 2091. C# - 웹 사이트가 어떤 버전의 TLS/SSL을 지원하는지 확인하는 방법
13236정성태1/29/20235269개발 환경 구성: 663. openssl을 이용해 인트라넷 IIS 사이트의 SSL 인증서 생성
13235정성태1/29/20234952개발 환경 구성: 662. openssl - 윈도우 환경의 명령행에서 SAN 적용하는 방법
13234정성태1/28/20236055개발 환경 구성: 661. dnSpy를 이용해 소스 코드가 없는 .NET 어셈블리의 코드를 변경하는 방법 [1]
13233정성태1/28/20237401오류 유형: 840. C# - WebClient로 https 호출 시 "The request was aborted: Could not create SSL/TLS secure channel" 예외 발생
13232정성태1/27/20235030스크립트: 43. uwsgi의 --processes와 --threads 옵션
13231정성태1/27/20234075오류 유형: 839. python - TypeError: '...' object is not callable
13230정성태1/26/20234477개발 환경 구성: 660. WSL 2 내부로부터 호스트 측의 네트워크로 UDP 데이터가 1개의 패킷으로만 제한되는 문제
13229정성태1/25/20235516.NET Framework: 2090. C# - UDP Datagram의 최대 크기
13228정성태1/24/20235653.NET Framework: 2089. C# - WMI 논리 디스크가 속한 물리 디스크의 정보를 얻는 방법 [2]파일 다운로드1
13227정성태1/23/20235256개발 환경 구성: 659. Windows - IP MTU 값을 바꿀 수 있을까요? [1]
13226정성태1/23/20234936.NET Framework: 2088. .NET 5부터 지원하는 GetRawSocketOption 사용 시 주의할 점
13225정성태1/21/20234135개발 환경 구성: 658. Windows에서 실행 중인 소켓 서버를 다른 PC 또는 WSL에서 접속할 수 없는 경우
13224정성태1/21/20234590Windows: 221. Windows - Private/Public/Domain이 아닌 네트워크 어댑터 단위로 방화벽을 on/off하는 방법
13223정성태1/20/20234739오류 유형: 838. RDP 연결 오류 - The two computers couldn't connect in the amount of time allotted
... [16]  17  18  19  20  21  22  23  24  25  26  27  28  29  30  ...