1

我正在研究封装在 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?

4

1 回答 1

3

您应该能够执行以下操作:

WebRequest.DefaultWebProxy.Credentials = CredentialCache.DefaultCredentials;

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

于 2012-12-10T17:53:35.110 回答