4

app.configファイルで定義されたbasicHttpBindingセクションの読み方を理解しようとしています。エンドポイント アドレスと同じように実行しようとしましたが、うまくいきません。これが私のエンドポイントアドレスのやり方です:

private EndpointAddress EndPointAddy
{
    get
    {
        var config = ConfigurationManager.GetSection("system.serviceModel/Client") as ServiceModelSectionGroup;                
        foreach (ChannelEndpointElement endpoint in config.Client.Endpoints)
        {
            Uri address = endpoint.Address;

            if (address != null)
            {
                return new EndpointAddress(address);                         
            }          
        }
        return null;           
    }
}  

これが私が BasicHttpBinding で試したことです

private BasicHttpBinding Binding
{
    get
    {
        var config = ConfigurationManager.GetSection("system.serviceModel/Client") as ServiceModelSectionGroup;
        foreach (ChannelEndpointElement bindings in config.Bindings.BasicHttpBinding)
        {
            string binding = config.Bindings.BasicHttpBinding;

            if (config.Bindings.BasicHttpBinding != null)
            {
                return new BasicHttpBinding(config.Bindings.BasicHttpBinding);
            }
        }
        return null;
    }

ただし、次のようなエラーが表示されます。

「'System.ServiceModel.Configuration.BasicHttpBindingCollectionElement' には 'GetEnumerator' のパブリック定義が含まれていないため、foreach ステートメントはタイプ 'System.ServiceModel.Configuration.BasicHttpBindingCollectionElement' の変数を操作できません」

ChannelEndpointElement を BasicHttpBindingElement に置き換えてみましたが、役に立ちません。endpointAddress と同じ効果が得られるように、これを正しく行う方法がわかりません。

編集: 私はこれを修正したと思っていましたが、私がしたことはエラーを取り除くことだけでした。プログラムをデバッグしようとすると、

System.NullReferenceException: オブジェクト参照がオブジェクトのインスタンスに設定されていません

次の時点で:

foreach (ChannelEndpointElement bindings in config.Bindings.BasicHttpBinding.Bindings)

ただし、この行で失敗しても、その上の行に気付きました:

var config = ConfigurationManager.GetSection("system.serviceModel") as ServiceModelSectionGroup;

もヌルです。何が間違っているのかわかりません。

4

0 に答える 0