Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/319.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何从app.config读取端点值并将其传递给客户端的代理类?_C# - Fatal编程技术网

C# 如何从app.config读取端点值并将其传递给客户端的代理类?

C# 如何从app.config读取端点值并将其传递给客户端的代理类?,c#,C#,我有一个服务主机,其app.config如下: <system.serviceModel> <bindings> <netTcpBinding> <binding name="NetTcpBinding_ISimSession" closeTimeout="00:10:00" openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" transaction

我有一个服务主机,其app.config如下:

<system.serviceModel>
 <bindings>
  <netTcpBinding>
    <binding name="NetTcpBinding_ISimSession" closeTimeout="00:10:00" openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions" hostNameComparisonMode="StrongWildcard" listenBacklog="10" maxBufferPoolSize="524288" maxBufferSize="104857600" maxConnections="10" maxReceivedMessageSize="104857600">          
    </binding>

    <binding name="NetTcpBinding_ISimExportImportSession" closeTimeout="00:10:00" openTimeout="00:10:00"
           receiveTimeout="00:10:00" sendTimeout="00:10:00" transactionFlow="false" transferMode="Streamed"
           hostNameComparisonMode="StrongWildcard"
           maxBufferSize="2147483647"
           maxBufferPoolSize="2147483647"
           maxReceivedMessageSize="2147483647">         

    </binding>
  </netTcpBinding>
</bindings>

<services>
  <service name="SimCentral.Server.SimSession">
    <endpoint address="net.tcp://localhost:8732/Design_Time_Addresses/NextGenService/SimSession/" binding="netTcpBinding" bindingConfiguration="NetTcpBinding_ISimSession"
              contract="NextGenServices.Contract.ISimSessionService.ISimSession">
      <identity>
        <dns value=""/>
      </identity>
    </endpoint>
    <endpoint address="net.tcp://localhost:8735/Design_Time_Addresses/NextGenService/SimExportImportSession/" binding="netTcpBinding" bindingConfiguration="NetTcpBinding_ISimExportImportSession"
              contract="NextGenServices.Contract.ISimSessionService.ISimExportImportSession">
      <identity>
        <dns value=""/>
      </identity>
    </endpoint>
    <endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange"/>
    <host>
      <baseAddresses>
        <add baseAddress="net.tcp://localhost:8732/Design_Time_Addresses/NextGenService/SimSession/"/>
      </baseAddresses>
    </host>
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior>

      <serviceMetadata httpGetEnabled="false"/>

      <serviceDebug includeExceptionDetailInFaults="true"/>
    </behavior>
  </serviceBehaviors>
</behaviors>

问题是,我如何从上面的app.config获取
绑定
远程地址
值以将其传递给构造函数?考虑ReloTebug将是App.CONFIG中所有3个端点的第一个端点。谢谢。

我使用以下代码访问端点地址。这可能对你有帮助

string crmAppSvcEndpointAddrTemplate = null;
        var serviceModelClientConfigSection = ConfigurationManager.GetSection("system.serviceModel/client") as ClientSection;
        foreach (ChannelEndpointElement endpoint in serviceModelClientConfigSection.Endpoints)
        {
            if (endpoint.Name == "MyService")
            {
                crmAppSvcEndpointAddrTemplate = endpoint.Address.ToString();
                break;
            }
        }
可能重复的
string crmAppSvcEndpointAddrTemplate = null;
        var serviceModelClientConfigSection = ConfigurationManager.GetSection("system.serviceModel/client") as ClientSection;
        foreach (ChannelEndpointElement endpoint in serviceModelClientConfigSection.Endpoints)
        {
            if (endpoint.Name == "MyService")
            {
                crmAppSvcEndpointAddrTemplate = endpoint.Address.ToString();
                break;
            }
        }