Microsoft MVP성태의 닷넷 이야기
.NET Framework: 74.6. IIS 6.0: 다중 Endpoint 제공 [링크 복사], [링크+제목 복사],
조회: 25054
글쓴 사람
정성태 (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)
13374정성태6/20/20233594오류 유형: 866. 파이썬 - <class 'AttributeError'> module 'flask.json' has no attribute 'JSONEncoder'
13373정성태6/19/20234876오류 유형: 865. 파이썬 - pymssql 설치 관련 오류 정리
13372정성태6/15/20233397개발 환경 구성: 682. SQL Server TLS 통신을 위해 사용되는 키 길이 확인 방법
13371정성태6/15/20233539개발 환경 구성: 681. openssl - 인증서 버전(V1 / V3)
13370정성태6/14/20233672개발 환경 구성: 680. C# - Ubuntu + Microsoft.Data.SqlClient + SQL Server 2008 R2 연결 방법 - TLS 1.2 지원
13369정성태6/13/20233485개발 환경 구성: 679. PyCharm(을 비롯해 JetBrains에 속한 여타) IDE에서 내부 Window들의 탭이 없어진 경우
13368정성태6/13/20233631개발 환경 구성: 678. openssl로 생성한 인증서를 SQL Server의 암호화 인증서로 설정하는 방법
13367정성태6/10/20233827오류 유형: 864. openssl로 만든 pfx 인증서를 Windows Server 2016 이하에서 등록 시 "The password you entered is incorrect" 오류 발생
13366정성태6/10/20233591.NET Framework: 2128. C# - 윈도우 시스템에서 지원하는 암호화 목록(Cipher Suites) 나열파일 다운로드1
13365정성태6/8/20233212오류 유형: 863. MODIFY FILE encountered operating system error 112(failed to retrieve text for this error. Reason: 15105)
13364정성태6/8/20234082.NET Framework: 2127. C# - Ubuntu + Microsoft.Data.SqlClient + SQL Server 2008 R2 연결 방법 [1]
13363정성태6/7/20233658스크립트: 49. 파이썬 - "Transformers (신경망 언어모델 라이브러리) 강좌" - 1장 2절 코드 실행 결과
13362정성태6/1/20233657.NET Framework: 2126. C# - 서버 측의 요청 제어 (Microsoft.AspNetCore.RateLimiting)파일 다운로드1
13361정성태5/31/20233984오류 유형: 862. Facebook - ASP.NET/WebClient 사용 시 graph.facebook.com/me 호출에 대해 403 Forbidden 오류
13360정성태5/31/20233342오류 유형: 861. WSL/docker - failed to start shim: start failed: io.containerd.runc.v2: create new shim socket
13359정성태5/19/20233646오류 유형: 860. Docker Desktop - k8s 초기화 무한 반복한다면?
13358정성태5/17/20234118.NET Framework: 2125. C# - Semantic Kernel의 Semantic Memory 사용 예제 [1]파일 다운로드1
13357정성태5/16/20233935.NET Framework: 2124. C# - Semantic Kernel의 Planner 사용 예제파일 다운로드1
13356정성태5/15/20234265DDK: 10. Device Driver 테스트 설치 관련 오류 (Code 37, Code 31) 및 인증서 관련 정리
13355정성태5/12/20234186.NET Framework: 2123. C# - Semantic Kernel의 ChatGPT 대화 구현 [1]파일 다운로드1
13354정성태5/12/20234310.NET Framework: 2122. C# - "Use Unicode UTF-8 for worldwide language support" 설정을 한 경우, 한글 입력이 '\0' 문자로 처리
13352정성태5/12/20234024.NET Framework: 2121. C# - Semantic Kernel의 대화 문맥 유지파일 다운로드1
13351정성태5/11/20234491VS.NET IDE: 185. Visual Studio - 원격 Docker container 내에 실행 중인 응용 프로그램에 대한 디버깅 [1]
13350정성태5/11/20233793오류 유형: 859. Windows Date and Time - Unable to continue. You do not have permission to perform this task
13349정성태5/11/20234127.NET Framework: 2120. C# - Semantic Kernel의 Skill과 Function 사용 예제파일 다운로드1
13348정성태5/10/20234035.NET Framework: 2119. C# - Semantic Kernel의 "Basic Loading of the Kernel" 예제
1  2  3  4  5  6  7  8  9  10  [11]  12  13  14  15  ...