이 샘플에서는 구성 파일을 사용하여 서비스를 검색 가능하게 만드는 방법을 보여 줍니다.
![]() |
---|
이 샘플은 구성에서 검색을 구현합니다. 코드에서 검색을 구현하는 샘플은 Basic 샘플을 참조하십시오. |
![]() |
---|
컴퓨터에 이 샘플이 이미 설치되어 있을 수도 있습니다. 계속하기 전에 다음(기본) 디렉터리를 확인하십시오.
<InstallDrive>:\WF_WCF_Samples
이 디렉터리가 없으면 Windows Communication Foundation (WCF) and Windows Workflow Foundation (WF) Samples for .NET Framework 4로 이동하여 WCF(Windows Communication Foundation) 및 WF 샘플을 모두 다운로드하십시오. 이 샘플은 다음 디렉터리에 있습니다.
<InstallDrive>:\WF_WCF_Samples\WCF\Basic\Discovery\Configuration
|
서비스 구성
이 샘플의 구성 파일에서는 다음 두 가지 기능을 보여 줍니다.
표준 UdpDiscoveryEndpoint를 통해 서비스를 검색할 수 있게 만듭니다.
서비스의 응용 프로그램 끝점에 대한 검색 관련 정보를 조정하고 표준 끝점의 검색 관련 설정 중 일부를 조정합니다.
검색 가능하도록 설정하려면 서비스의 응용 프로그램 구성 파일에서 다음 두 가지 변경 작업을 수행해야 합니다.
<service>
요소에 검색 끝점을 추가해야 합니다. 이는 표준 UdpDiscoveryEndpoint 끝점으로서, 런타임에서 검색 서비스와 연결하는 시스템 끝점입니다. 검색 서비스는 이 끝점에서 메시지를 수신 대기합니다.<serviceBehaviors>
섹션에<serviceDiscovery>
동작을 추가합니다. 이 동작은 런타임에 서비스를 검색할 수 있게 해 주며, 앞에서 설명한 검색 끝점을 사용하여 검색 Probe 및 Resolve 메시지를 수신 대기합니다. 이 두 가지 항목을 추가하면 서비스를 지정된 검색 끝점에서 검색할 수 있게 됩니다.
이 구성 파일에서는 추가 동작을 수정하여 이러한 간단한 단계 외의 작업도 수행할 수 있습니다. 특정 끝점을 사용하여 검색 관련 정보를 제어할 수 있습니다. 즉, 사용자가 끝점의 검색 가능 여부를 제어할 수 있으며 해당 끝점을 Scopes 및 사용자 지정 XML 메타데이터로 표시할 수도 있습니다. 이렇게 하려면 응용 프로그램 끝점에 behaviorConfiguration
속성을 추가해야 합니다. 이 경우 다음 속성이 응용 프로그램 끝점에 추가됩니다.
behaviorConfiguration="endpointBehaviorConfiguration"
이제 동작 구성 요소를 통해 검색 관련 특성을 제어할 수 있습니다. 이 경우 두 개의 범위가 응용 프로그램 끝점에 추가됩니다.
검색 끝점의 특정 세부 정보를 제어할 수도 있습니다. 이 작업은 StandardEndpointsSection을 통해 수행합니다. 이 샘플에서는 다음 코드 예제와 같이 사용되는 프로토콜 버전을 수정할 뿐 아니라 maxResponseDelay
특성도 추가합니다.
<configuration>
<system.serviceModel>
<services>
<service name="Microsoft.Samples.Discovery.CalculatorService"
behaviorConfiguration="calculatorServiceBehavior">
<endpoint address=""
binding="wsHttpBinding"
contract="Microsoft.Samples.Discovery.ICalculatorService"
behaviorConfiguration="endpointBehaviorConfiguration" />
<endpoint name="udpDiscovery" kind="udpDiscoveryEndpoint" endpointConfiguration="adhocDiscoveryEndpointConfiguration"/> </service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="calculatorServiceBehavior">
<serviceDiscovery/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="endpointBehaviorConfiguration">
<endpointDiscovery>
<scopes>
<add scope="http://www.example.org/calculator"/>
<add scope="ldap:///ou=engineering,o=exampleorg,c=us"/>
</scopes>
</endpointDiscovery>
</behavior>
</endpointBehaviors>
</behaviors>
<standardEndpoints>
<udpDiscoveryEndpoint>
<!-- Specify the discovery protocol version and maxResponseDelay -->
<standardEndpoint name="adhocDiscoveryEndpointConfiguration" discoveryVersion="WSDiscovery11" maxResponseDelay="00:00:00.600" />
</udpDiscoveryEndpoint>
</standardEndpoints>
</system.serviceModel>
</configuration>
클라이언트 구성
클라이언트의 응용 프로그램 구성 파일에서 dynamicEndpoint
형식의 standardEndpoint
는 검색을 활용하는 데 사용됩니다. 클라이언트에서 dynamicEndpoint
를 사용하는 경우 런타임에서는 검색을 자동으로 수행합니다. 검색 중에는 클라이언트가 표준 udpDiscovery 끝점을 사용하여 지정한 계약과 일치하는 서비스를 찾는 discoveryClient
등의 다양한 기본 설정이 사용됩니다. 이 샘플에서는 이 기능을 확장하고, 클라이언트에서 사용하는 FindCriteria뿐 아니라 검색에 사용되는 표준 updDiscoveryEndpoint
의 일부 속성도 수정합니다. 범위, 특정 scopeMatchBy
알고리즘 및 사용자 지정 종료 조건을 사용하도록 FindCriteria를 수정합니다. 또한 이 샘플에서는 클라이언트가 Probe
메시지를 사용하여 XML 요소를 보내는 방법도 보여 줍니다. 마지막으로 다음 구성 파일과 같이 UdpDiscoveryEndpoint에 대해 사용되는 프로토콜 버전 및 UDP 관련 설정 등의 사항을 변경합니다.
<configuration>
<system.serviceModel>
<client>
<!-- Create an endpoint, make kind="dynamicEndpoint" and use the endpointConfiguration to change settings of DynamicEndpoint -->
<endpoint name="calculatorEndpoint"
binding="wsHttpBinding"
contract="ICalculatorService"
kind ="dynamicEndpoint"
endpointConfiguration="dynamicEndpointConfiguration">
</endpoint>
</client>
<standardEndpoints>
<dynamicEndpoint>
<standardEndpoint name="dynamicEndpointConfiguration">
<discoveryClientSettings>
<!-- Controls where the discovery happens. In this case, Probe message is sent over UdpDiscoveryEndpoint. -->
<endpoint kind="udpDiscoveryEndpoint" endpointConfiguration="adhocDiscoveryEndpointConfiguration" />
<!-- Add Scopes, ScopeMatchBy, Extensions and termination criteria in FindCriteria -->
<findCriteria scopeMatchBy="https://schemas.microsoft.com/ws/2008/06/discovery/rfc" duration="00:00:10" maxResults="1">
<scopes>
<add scope="https://www.microsoft.com/building42/floor1"/>
</scopes>
<!-- These extensions are sent from the client to the service as part of the probe message -->
<extensions>
<CustomMetadata>This is custom metadata that is sent to the service along with the client's find request.</CustomMetadata>
</extensions>
</findCriteria>
</discoveryClientSettings>
</standardEndpoint>
</dynamicEndpoint>
<udpDiscoveryEndpoint>
<!-- Specify the discovery protocol version and UDP transport settings. -->
<standardEndpoint name="adhocDiscoveryEndpointConfiguration" discoveryVersion="WSDiscovery11">
<transportSettings duplicateMessageHistoryLength="2048"
maxPendingMessageCount="5"
maxReceivedMessageSize="8192"
maxBufferPoolSize="262144"/>
</standardEndpoint>
</udpDiscoveryEndpoint>
</standardEndpoints>
</system.serviceModel>
이 샘플을 사용하려면
이 샘플에서는 HTTP 끝점을 사용하며, 이 샘플을 실행하려면 적절한 URL ACL을 추가해야 합니다. 자세한 내용은 HTTP 및 HTTPS 구성을 참조하십시오. 높은 권한으로 다음 명령을 실행하면 적절한 ACL이 추가됩니다. 명령이 지정한 대로 작동하지 않는 경우 다음 인수의 도메인과 사용자 이름을 대체할 수 있습니다.
netsh http add urlacl url=http://+:8000/ user=%DOMAIN%\%UserName%
솔루션을 빌드합니다.
빌드 디렉터리에서 서비스 실행 파일을 실행합니다.
클라이언트 실행 파일을 실행합니다. 클라이언트에서 서비스를 찾을 수 있는지 확인합니다.