我有一个服务主机,其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配置文件中获取2个参数绑定和端点。
// constructor for the proxy
public SimSessionServiceReferenceProxyObject(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress)
{
....
}
问题是,如何从上面的app.config获取binding
和remoteAddress
值以将其传递给构造函数?考虑remoteAddress将是app.config中所有3个端点的第一个端点。谢谢。
答案 0 :(得分:1)
我使用以下代码来访问终点地址。这可能会对你有所帮助。
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;
}
}