简体   繁体   English

设置WCF应用程序的凭据?

[英]Setting credentials for a WCF application?

I've written a simple Application that utilizes WCF to communicate between client and server. 我写了一个简单的应用程序,利用WCF在客户端和服务器之间进行通信。 When I run it locally it works fine, however when I run the server and client on two different boxes I get the following exception: 当我在本地运行它工作正常,但是当我在两个不同的盒子上运行服务器和客户端时,我得到以下异常:

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

What are the credentials that are not being accepted? 什么是不被接受的凭证? And how can I set them? 我该怎么设置它们?

Is there a way to configure the server to not require authentication? 有没有办法将服务器配置为不需要身份验证? The application is a simple monitoring app to security is not really an issue. 该应用程序是一个简单的监控应用程序,安全性并不是真正的问题。

Sorry about not being very specific: The app uses a pipe proxy and there is no wcf config file as the wcf code is hand coded. 很抱歉不是非常具体:该应用程序使用管道代理,并且没有wcf配置文件,因为wcf代码是手动编码的。

My WCF code is based on the code in this tutorial: http://www.switchonthecode.com/tutorials/wcf-tutorial-basic-interprocess-communication 我的WCF代码基于本教程中的代码: http//www.switchonthecode.com/tutorials/wcf-tutorial-basic-interprocess-communication

I didn't konw it was standard proctice to generate the wcf classes from a config till after I'd finished writing all the code. 我没有知道从配置生成wcf类直到我写完所有代码之后才是标准的proctice。 Now whenever I look at a tutorial/ help doc they use generated code and everything requires changing the config. 现在每当我查看教程/帮助文档时,他们都会使用生成的代码,所有内容都需要更改配置。

I don't have the bandwidth (I'm juggling 3 projects already) to replace my wcf component with one tht uses generated code but I will make sure to use the code generation next time I use wcf. 我没有带宽(我已经在处理3个项目)用一个使用生成的代码替换我的wcf组件但我确保下次使用wcf时使用代码生成。

Here's a solution I found in a search for disabling wcf security/authentication. 这是我在搜索禁用wcf安全/身份验证时找到的解决方案。

From MSDN : 来自MSDN

WSHttpBinding b = new WSHttpBinding();

b.Security.Mode = SecurityMode.None;

or add the following in config: 或者在config中添加以下内容:

<wsHttpBinding>

    <binding name="myBinding">

        <security mode="None" />

    </binding>

</wsHttpBinding>

Create a method like this... 创建这样的方法......

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

and call it when you create the new client class. 并在创建新客户端类时调用它。

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

Obvously, this is setting the information to be a specific user, and has security implications if your code is decompiled, but it should work in your (config file-less scenario) 显然,这是将信息设置为特定用户,如果您的代码被反编译,则会产生安全隐患,但它应该适用于您的(无文件配置文件的情况)

If you are using a WCF binding configuration with the following security: 如果您使用具有以下安全性的WCF绑定配置:

<transport clientCredentialType="Windows" />

then you will need to explicitly set the Windows Credentials on the WCF instance created in code like below: 那么您需要在如下代码中创建的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