2009-12-15 5 views
3

WCF 서비스와 클라이언트는 바인딩에 대해 동일한 설정 파일에서 동일한 설정을 공유 할 수 있습니까? 즉, 단일 바인딩 섹션을 작성하고 아무 것도 넣을 수 있으며 서비스 및 클라이언트에 적합한지 확인할 수 있습니까?서비스와 클라이언트간에 WCF 설정을 공유하십시오.

더 잘 설명하겠습니다. 이 같은 설정 파일이 있습니다

<services> 
    <service name="TestClass1"> 
    <endpoint binding="basicHttpBinding" address="http://dev00:4322/host1/TestApplication1" contract="myApp.Interface.ITestApplication"/> 
    <endpoint binding="netTcpBinding" bindingConfiguration="Binding1" address="net.tcp://dev00:4321/host1/TestApplication1" contract="myApp.Interface.ITestApplication"/> 
    <endpoint binding="netNamedPipeBinding" address="net.pipe://localhost/host1/TestApplication1" contract="myApp.Interface.ITestApplication"/> 
    </service> 

    <service name="ManagementClass1"> 
    <endpoint binding="netNamedPipeBinding" address="net.pipe://localhost/host1/ManagementApplication1" contract="myApp.Interface.IManagementApplication"/> 
    <endpoint binding="netTcpBinding" bindingConfiguration="Binding1" address="net.tcp://dev00:4321/host1/ManagementApplication1" contract="myApp.Interface.IManagementApplication"/> 
    </service> 
</services> 

<client> 
    <endpoint name="clientTestClass1Tcp" 
     address="net.tcp://dev00:4321/host1/TestApplication1" 
     binding="netTcpBinding" 
     bindingConfiguration="Binding1" 
     contract="myApp.Interface.ITestApplication"/> 

    <endpoint name="clientManagementClass1Tcp" 
     address="net.tcp://dev00:4321/host1/ManagementApplication1" 
     binding="netTcpBinding" 
     bindingConfiguration="Binding1" 
     contract="myApp.Interface.IManagementApplication"/> 
</client> 

<bindings> 
    <netTcpBinding> 
    <binding name="Binding1" 
     closeTimeout="00:00:10" 
     openTimeout="00:00:10" 
     receiveTimeout="00:01:00" 
     sendTimeout="00:01:00" 
     transactionFlow="false" 
     transferMode="Buffered" 
     transactionProtocol="OleTransactions" 
     hostNameComparisonMode="StrongWildcard" 
     listenBacklog="10" 
     maxBufferPoolSize="524288" 
     maxBufferSize="65536" 
     maxConnections="30" 
     maxReceivedMessageSize="65536"> 
     <security mode="None"> 
     <transport clientCredentialType="None" /> 
     </security> 
    </binding> 
    </netTcpBinding> 
</bindings> 

모든 내 통제하에있다. 서비스와 클라이언트간에 바인딩 (및 다른 섹션 ..)을 공유하는 것이 무엇이든간에 서비스와 클라이언트 모두에서 잘 작동하는지 확인할 수 있습니까?

답변

4

예, 할 수 있습니다 - 어느 정도 :

  • 참조 별도의 설정 파일로 바인딩, 행동, 확장 정보를 넣어 클라이언트와 애플리케이션의 서버 부분에서 모두들

e

<?xml version="1.0" encoding="utf-8"?> 
<bindings> 
    <basicHttpBinding> 
    <binding name="Default" useDefaultWebProxy="false"> 
     <security mode="TransportCredentialOnly"> 
     <transport clientCredentialType="Basic" 
        proxyCredentialType="None" realm="" /> 
     </security> 
    </binding> 
    </basicHttpBinding> 
</bindings> 

을 다음 서비스의의 app.config 또는 Web.config의에서 해당 파일을 참조 : bindings.config에 바인딩을 넣어

<system.serviceModel> 
    <bindings configSource="bindings.config" /> 
</system.serviceModel> 

비주얼 스튜디오는 "configSource"에 대해 불평 할 것이다 -하지만 날 믿어, 그것은 작동합니다. 이는 유효성 검사에 사용되는 Visual Studio XML 스키마의 결함이지만 기능은 작동합니다. 이것은 실제로 구성 섹션 (구성 섹션 그룹은 제외)에서 web.config/app.config에서 작동합니다.

<system.serviceModel> 구성 그룹 (클라이언트, 서버, 동작, 확장)의 "하위 섹션"에 대해이 작업을 수행 할 수 있습니다.

마크

-1

예. 다음은 내가 사용하는 (단순화 된) app.config 파일입니다.

0

양방향 코드를 제어하는 ​​또 다른 옵션은 구성 파일에서 읽은 서버의 이름과 별도로 코드에서 전체 구성을 수행하는 것입니다.

그런 다음 클라이언트와 서버 모두에서 어셈블리를 사용할 수 있습니다. 이미 WCF 인터페이스를 정의하기 위해 생성 된 프록시 클래스가 아닌 공유 어셈블리를 사용할 때이 작업이 효과적 일 수 있습니다.

관련 문제