2009-11-17 2 views
1

우리는 구성 속성을 사용하여 WCF 서비스를 제공하는 "프록시"클래스를 만들려고합니다. system.serviceModel 구성 섹션을 재정의 할 수 있습니까?

우리가 app.config 파일에 이러한 속성을 저장할 수 없기 때문에

, 내가 "프록시"그것을 밖으로와는 요청에 따라 모든 데이터를 제공 할 사용자 정의없는 ConfigurationSection을 사용하는 방법을 찾고 있어요. 그렇게하기 위해서는 .NET Framework에서 내 ConfigurationSection을 사용하여 system.serviceModel을로드해야한다고 말할 수 있어야하고, 내가 할 수 있는지 확실하지 않습니다.

아무도 내 가정을 승인하거나 더 나은 경우 아이디어를 제공 할 수 있습니다. WCF 구성 설정이 다른 소스를 사용하면 도움이 될 것입니다. 아래

이 서비스 호스트 객체를 생성하는 방법이다 : 당신이 pls는 예를 들어 아래의 코드를 확인 만들고 코드에서 WCF 서비스를 등록 할 수있는 방법을 찾고 있다면

감사

답변

1

:

ServiceHost host = RegisterService<your_service_interface>(your_service, port, "yout_service_name"); 
host.Open(); 

희망 일을 여기

public static ServiceHost RegisterService<T>(object service, int port, string serviceName) 
{ 
    // Returns a list of ipaddress configuration 
    IPHostEntry ips = Dns.GetHostEntry(Dns.GetHostName()); 

    // Select the first entry. I hope it's this maschines IP 
    IPAddress ipAddress = ips.AddressList[0]; 

    // Create the url that is needed to specify where the service should be started 
    string urlService = "net.tcp://" + ipAddress.ToString() + String.Format(":{0}/{1}", port, serviceName); 

    // Instruct the ServiceHost that the type that is used is a ServiceLibrary.service1 
    ServiceHost host = new ServiceHost(service); 
    // define events if needed 
    //host.Opening += new EventHandler(HostOpeningEvent); 
    //host.Opened += new EventHandler(HostOpenedEvent); 
    //host.Closing += new EventHandler(HostClosingEvent); 
    //host.Closed += new EventHandler(HostClosedEvent); 

    // The binding is where we can choose what transport layer we want to use. HTTP, TCP ect. 
    NetTcpBinding tcpBinding = new NetTcpBinding(); 
    tcpBinding.TransactionFlow = false; 
    tcpBinding.Security.Transport.ProtectionLevel = System.Net.Security.ProtectionLevel.EncryptAndSign; 
    tcpBinding.Security.Transport.ClientCredentialType = TcpClientCredentialType.Windows; 
    tcpBinding.Security.Mode = SecurityMode.None; 

    // Add a endpoint 
    host.AddServiceEndpoint(typeof(T), tcpBinding, urlService); 

    // A channel to describe the service. Used with the proxy scvutil.exe tool 
    ServiceMetadataBehavior metadataBehavior; 
    metadataBehavior = host.Description.Behaviors.Find<ServiceMetadataBehavior>(); 
    if (metadataBehavior == null) 
    { 
     string httpURL = "http://" + ipAddress.ToString() + String.Format(":{0}/{1}", port + 1, serviceName); 

     // This is how I create the proxy object that is generated via the svcutil.exe tool 
     metadataBehavior = new ServiceMetadataBehavior(); 
     metadataBehavior.HttpGetUrl = new Uri(httpURL); 
     metadataBehavior.HttpGetEnabled = true; 
     metadataBehavior.ToString(); 
     host.Description.Behaviors.Add(metadataBehavior); 
    } 
    return host; 
} 

당신이 그것을 사용하는 방법입니다 도움이된다면,