2011-02-06 3 views
1

주어진 Endpoint의 주소를 기반으로 가장 기본적인 WCF 바인딩을 생성하기위한 바로 가기가 있습니까?EndpointAddress에서 WCF 바인딩을 만드는 간단한 방법

엔드 포인트 : net.tcp : // localhost를 : 7879/Service.svc

대신 if 문의 큰 블록의

...

Binding binding = null; 

if (endpoint.StartsWith("net.tcp")) 
{ 
    binding = new NetTcpBinding(); 
} 
else if (endpoint.StartWith("http")) 
{ 
    binding = new WsHttpBinding(); 
} 

. 
. 
. 

이 프레임 워크의 라이브러리에있는 바로 가기가 있음 공개적으로 존재하지 않기 때문에 찾을 수 없거나 찾지 못할 수 있습니다.

답변

2

.NET 4의 WCF가 자동으로 수행합니다.이 기능은 기본 끝점이라고합니다. 기사에 초 정도 단락에 관한 A Developer's Introduction to WCF 4

기본 엔드 포인트 :

는 WCF 4의 새로운 여기에 기능에 대한 모든 읽기.

+0

예, 어떻게 그 동작을 모방합니까? –

+0

.NET 4로 업그레이드 할 수 없습니까? 그렇다면 아무것도 모방 할 필요가 없을 것입니다 ... WCF 나 .NET에서 당신이 찾고있는 것을 할 수있는 것을 모릅니다. 만약 당신이'if' 문의 aseries로 살아야 할 것 같아요. .NET 4로 업그레이드 할 수없는 한 오래 –

2

, 그것은 기본 클라이언트 엔드 포인트를 지원하지 않습니다. 불행하게도 (원 캐싱 및 추적 논리를 건너 뛰는) 기본 바인딩을 생성하는 프레임 워크에 의해 사용되는 방법은 내부 있습니다,하지만 난 클라이언트 측에서 사용하도록 다시 구현 그래서 그 뒤에 논리는 간단하다

private static Binding GetBinding(string scheme) 
{ 
    // replace with ConfigurationManager if not running in ASP.NET 
    var configuration = WebConfigurationManager.OpenWebConfiguration(null); 
    var sectionGroup = ServiceModelSectionGroup.GetSectionGroup(configuration); 
    Debug.Assert(sectionGroup != null, "system.serviceModel configuration section is missing."); 
    var mapping = sectionGroup.ProtocolMapping.ProtocolMappingCollection 
           .OfType<ProtocolMappingElement>() 
           .SingleOrDefault(e => e.Scheme == scheme); 
    if (mapping == null) 
     throw new NotSupportedException(string.Format("The URI scheme {0} is not supported.", scheme)); 
    var bindingElement = sectionGroup.Bindings.BindingCollections.Single(e => e.BindingName == mapping.Binding); 
    var binding = (Binding) Activator.CreateInstance(bindingElement.BindingType); 
    var bindingConfiguration = bindingElement.ConfiguredBindings.SingleOrDefault(e => e.Name == mapping.BindingConfiguration); 
    if (bindingConfiguration != null) 
     bindingConfiguration.ApplyConfiguration(binding); 
    return binding; 
} 

없이 모든 구성은이 코드가 질문의 코드와 동일하지만 system.serviceModel/protocolMapping 섹션에서 바인딩을 선택하고 구성 할 수 있습니다.

관련 문제