Microsoft MVP성태의 닷넷 이야기
.NET Framework: 74.6. IIS 6.0: 다중 Endpoint 제공 [링크 복사], [링크+제목 복사],
조회: 25048
글쓴 사람
정성태 (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)
13502정성태12/26/20232763닷넷: 2187. C# - 다른 프로세스의 환경변수 읽는 예제파일 다운로드1
13501정성태12/25/20232569개발 환경 구성: 700. WSL + uwsgi - IPv6로 바인딩하는 방법
13500정성태12/24/20232715디버깅 기술: 194. Windbg - x64 가상 주소를 물리 주소로 변환
13498정성태12/23/20233399닷넷: 2186. 한국투자증권 KIS Developers OpenAPI의 C# 래퍼 버전 - eFriendOpenAPI NuGet 패키지
13497정성태12/22/20232715오류 유형: 885. Visual Studiio - error : Could not connect to the remote system. Please verify your connection settings, and that your machine is on the network and reachable.
13496정성태12/21/20232918Linux: 66. 리눅스 - 실행 중인 프로세스 내부의 환경변수 설정을 구하는 방법 (gdb)
13495정성태12/20/20232852Linux: 65. clang++로 공유 라이브러리의 -static 옵션 빌드가 가능할까요?
13494정성태12/20/20233002Linux: 64. Linux 응용 프로그램의 (C++) so 의존성 줄이기(ReleaseMinDependency) - 두 번째 이야기
13493정성태12/19/20233119닷넷: 2185. C# - object를 QueryString으로 직렬화하는 방법
13492정성태12/19/20232786개발 환경 구성: 699. WSL에 nopCommerce 예제 구성
13491정성태12/19/20232527Linux: 63. 리눅스 - 다중 그룹 또는 사용자를 리소스에 권한 부여
13490정성태12/19/20232668개발 환경 구성: 698. Golang - GLIBC 의존을 없애는 정적 빌드 방법
13489정성태12/19/20232437개발 환경 구성: 697. GoLand에서 ldflags 지정 방법
13488정성태12/18/20232384오류 유형: 884. HTTP 500.0 - 명령행에서 실행한 ASP.NET Core 응용 프로그램을 실행하는 방법
13487정성태12/16/20232699개발 환경 구성: 696. C# - 리눅스용 AOT 빌드를 docker에서 수행 [1]
13486정성태12/15/20232509개발 환경 구성: 695. Nuget config 파일에 값 설정/삭제 방법
13485정성태12/15/20232377오류 유형: 883. dotnet build/restore - error : Root element is missing
13484정성태12/14/20232552개발 환경 구성: 694. Windows 디렉터리 경로를 WSL의 /mnt 포맷으로 구하는 방법
13483정성태12/14/20232740닷넷: 2184. C# - 하나의 resource 파일을 여러 프로그램에서 (AOT 시에도) 사용하는 방법파일 다운로드1
13482정성태12/13/20233383닷넷: 2183. C# - eFriend Expert OCX 예제를 .NET Core/5+ Console App에서 사용하는 방법 [2]파일 다운로드1
13481정성태12/13/20232747개발 환경 구성: 693. msbuild - .NET Core/5+ 프로젝트에서 resgen을 이용한 리소스 파일 생성 방법파일 다운로드1
13480정성태12/12/20233121개발 환경 구성: 692. Windows WSL 2 + Chrome 웹 브라우저 설치
13479정성태12/11/20232651개발 환경 구성: 691. WSL 2 (Ubuntu) + nginx 환경 설정
13477정성태12/8/20232887닷넷: 2182. C# - .NET 7부터 추가된 Int128, UInt128 [1]파일 다운로드1
13476정성태12/8/20232722닷넷: 2181. C# - .NET 8 JsonStringEnumConverter의 AOT를 위한 개선파일 다운로드1
13475정성태12/7/20232742닷넷: 2180. .NET 8 - 함수 포인터에 대한 Reflection 정보 조회파일 다운로드1
1  2  3  4  5  [6]  7  8  9  10  11  12  13  14  15  ...