2016-04-18 14 views
1

サービス参照を追加した後。 App.configファイルでは、このような何かを得る:サービス参照と設定可能なURL

<client> 
     <endpoint address="http://172.31.82.70:8003/TestMatchService/TestMatchService" 
      binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ITestMatchService1" 
      contract="TestMatchServiceV2.ITestMatchService" name="BasicHttpBinding_ITestMatchService1" /> 
    </client> 

私はこのように設定するカスタムアプリケーションを追加したい:

<add key="Server" value="172.31.82.70"/> 

にはどうすればアプリからIPアドレスをピックアップして、エンドポイントを変更することができます設定?

+0

設定ファイルの別のセクションからパラメータを選択することはできません。どうしてそうするか ? –

答えて

1

あなたは、プログラムのエンドポイントを設定することができますので、あなたはただ、これは通常どおりのappSettingsから設定を読み込むと組み合わせるん:

// Read this from your config instead... 
string server = ConfigurationManager.AppSettings["Server"] 
string address = $"http://{server}:8003/TestMatchService/TestMatchService"; 

var binding = new BasicHttpBinding(); 
var endpoint = new EndpointAddress(address); 
var channelFactory = new ChannelFactory<ITestMatchService>(binding, endpoint); 
ITestMatchService client = channelFactory.CreateChannel(); 

あなたは、configファイルのWCFの部分には何も必要はありませんもう

関連する問題