ReliableSession 샘플은 다양한 전송 및 메시지 인코딩 요소, 특히 신뢰할 수 있는 세션을 사용하도록 설정하는 사용자 지정 바인딩을 구성하는 방법을 보여 줍니다. 사용자 지정 바인딩은 개별 바인딩 요소의 순서가 지정된 목록으로 정의됩니다.
샘플 세부 정보
신뢰할 수 있는 세션은 신뢰할 수 있는 메시징 및 세션에 대한 기능을 제공합니다. 신뢰할 수 있는 메시징은 실패 시 통신을 다시 시도하며 메시지의 순서대로 도착과 같은 배달 보증을 지정할 수 있습니다. 세션은 호출 간에 클라이언트의 상태를 유지 관리합니다. 이 샘플은 클라이언트 상태를 유지 관리하기 위한 세션을 구현하고 순서대로 배달 보증을 지정합니다. 샘플은 계산기 서비스를 구현하는 시작 서비스를 기반으로 합니다. 신뢰할 수 있는 세션 기능은 클라이언트 및 서비스에 대한 애플리케이션 구성 파일에서 활성화되고 구성됩니다.
비고
이 샘플에 대한 설정 절차 및 빌드 지침은 이 항목의 끝에 있습니다.
바인딩 요소의 순서는 각각 채널 스택의 레이어를 나타내므로 사용자 지정 바인딩을 정의하는 데 중요 합니다(사용자 지정 바인딩 참조).
샘플에 대한 서비스 구성은 다음 코드 예제와 같이 정의됩니다.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<services>
<service
name="Microsoft.ServiceModel.Samples.CalculatorService"
behaviorConfiguration="CalculatorServiceBehavior">
<!-- This endpoint is exposed at the base address provided by host: http://localhost/servicemodelsamples/service.svc -->
<!-- specify customBinding binding and a binding configuration to use -->
<endpoint address=""
binding="customBinding"
bindingConfiguration="Binding1"
contract="Microsoft.ServiceModel.Samples.ICalculator" />
<!-- The mex endpoint is exposed at http://localhost/servicemodelsamples/service.svc/mex -->
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
<!-- custom binding configuration - configures HTTP transport, reliable sessions -->
<bindings>
<customBinding>
<binding name="Binding1">
<reliableSession />
<security authenticationMode="SecureConversation"
requireSecurityContextCancellation="true">
</security>
<compositeDuplex />
<oneWay />
<textMessageEncoding messageVersion="Soap12WSAddressing10" writeEncoding="utf-8" />
<httpTransport authenticationScheme="Anonymous" bypassProxyOnLocal="false"
hostNameComparisonMode="StrongWildcard"
proxyAuthenticationScheme="Anonymous" realm=""
useDefaultWebProxy="true" />
</binding>
</customBinding>
</bindings>
<!--For debugging purposes set the includeExceptionDetailInFaults attribute to true-->
<behaviors>
<serviceBehaviors>
<behavior name="CalculatorServiceBehavior">
<serviceMetadata httpGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
컴퓨터 간 시나리오에서 실행하는 경우 서비스의 호스트 이름을 반영하도록 클라이언트의 엔드포인트 주소를 변경해야 합니다.
샘플을 실행하면 작업 요청 및 응답이 클라이언트 콘솔 창에 표시됩니다. 클라이언트 창에서 Enter 키를 눌러 클라이언트를 종료합니다.
Add(100,15.99) = 115.99
Subtract(145,76.54) = 68.46
Multiply(9,81.25) = 731.25
Divide(22,7) = 3.14285714285714
Press <ENTER> to terminate client.
샘플을 설정, 빌드 및 실행하려면
다음 명령을 사용하여 ASP.NET 4.0을 설치합니다.
%windir%\Microsoft.NET\Framework\v4.0.XXXXX\aspnet_regiis.exe /i /enable
Windows Communication Foundation 샘플 에 대한One-Time 설정 절차를 수행했는지 확인합니다.
솔루션의 C# 또는 Visual Basic .NET 버전을 빌드하려면 Windows Communication Foundation 샘플빌드의 지침을 따릅니다.
단일 또는 컴퓨터 간 구성에서 샘플을 실행하려면 Windows Communication Foundation 샘플실행의 지침을 따릅니다.
중요합니다
컴퓨터 간 구성에서 클라이언트를 실행하는 경우 다음 예제와 같이
address
특성과 <> 특성 모두에서 "localhost"를 적절한 컴퓨터의 이름으로 바꿔야 합니다.<endpoint name = "" address="http://service_machine_name/servicemodelsamples/service.svc" /> <compositeDuplex clientBaseAddress="http://client_machine_name:8000/myClient/" />