質問

C#.純3.5、WCFん書のWCF設定でクライアントアプリケーション(サーバの名前のクライアントが接続しまいます。

その方法は、 ConfigurationManager への負荷の設定を記のデータします。

var serviceModelSection = ConfigurationManager.GetSection("system.serviceModel");

が常にnullを返します。

var serviceModelSection = ConfigurationManager.GetSection("appSettings");

コンビニエンスストアでのお支.

の構成部分が存在しています。configが何らかの理由 ConfigurationManager を拒否する負荷の system.ServiceModel ます。

避けたい手動荷重をさせて頂きます。exe.configファイルを使用XPathがう場合、どのようなリゾートといたします。うに思われるビットのhack.

ご意見募集

役に立ちましたか?

解決

<system.serviceModel> 要素は次の設定 グループ, なされるかどうかを設定するできます。 System.ServiceModel.Configuration.ServiceModelSectionGroup.GetSectionGroup() のグループ全体

他のヒント

http://mostlytech.blogspot.com/2007/11/programmatically-enumerate-wcf.html

// Automagically find all client endpoints defined in app.config
ClientSection clientSection = 
    ConfigurationManager.GetSection("system.serviceModel/client") as ClientSection;

ChannelEndpointElementCollection endpointCollection =
    clientSection.ElementInformation.Properties[string.Empty].Value as     ChannelEndpointElementCollection;
List<string> endpointNames = new List<string>();
foreach (ChannelEndpointElement endpointElement in endpointCollection)
{
    endpointNames.Add(endpointElement.Name);
}
// use endpointNames somehow ...

が多くなっております。

そして、自分の書いた文章を探していたん@marxidadのポインタです。

    public static string GetServerName()
    {
        string serverName = "Unknown";

        Configuration appConfig = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
        ServiceModelSectionGroup serviceModel = ServiceModelSectionGroup.GetSectionGroup(appConfig);
        BindingsSection bindings = serviceModel.Bindings;

        ChannelEndpointElementCollection endpoints = serviceModel.Client.Endpoints;

        for(int i=0; i<endpoints.Count; i++)
        {
            ChannelEndpointElement endpointElement = endpoints[i];
            if (endpointElement.Contract == "MyContractName")
            {
                serverName = endpointElement.Address.Host;
            }
        }

        return serverName;
    }

GetSectionGroup()がサポートしないパラメータが設定(framework3.5).

代わりに使用

Configuration config = System.Configuration.ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
ServiceModelSectionGroup group = System.ServiceModel.Configuration.ServiceModelSectionGroup.GetSectionGroup(config);

その他のポスターはこの機能を開発しのURIを指名してのエンドポイントを作成できます。上の評価項目に使用する実際のコンフィグファイルしたときに用いられるデバッグ:

Private Function GetEndpointAddress(name As String) As String
    Debug.Print("--- GetEndpointAddress ---")
    Dim address As String = "Unknown"
    Dim appConfig As Configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None)
    Debug.Print("app.config: " & appConfig.FilePath)
    Dim serviceModel As ServiceModelSectionGroup = ServiceModelSectionGroup.GetSectionGroup(appConfig)
    Dim bindings As BindingsSection = serviceModel.Bindings
    Dim endpoints As ChannelEndpointElementCollection = serviceModel.Client.Endpoints
    For i As Integer = 0 To endpoints.Count - 1
        Dim endpoint As ChannelEndpointElement = endpoints(i)
        Debug.Print("Endpoint: " & endpoint.Name & " - " & endpoint.Address.ToString)
        If endpoint.Name = name Then
            address = endpoint.Address.ToString
        End If
    Next
    Debug.Print("--- GetEndpointAddress ---")
    Return address
End Function
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top