Winforms 如何使用NTLM授权方案调用web服务?

Winforms 如何使用NTLM授权方案调用web服务?,winforms,wcf,.net-4.0,tfs,Winforms,Wcf,.net 4.0,Tfs,我不知道如何调用WCF web服务,所以我希望这是一个简单的问题。使用.NET 4 winform客户端调用web服务时,如何将授权方案从匿名更改为NTLM 现在我得到了一个例外:HTTP请求未经授权,客户端身份验证方案为“匿名”。从服务器接收的身份验证标头为“NTLM” 我的目标是构建一个小工具来帮助我监控TFS2010的数据仓库和多维数据集。TFS提供WarehouseControlWebService web服务。登录到服务器后,我可以通过浏览器中的测试模式调用该服务。然而,我试图从桌面远

我不知道如何调用WCF web服务,所以我希望这是一个简单的问题。使用.NET 4 winform客户端调用web服务时,如何将授权方案从匿名更改为NTLM

现在我得到了一个例外:HTTP请求未经授权,客户端身份验证方案为“匿名”。从服务器接收的身份验证标头为“NTLM”

我的目标是构建一个小工具来帮助我监控TFS2010的数据仓库和多维数据集。TFS提供WarehouseControlWebService web服务。登录到服务器后,我可以通过浏览器中的测试模式调用该服务。然而,我试图从桌面远程调用相同的web服务。我的用户帐户位于服务器上的本地管理员组中

我已经创建了一个带有规范按钮1和文本区域1的.NET 4 WinForm。然后,我向web服务添加了一个服务引用,并创造性地将其称为ServiceReference1:

Add Service Reference...
http://tfssvr:8080/tfs/TeamFoundation/Administration/v3.0/WarehouseControlService.asmx
下面是我的代码:

private void button1_Click(object sender, EventArgs e)
{
    // Creating a proxy takes about 3-4 seconds
    var dwSvc = new ServiceReference1.WarehouseControlWebServiceSoapClient();

    // Invoking the method throws an MessageSecurityException
    var dwStatus = dwSvc.GetProcessingStatus(null, null, null);
}
我正在获取System.ServiceModel.Security.MessageSecurityException:

HTTP请求未经客户端身份验证方案“匿名”授权。从服务器接收的身份验证标头为“NTLM”

我已尝试通过以下方式传递我的凭据:

dwSvc.ClientCredentials.Windows.ClientCredential =
    new System.Net.NetworkCredential("user", "pass", "domain");
而且

dwSvc.ClientCredentials.Windows.ClientCredential =
    CredentialCache.DefaultNetworkCredentials;
我正在浏览WCF文档,但是。。。哦,孩子。。。那里有很多。我希望这是件容易的事


提前谢谢。

你看的方向是对的。这是一个很好的页面,提供了一些有关您需要的可用身份验证方法的示例级别信息:。至少该页面应该为您提供更多的线索,以便继续您的工作。

设置您的配置绑定 至安全模式=“TransportCredentialOnly”和传输客户端CredentialType=“Ntlm”



请参见我尝试使用此配置,但是,我们的服务器只能通过https访问,因此我将其替换为
wsHttpBinding
TransportWithMessageCredential
。它不工作,抛出
“HTTP请求未经客户端身份验证方案“匿名”授权。从服务器接收的身份验证标头为“NTLM”。
错误。您对如何使它与
wsHttpBinding
一起工作有什么建议吗?我在VisualStudio2010中得到了这个建议。在新版本的VisualStudio中出现了不同的错误。它们生成不同的配置文件。
<system.serviceModel>
    <bindings>  
        <basicHttpBinding>
            <binding name="WarehouseControlWebServiceSoap" closeTimeout="00:01:00"
                openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
                useDefaultWebProxy="true">
                <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                    maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                <security mode="TransportCredentialOnly">
                    <transport clientCredentialType="Ntlm" proxyCredentialType="None"
                        realm="" />
                    <message clientCredentialType="UserName" algorithmSuite="Default" />
                </security>
            </binding>
        </basicHttpBinding>
    </bindings>
    <client>
        <endpoint address="http://tfsServer:8080/tfs/TeamFoundation/Administration/v3.0/WarehouseControlService.asmx"
            binding="basicHttpBinding" bindingConfiguration="WarehouseControlWebServiceSoap"
            contract="TfsWarehouse.WarehouseControlWebServiceSoap" name="WarehouseControlWebServiceSoap" />
    </client>
</system.serviceModel>