【发布时间】:2011-11-03 08:00:19
【问题描述】:
我有一些使用 WCF 服务的代码。该服务受基本身份验证保护,因此在创建客户端时,我使用以下代码:
BasicHttpBinding httpBinding = new BasicHttpBinding();
httpBinding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
httpBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
httpBinding.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.None;
httpBinding.Security.Transport.Realm = service_realm;
EndpointAddress address = new EndpointAddress(service_address);
Service.ServiceClient client = new Service.ServiceClient(httpBinding, address);
client.ClientCredentials.UserName.UserName = service_username;
client.ClientCredentials.UserName.Password = service_password;
当我从控制台应用程序运行代码时工作正常。但是当我从 Windows 服务运行相同的代码时,会抛出 MessageSecurityException 告诉我我的请求未经授权。出于某种原因,它似乎正在使用当前的 Windows 帐户进行身份验证,因为我自己的帐户确实可以访问该服务。但我不希望它,我希望它使用存储的凭据。我在这里想念什么?
【问题讨论】:
标签: wcf windows-services