■ 커스텀 바인딩을 사용하는 방법을 보여준다.
[TestServer 프로젝트]
▶ TestCustomBinding.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
using System.ServiceModel.Channels; namespace TestServer { /// <summary> /// 테스트 커스텀 바인딩 /// </summary> public class TestCustomBinding : Binding { //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Private #region Field /// <summary> /// 트랜스포트 /// </summary> private HttpTransportBindingElement transport; /// <summary> /// 인코딩 /// </summary> private BinaryMessageEncodingBindingElement encoding; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 스킴 - Scheme /// <summary> /// 스킴 /// </summary> public override string Scheme { get { return this.transport.Scheme; } } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - TestCustomBinding() /// <summary> /// 생성자 /// </summary> public TestCustomBinding() : base() { this.transport = new HttpTransportBindingElement(); this.encoding = new BinaryMessageEncodingBindingElement(); } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 바인딩 엘리먼트 컬렉션 생성하기 - CreateBindingElements() /// <summary> /// 바인딩 엘리먼트 컬렉션 생성하기 /// </summary> /// <returns>바인딩 엘리먼트 컬렉션</returns> public override BindingElementCollection CreateBindingElements() { BindingElementCollection collection = new BindingElementCollection(); collection.Add(this.encoding); collection.Add(this.transport); return collection; } #endregion } } |
▶ TestCustomBindingCollectionElement.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Configuration; using System.ServiceModel.Channels; using System.ServiceModel.Configuration; namespace TestServer { /// <summary> /// 테스트 커스텀 바인딩 컬렉션 엘리먼트 /// </summary> public class TestCustomBindingCollectionElement : BindingCollectionElement { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 바인딩 타입 - BindingType /// <summary> /// 바인딩 타입 /// </summary> public override Type BindingType { get { return typeof(TestCustomBinding); } } #endregion #region 구성 바인딩 컬렉션 - ConfiguredBindings /// <summary> /// 구성 바인딩 컬렉션 /// </summary> public override ReadOnlyCollection<IBindingConfigurationElement> ConfiguredBindings { get { return new ReadOnlyCollection<IBindingConfigurationElement>(new List<IBindingConfigurationElement>()); } } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 키 포함 여부 구하기 - ContainsKey(name) /// <summary> /// 키 포함 여부 구하기 /// </summary> /// <param name="name">명칭</param> /// <returns>키 포함 여부</returns> public override bool ContainsKey(string name) { throw new NotImplementedException(); } #endregion ////////////////////////////////////////////////////////////////////////////////////////// Protected #region 디폴트 구하기 - GetDefault() /// <summary> /// 디폴트 구하기 /// </summary> /// <returns>바인딩</returns> protected override Binding GetDefault() { return new TestCustomBinding(); } #endregion #region 추가 시도하기 - TryAdd(name, binding, configuration) /// <summary> /// 추가 시도하기 /// </summary> /// <param name="name">명칭</param> /// <param name="binding">바인딩</param> /// <param name="configuration">구성</param> /// <returns>처리 결과</returns> protected override bool TryAdd(string name, Binding binding, Configuration configuration) { throw new NotImplementedException(); } #endregion } } |
▶ App.config
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
<?xml version="1.0" encoding="utf-8" ?> <configuration> <startup> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /> </startup> <system.serviceModel> <behaviors> <serviceBehaviors> <behavior name="mexBehavior"> <serviceMetadata httpGetEnabled="true" /> <serviceDebug includeExceptionDetailInFaults="true" /> </behavior> </serviceBehaviors> </behaviors> <bindings> <customBinding> <binding name="testCustomHttp" sendTimeout="00:10:00" receiveTimeout="00:10:00"> <binaryMessageEncoding /> <httpTransport maxReceivedMessageSize="1262485504" /> </binding> </customBinding> <netTcpBinding> <binding name="netTcp" sendTimeout="00:10:00" receiveTimeout="00:10:00" maxReceivedMessageSize="1262485504" /> </netTcpBinding> </bindings> <services> <service name="TestServer.HelloService" behaviorConfiguration="mexBehavior"> <endpoint address="HelloService" binding="customBinding" bindingConfiguration="testCustomHttp" contract="TestServer.IHelloService" /> <endpoint address="HelloService" binding="netTcpBinding" bindingConfiguration="netTcp" contract="TestServer.IHelloService" /> <host> <baseAddresses> <add baseAddress="http://localhost:8080" /> <add baseAddress="net.tcp://localhost:8090" /> </baseAddresses> </host> </service> </services> <extensions> <bindingExtensions> <add name="testCustomBinding" type="TestServer.TestCustomBindingCollectionElement, CustomBinding, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" /> </bindingExtensions> </extensions> </system.serviceModel> </configuration> |