小编dex*_*ter的帖子

HttpClient和使用代理 - 不断获得407

这是代码:

 HttpClient client = null;
 HttpClientHandler httpClientHandler = new HttpClientHandler()
 {
    Proxy = new WebProxy(string.Format("{0}:{1}", proxyServerSettings.Address, 
    proxyServerSettings.Port),false),
    PreAuthenticate = true,
    UseDefaultCredentials = false,
 };


 this.httpClientHandler.Credentials = new NetworkCredential(proxyServerSettings.UserName, 
                        proxyServerSettings.Password);


 this.client = new HttpClient(this.httpClientHandler);
Run Code Online (Sandbox Code Playgroud)

当我最终这样做时:

HttpResponseMessage httpResponseMessage = this.client.PostAsync(urlToPost, new StringContent(data, Encoding.UTF8, this.mediaType)).Result;
Run Code Online (Sandbox Code Playgroud)

它总是抛出

远程服务器返回错误:(407)需要代理身份验证.

对于我这个世界,我不明白.

在IE10中配置或者我使用HttpWebRequest该类时,相同的代理设置工作正常

.net c# proxy httpclient

45
推荐指数
2
解决办法
6万
查看次数

将参数传递给PowerShell中的scriptblock

我猜你不能这样做:

  $servicePath = $args[0]

  if(Test-Path -path $servicePath) <-- does not throw in here

  $block = {

        write-host $servicePath -foreground "magenta"

        if((Test-Path -path $servicePath)) { <-- throws here.

              dowork 
        }
  }
Run Code Online (Sandbox Code Playgroud)

那么如何将我的变量传递给scriptblock $ block?

powershell scriptblock

40
推荐指数
4
解决办法
7万
查看次数

在WPF中Control.InvokeRequired发生了什么?

我正在编写一个小型WPF应用程序,它会产生一些线程来对网站页面进行压力测试.我想在我从主WPF线程手动启动的线程的状态的wpf形式的文本框中输出一些信息.我有点期望WPF具有相同的功能,只要通过以下方式将我的线程同步回GUI线程:

  if(this.InvokeRequired)
       this.Invoke(ProcessState);
Run Code Online (Sandbox Code Playgroud)

但是WPF中没有任何类型的东西......在WPF中从非gui线程输出的选项是什么?

编辑: 现在的问题似乎是事实,我不能来检查方法CheckAccess()中的Dispatcher我控制的对象.我正在运行.net和VS 2008 SP1的3.5版本.

这是我的Dispatcher Class的完整元数据(F12就可以了):

  using MS.Internal.WindowsBase;
  using System;
  using System.ComponentModel;
  using System.Security;
  using System.Threading;

  namespace System.Windows.Threading
  {
     // Summary:
//     Provides services for managing the queue of work items for a thread.
public sealed class Dispatcher
{
    // Summary:
    //     Gets the System.Windows.Threading.Dispatcher for the thread currently executing
    //     and creates a new System.Windows.Threading.Dispatcher if one is not already
    //     associated with the thread.
    //
    // Returns:
    //     The dispatcher …
Run Code Online (Sandbox Code Playgroud)

.net c# wpf multithreading

21
推荐指数
1
解决办法
2万
查看次数

查找前x天的记录?

如何设置选择过去30天结果的存储过程?

where MONTH(RequestDate) > 6 and DAY(RequestDate) >= 10 
and MONTH(RequestDate) < 21 and DAY(RequestDate) < 7
Run Code Online (Sandbox Code Playgroud)

sql t-sql sql-server

19
推荐指数
1
解决办法
3万
查看次数

使用Linq选择N个随机记录

我有一个包含20多条记录的静态表,我想以随机的方式从该表中选择N(N <20).使用LINQ在代码中执行此操作的最佳方法是什么?

linq-to-sql

17
推荐指数
2
解决办法
2万
查看次数

Active Directory用户密码到期日期.NET/OU组策略

我搜索了该站点以获取信息,并发现: ASP.NET C#Active Directory - 查看用户密码到期之前的时间

它解释了如何根据域策略获取密码何时到期的值.

我的问题是:如果用户的OU组策略具有不同的MaxPasswordAge值,覆盖域组策略中指定的值,该怎么办?如何以编程方式获取OU的组策略对象?

编辑:为了使这个问题更加清晰,我正在添加此编辑.我所追求的是能够告诉用户的密码何时到期.据我所知,日期值可以由域本地策略或组对象策略控制.我有一个Linq2DirectoryService Provider,它将Linq转换为Ldap查询.因此,获取日期到期值的LDAP查询对于此subj将是最佳的.如果你回答包括.net所支持的对象包装器被包含在这个等式中 - 它将是一个死的答案!

c# adsi gpo

12
推荐指数
2
解决办法
3万
查看次数

为什么.net WCF服务需要接口

与asmx实现不同,wcf需要您实现它的接口.我不太明白这种设计背后的原因.接口是两个类之间的契约......说到这一点,你有多少次有2个wcf服务满足相同的接口但实现方式不同?

另一条评论,msdn强烈建议这样做:

   MyService service = new MyService();

   try {

      service.DoWork();

   }
   catch(Exception) {}
   finally {
      service.Close();
   }
Run Code Online (Sandbox Code Playgroud)

所以,假设我要使用它的界面注入我的服务,如下所示:

   public MyComponent : IDisposable
   {

       readonly IMyService service = null;

       public MyComponent(IMyService service) {

           this.service = service;

       }

       public DoWork() 
       {
           //some additional code.
           this.service.DoWork();

       }

       public void Dispose() 
       {
           //The Interface does not have the Close method,
           //So doing this defeats the whole purpose of polymorphysm
           (this.service as MyService).Close(); //Silly.
       }
   } 
Run Code Online (Sandbox Code Playgroud)

你如何利用WCF的界面?

.net polymorphism wcf c#-4.0

12
推荐指数
3
解决办法
1万
查看次数

为什么属性不能作为out参数传递?

例如:

    int? qID= null;

    answer.QuestionID = int.TryParse(lblID.Text, out qID.Value) ? qID : null; //Error: Property or Indexer may not be passed as an out ot ref parameter.
Run Code Online (Sandbox Code Playgroud)

从microsoft文档中可以看出:

"作为out参数传递的变量不需要初始化.但是,必须在方法返回之前为out参数赋值."

然后:

"属性不是变量,不能作为out参数传递.

那么基础.net平台设计中的原因是什么禁止通过out设置对象的属性?out的值也不一定是参考对象 - 使用值类型完全合法.那为什么不呢?

.net c# parameters

11
推荐指数
2
解决办法
5924
查看次数

选择投影中的索引

我希望我的索引从大于0的数字开始,同时执行以下操作:

var dataSource = WebConfigurationHelper.GetSupportedDomainsString().Select((domain, index) => 
new { index , Name = domain });
Run Code Online (Sandbox Code Playgroud)

所以我的输出成为:

index=2 domain=zombieland
index=3 domain=mydomain
Run Code Online (Sandbox Code Playgroud)

有可能吗?

c# linq ienumerable select

11
推荐指数
1
解决办法
5548
查看次数

新构建服务器的问题

移动我的构建服务器后,我收到以下错误:

C:\Windows\Microsoft.NET\Framework64\v3.5\Microsoft.Common.targets (1682): Could not run the "GenerateResource" task because MSBuild could not create or connect to a task host with runtime "CLR2" and architecture "x64". Please ensure that (1) the requested runtime and/or architecture are available on the machine, and (2) that the required executable "MSBuildTaskHost.exe" exists and can be run.

我的配置说:

<ConfigurationToBuild Include="Release|Any CPU">
    <FlavorToBuild>Release</FlavorToBuild>
    <PlatformToBuild>Any CPU</PlatformToBuild>
 </ConfigurationToBuild>
Run Code Online (Sandbox Code Playgroud)

我错过了什么?

64-bit configuration-files visual-studio msbuild-4.0 tfs2012

11
推荐指数
2
解决办法
7945
查看次数