Microsoft MVP성태의 닷넷 이야기
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
 

같은 컴퓨터에서만 WCF 요청을 서비스하도록 설정


이런 경우가 있죠? 보안상. 단지 한 대의 PC 내부에서만 프로세스끼리 통신해야 할 경우라면 굳이 외부로부터 오는 원격 메서드 호출을 허용해야 할 필요가 없습니다.

이에 대한 해결책을 아래의 글에서 설명해 주고 있습니다.

Securing WCF to only respond to local requests
; http://blogs.msdn.com/phenning/archive/2006/10/31/securing-wcf-to-only-respond-to-local-requests.aspx

오호... 언제나 Default 값으로만 놓고 사용했던 HostNameComparisonMode 값이 여기서 빛을 발하는군요. ^^

config에서 설정해주는 것도 물론 가능합니다. 서버 측은 다음과 같이 설정해 주고,

<services>
  <service
     name="TestWCF.TestService"
     behaviorConfiguration="TestServiceBehavior">
    <host>
      <baseAddresses>
        <add baseAddress="http://127.0.0.1:20000/TestService/"/>
      </baseAddresses>
    </host>
    <endpoint address=""
       binding="basicHttpBinding"
       bindingConfiguration="TestServiceHttpBinding"
       contract="TestWCF.ITestService" />
  </service>
</services>

<bindings>
  <basicHttpBinding>
    <binding name="TestServiceHttpBinding" hostNameComparisonMode="Exact">
      <security mode="None" />
    </binding>
  </basicHttpBinding>
</bindings>

클라이언트 측에서는 다음과 같이 설정해 주면 됩니다.

<client>
  <endpoint address="http://127.0.0.1:20000/TestService/" 
            binding="basicHttpBinding"
            bindingConfiguration="BasicHttpBinding_ITestService" 
            contract="TestWCF.ITestService"
            name="BasicHttpBinding_ITestService" />
</client>

<bindings>
  <basicHttpBinding>
    <binding name="BasicHttpBinding_ITestService" ... >
    </binding>
  </basicHttpBinding>
</bindings>

서버에서 127.0.0.1로 설정되어 있죠? 재미있는 것은 클라이언트 측에서 접속 주소가 "http://localhost:20000"으로 하는 것조차도 막는다는 것입니다. 그래서 이런 경우 다음과 같이 예외를 발생시킵니다.

System.ServiceModel.EndpointNotFoundException was unhandled
  Message="There was no endpoint listening at http://localhost:20000/TestService/ that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details."
  Source="mscorlib"
  StackTrace:
    Server stack trace: 
       at System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebException webException, HttpWebRequest request, HttpAbortReason abortReason)
       at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
       at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
    ... [중간 생략] ...
       at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback(Object state)
  InnerException: System.Net.WebException
       Message="The remote server returned an error: (404) Not Found."
       Source="System"
       StackTrace:
            at System.Net.HttpWebRequest.GetResponse()
            at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
       InnerException: 




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







[최초 등록일: ]
[최종 수정일: 4/11/2022]

Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
by SeongTae Jeong, mailto:techsharer at outlook.com

비밀번호

댓글 작성자
 




... [151]  152  153  154  155  156  157  158  159  160  161  162  163  164  165  ...
NoWriterDateCnt.TitleFile(s)
1274정성태4/17/201221424Phone: 4. "Holiday Calendar" 윈폰 응용 프로그램 등록
1273정성태4/6/201224643Phone: 3. 윈도우 폰을 위한 Holiyday Calendar 앱 개발파일 다운로드1
1272정성태4/5/201226177오류 유형: 151. ASP.NET - EcbGetUnicodeServerVariables 코드에서 System.AccessViolationException 예외 발생
1271정성태4/3/201228861Math: 6. 동전을 여러 더미로 나누는 경우의 수 세기 [1]
1270정성태3/29/201222759오류 유형: 150. Visual Studio 2010 원격 디버깅 오류 - Kerberos authentication failed
1269정성태3/27/201236590오류 유형: 149. ODP.NET 오류 - The provider is not compatible with the version of Oracle client
1268정성태3/27/201233120오류 유형: 148. WCF svc 호출 시 HTTP Error 404.17 - Not Found [1]
1267정성태3/16/201231060.NET Framework: 314. C++의 inline asm 사용을 .NET으로 포팅하는 방법 [1]파일 다운로드1
1266정성태3/14/201234267개발 환경 구성: 149. RAID 1 구성 시 하드 디스크 장애 발생 해결에 대한 경험담
1265정성태3/13/201224624VC++: 61. 아이태니엄(IA64: Itanium) 에서 겪은 C++ 포인터 연산 문제 [2]
1264정성태3/10/201243979.NET Framework: 313. WELL512 난수 발생 알고리즘 - C# [5]파일 다운로드1
1263정성태3/9/201222811개발 환경 구성: 148. tinyget 사용법
1262정성태3/8/201243703개발 환경 구성: 147. .keystore 파일에 저장된 개인키 추출 방법과 인증기관으로부터 온 공개키를 합친 pfx 파일 만드는 방법 [1]
1261정성태3/7/201224410Phone: 2. 개발자용 윈도우 폰 7 기기 등록하는 방법
1260정성태3/6/201224235Phone: 1. 윈도폰 7 개발자 (회사) 등록하는 방법 [3]
1259정성태3/4/201235716Windows: 57. 새로 추가된 네트워크 커널 디버깅 및 PowerShell 3.0 [1]
1258정성태3/3/201237363개발 환경 구성: 146. SQL Server 2012에 포함된 LocalDB 기능 소개 [3]파일 다운로드1
1257정성태3/3/201225564.NET Framework: 312. Native 스레드와 Managed 스레드 개체의 상태 관계 [1]파일 다운로드1
1256정성태3/3/201229091Math: 5. Euler's totient function - C#파일 다운로드1
1255정성태3/3/201231460Math: 4. 소수 판정 및 소인수 분해 소스 코드 - C# [1]파일 다운로드1
1254정성태3/1/201226380Windows: 56. Windows 8 Consumer Preview를 사용해 보고... [1]
1253정성태3/1/201227873VS.NET IDE: 71. Visual Studio 11 Ultimate 베타 설치 [3]
1252정성태3/1/201225246Windows: 55. 윈도우 8 베타 설치 과정 [1]
1251정성태2/27/201229191VC++: 60. C/C++ Native 스레드 콜 스택 덤프를 얻는 공개 라이브러리 [2]파일 다운로드1
1250정성태2/27/201231317VC++: 59. C/C++ 프로젝트 빌드 속도 개선 - UnityBuild를 아세요? [3]
1249정성태2/26/201230984.NET Framework: 311. .NET 스레드 콜 스택 덤프 (5) - ICorDebug 인터페이스 사용법 [2]파일 다운로드3
... [151]  152  153  154  155  156  157  158  159  160  161  162  163  164  165  ...