簡體   English   中英

在運行時在app.config中設置defaultProxy

[英]Set defaultProxy in app.config at runtime

我正在研究一個在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?

您應該能夠執行以下操作:

WebRequest.DefaultWebProxy.Credentials = CredentialCache.DefaultCredentials;

這會將默認Web代理使用的憑據設置為默認憑據,這應與useDefaultCredentials="true"具有相同的效果。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM