Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting credentials for a WCF application?

Tags:

c#

.net

wcf

I've written a simple Application that utilizes WCF to communicate between client and server. 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.

My WCF code is based on the code in this tutorial: 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. 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.

like image 993
Omar Kooheji Avatar asked May 14 '09 15:05

Omar Kooheji


People also ask

How do I pass credentials to WCF services for Windows authentication?

To configure a service to authenticate its clients using Windows Domain username and passwords use the WSHttpBinding and set its Security. Mode property to Message . In addition you must specify an X509 certificate that will be used to encrypt the username and password as they are sent from the client to the service.


2 Answers

Here's a solution I found in a search for disabling wcf security/authentication.

From MSDN:

WSHttpBinding b = new WSHttpBinding();

b.Security.Mode = SecurityMode.None;

or add the following in config:

<wsHttpBinding>

    <binding name="myBinding">

        <security mode="None" />

    </binding>

</wsHttpBinding>
like image 189
mirezus Avatar answered Nov 07 '22 04:11

mirezus


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)

like image 31
ZombieSheep Avatar answered Nov 07 '22 02:11

ZombieSheep