我正在研究一个在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?
答案 0 :(得分:3)
您应该能够执行以下操作:
WebRequest.DefaultWebProxy.Credentials = CredentialCache.DefaultCredentials;
这会将默认Web代理使用的凭据设置为默认凭据,其效果应与useDefaultCredentials="true"
相同。