Sharing WCF settings between service and client

Can WCF sevice and client use the same settings (from the same configuration file) about bindings, etc., whatever? In other words, can I write one section of bindings and insert anything and make sure that it is good for the service and the client?

I will explain better. I have a configuration file similar to this:

<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>

where not everything is under my control. Can I be sure that the sharing of bindings (and other sections ..) between the service and the client, regardless of what is written, everything works well both on the service and on the client?

+3
source share
3 answers

, - :

  • , , .
  • , .

.. bindings.config:

<?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:

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

Visual Studio "configSource", , WORKS. XML- Visual Studio, , . ( ) web.config/app.config.

"" <system.serviceModel> - , , , , .

+4

, , , , .

, ; , ( ) WCF .

0

Yes. It uses the (simplified) app.config file that I use.

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.serviceModel>
        <client>
            <endpoint name="MyServiceClient"
                address="net.pipe://localhost/MyService"
                contract="IMyService"
                binding="netNamedPipeBinding" />
        </client>
        <services>
            <service name="MyService">
                <endpoint name="MyService"
                    address="net.pipe://localhost/MyService"
                    contract="IMyService"
                    binding="netNamedPipeBinding" />
            </service>
        </services>
    </system.serviceModel>
</configuration>
-1
source

Source: https://habr.com/ru/post/1725727/


All Articles