【问题标题】:Set defaultProxy in app.config at runtime在运行时在 app.config 中设置 defaultProxy
【发布时间】:2012-12-10 15:48:44
【问题描述】:

我正在研究封装在 COM-dll 中的 SOAP 客户端。不幸的是,我无法提供 app.config,因此我必须在运行时插入我的值:

        try
        {
            var dataSet = ConfigurationManager.GetSection("system.data") as System.Data.DataSet;
            dataSet.Tables[0].Rows.Add("FirebirdClient Data Provider"
            , ".Net Framework Data Provider for Firebird"
            , "FirebirdSql.Data.FirebirdClient"
            , "FirebirdSql.Data.FirebirdClient.FirebirdClientFactory, FirebirdSql.Data.FirebirdClient, Version=2.6.0.0, Culture=neutral, PublicKeyToken=3750abcc3150b00c");              
        }
        catch
        { }

但我不知道如何在运行时设置默认代理:

<system.net>
  <defaultProxy useDefaultCredentials="true"/>
</system.net>

如果没有此选项,我将无法通过代理进行通信...

BasicHttpBinding basicHttpBinding = new BasicHttpBinding();
EndpointAddress endpointAddress = new EndpointAddress(Adress);

ServiceReference.DataTransferationServiceSoap serviceClient = new ServiceReference.DataTransferationServiceSoapClient(basicHttpBinding, endpointAddress);

serviceClient.doSomething();

如何在运行时设置 useDefaultCredentials?

【问题讨论】:

    标签: c# soap app-config


    【解决方案1】:

    您应该能够做到以下几点:

    WebRequest.DefaultWebProxy.Credentials = CredentialCache.DefaultCredentials;
    

    这会将默认 Web 代理使用的凭据设置为默认凭据,其效果应该与 useDefaultCredentials="true" 相同。

    【讨论】:

    • 完美运行。谢谢你^^
    猜你喜欢
    • 2010-11-02
    • 2018-02-06
    • 2018-01-30
    • 1970-01-01
    • 2011-03-19
    • 2012-02-11
    • 2011-01-01
    • 2010-12-05
    • 2014-03-13
    相关资源
    最近更新 更多