C# 如何在代码(不是app.config)中为端点指定Windows身份验证?
我正在尝试运行一个独立的应用程序(即不需要C# 如何在代码(不是app.config)中为端点指定Windows身份验证?,c#,web-services,binding,C#,Web Services,Binding,我正在尝试运行一个独立的应用程序(即不需要app.config)。它使用Web服务,绑定最初位于app.config中,如下所示: <endpoint address="https://svcmysvc.com/ServiceLibrary/LoginScript.svc/LoginScript.svc" binding="basicHttpBinding" bindingConfiguration="LoginScriptEndpoint"
app.config
)。它使用Web服务,绑定最初位于app.config中,如下所示:
<endpoint address="https://svcmysvc.com/ServiceLibrary/LoginScript.svc/LoginScript.svc"
binding="basicHttpBinding" bindingConfiguration="LoginScriptEndpoint"
contract="LoginScriptService.ILoginScript" name="LoginScriptEndpoint" />
<binding name="LoginScriptEndpoint">
<security mode="Transport">
<transport clientCredentialType="Windows" />
</security>
</binding>
我得到以下错误:
HTTP请求未经客户端身份验证方案授权
“匿名”。从服务器接收的身份验证标头为
“谈判,NTLM”
如何确保它使用本地用户的windows凭据?(我认为这就是导致错误的原因。)
BasicHttpsBinding binding = new BasicHttpsBinding();
binding.AllowCookies = true;
binding.MaxBufferPoolSize = 512000;
binding.MaxReceivedMessageSize = 512000;
binding.Security.Mode = BasicHttpsSecurityMode.Transport;
EndpointAddress address = new EndpointAddress("https://svc.mysvc.com/ServiceLibrary/LoginScript.svc/LoginScript.svc");
LoginScriptClient ls = new LoginScriptClient(binding, address);
ls.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;