繁体   English   中英

设置WCF应用程序的凭据?

[英]Setting credentials for a WCF application?

我写了一个简单的应用程序,利用WCF在客户端和服务器之间进行通信。 当我在本地运行它工作正常,但是当我在两个不同的盒子上运行服务器和客户端时,我得到以下异常:

Unexpected error occured, while getting the group names from the VDN server
System.ServiceModel.Security.SecurityNegotiationException: The server has rejected the client credentials.
System.Security.Authentication.InvalidCredentialException: The server has rejected the client credentials.
System.ComponentModel.Win32Exception: The logon attempt failed

什么是不被接受的凭证? 我该怎么设置它们?

有没有办法将服务器配置为不需要身份验证? 该应用程序是一个简单的监控应用程序,安全性并不是真正的问题。

很抱歉不是非常具体:该应用程序使用管道代理,并且没有wcf配置文件,因为wcf代码是手动编码的。

我的WCF代码基于本教程中的代码: http//www.switchonthecode.com/tutorials/wcf-tutorial-basic-interprocess-communication

我没有知道从配置生成wcf类直到我写完所有代码之后才是标准的proctice。 现在每当我查看教程/帮助文档时,他们都会使用生成的代码,所有内容都需要更改配置。

我没有带宽(我已经在处理3个项目)用一个使用生成的代码替换我的wcf组件但我确保下次使用wcf时使用代码生成。

这是我在搜索禁用wcf安全/身份验证时找到的解决方案。

来自MSDN

WSHttpBinding b = new WSHttpBinding();

b.Security.Mode = SecurityMode.None;

或者在config中添加以下内容:

<wsHttpBinding>

    <binding name="myBinding">

        <security mode="None" />

    </binding>

</wsHttpBinding>

创建这样的方法......

void SetImpersonation(ref IServiceClient proxy)
{
  proxy.ClientCredentials.Windows.ClientCredential.Domain = "MYDOMAIN";
  proxy.ClientCredentials.Windows.ClientCredential.UserName = "A_USER";
  proxy.ClientCredentials.Windows.ClientCredential.Password = "P4SSW0RD";
}

并在创建新客户端类时调用它。

IServiceClient proxy = new IServiceClient ();
SetImpersonation(ref proxy);

显然,这是将信息设置为特定用户,如果您的代码被反编译,则会产生安全隐患,但它应该适用于您的(无文件配置文件的情况)

如果您使用具有以下安全性的WCF绑定配置:

<transport clientCredentialType="Windows" />

那么您需要在如下代码中创建的WCF实例上显式设置Windows凭据:

'Create an instance of the WCF service      
Dim MyService As New MyWCFServiceClient

'Build credentials object for which this WCF call will be made
MyService.ClientCredentials.Windows.ClientCredential = New System.Net.NetworkCredential("UserName", "Password", "DomainName")

'Call a method on the service
MyService.MyMethod1()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM