C# WCF 服务 app.config

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18252262/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 11:40:48  来源:igfitidea点击:

WCF Service app.config

c#wcfapp-config

提问by Omri Btian

I'm developing a WCF Service and I'm a little confused about where its consuming its configurations.

我正在开发一个 WCF 服务,我对它在哪里使用它的配置有点困惑。

I have an app.config file in my host application (console application) and in my WCF Service project (came with the template)

我的主机应用程序(控制台应用程序)和我的 WCF 服务项目(模板附带)中有一个 app.config 文件

In run time I can see that configurations from both files are used.

在运行时,我可以看到使用了来自两个文件的配置。

How does it work? Why does the WCF library project (a dll project) contains an app.config file and what is it's purpose?

它是如何工作的?为什么 WCF 库项目(一个 dll 项目)包含一个 app.config 文件,它的用途是什么?

I can really use some clarifications about this ...

我真的可以对此进行一些澄清......

Update

更新

this is the WCF configuration from my app.config in the host application

这是主机应用程序中我的 app.config 中的 WCF 配置

<system.serviceModel>

    <!-- services -->
    <services>
        <service name="Services.CalcService">
            <endpoint address="net.tcp://localhost:8412/MyCalcService"
                      binding="netTcpBinding"
                      bindingConfiguration="MyNetTcpBinding"
                      contract="Contracts.ICalc"/>
        </service>
    </services>

    <!-- bindings -->
    <bindings>
        <netTcpBinding>
            <binding name="MyNetTcpBinding"
                     closeTimeout="00:01:00"
                     openTimeout="00:01:00"
                     receiveTimeout="00:10:00"
                     sendTimeout="00:01:00"
                     transactionFlow="false"
                     transferMode="Streamed"
                     transactionProtocol="OleTransactions"
                     hostNameComparisonMode="StrongWildcard"
                     listenBacklog="10"
                     maxBufferPoolSize="524288"
                     maxBufferSize="65536"
                     maxConnections="10"
                     maxReceivedMessageSize="65536">
                <readerQuotas maxDepth="32"
                              maxStringContentLength="8192"
                              maxArrayLength="16384"
                              maxBytesPerRead="4096"
                              maxNameTableCharCount="16384" />
                <reliableSession ordered="true"
                                 inactivityTimeout="00:10:00"
                                 enabled="false" />
                <security mode="Transport">
                    <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
                </security>
            </binding>
        </netTcpBinding>
    </bindings>

</system.serviceModel>

This is my WCF configuration from my WCF service library

这是我的 WCF 服务库中的 WCF 配置

  <system.serviceModel>
<services>
  <service name="Services.CalcService">
    <endpoint address="" binding="basicHttpBinding" contract="Contracts.ICalc">
      <identity>
        <dns value="localhost" />
      </identity>
    </endpoint>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost:8733/Design_Time_Addresses/Services/CalcService/" />
      </baseAddresses>
    </host>
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior>
      <serviceMetadata httpGetEnabled="True" httpsGetEnabled="True"/>
      <serviceDebug includeExceptionDetailInFaults="False" />
    </behavior>
  </serviceBehaviors>
</behaviors>

Thanks, Omri.

谢谢,暗里。

采纳答案by Darin Dimitrov

How does it work?

它是如何工作的?

Only the configuration file of the host application is used.

仅使用主机应用程序的配置文件。

Why does the WCF library project (a dll project) contains an app.config file

为什么WCF库项目(一个dll项目)包含一个app.config文件

If it is in a class library I guess it's the VS template that added it.

如果它在类库中,我猜是 VS 模板添加了它。

what is it's purpose?

它的目的是什么?

It could be used by the WCF Service Host (WcfSvcHost.exe)when you run the WCF service library with F5 in Visual Studio.

WCF Service Host (WcfSvcHost.exe)在 Visual Studio 中使用 F5 运行 WCF 服务库时可以使用它。