In this post I will explain how you can build an Windows Communication Foundation web service and client which use a Username and Password combination to authenticate a user. The most difficult action is to create a X509 certificate which is used to encrypt messages passed back and forward to the server.
In this application we will use WCF’s wsHttpBinding and message level security provided by an X509 certificate. The X509 certificate encryption is required by WCF because the client credentials (username/password) are passed as clear text in the SOAP message.
There is one problem that we will face during this series of posts. WCF is reluctant to accept a test certificate, it requires a lot of extra work to get it done. However once you understand the steps that you need to take, you will find it an repetitive but easy task.
I hope you find this post useful. If you have any questions or comments, feel free to post them as reactions on this post. Enjoy!
Generating a Certificate
The first step is to create a test X509 certificate, which is used to encrypt the messages. The certificate will be placed in the ‘My’ folder on the ‘Local Machine’ store under the name ‘MyServerCert’.
To generate the necessary certificate, execute the following command in the windows SDK command line utility:
makecert.exe -sr LocalMachine -ss My -a sha1 -n CN=MyServerCert -sky exchange –pe
Warning: This certificate should be used for testing purposes only.
Setting Up the Service
There are several steps we need to perform on the service, to force it to use username/password validation.
The first step is to implement the validator class which takes the username/password combination and ensures they are correct. First make sure you reference the System.IdentityModel assembly, next create a new class and derive it from System.IdentityModel.Selectors.UserNamePasswordValidator. Now override the Validate function derived from UserNamePasswordValidator.
Now you can write code that checks if the username/password combination is valid, if the combination is not valid throw a System.IdentityModel.Tokens.SecurityTokenException.
Here is my implementation:
public class UsernameValidator: UserNamePasswordValidator
{
public override void Validate(string userName, string password)
{
// validate arguments
if (string.IsNullOrEmpty(userName))
throw new ArgumentNullException("userName");
if (string.IsNullOrEmpty(password))
throw new ArgumentNullException("password");
// check if the user is not test
if (userName != "test" || password != "test")
throw new SecurityTokenException("Unknown username or password");
}
}
The next step is to configure the service to use our custom validator and enforce the username/password client credentials.
First create a new binding with the following configuration:
<bindings> <wshttpbinding> <binding name="mySecureBinding"> <security mode="Message"> <message clientCredentialType="UserName" /> </security> </binding> </wshttpbinding> </bindings>
Notice that the binding enforces message level security and the client has to provide the UserName credentials.
Now that the binding is ready we need to define some behaviour for the service endpoint:
<behaviors> <servicebehaviors> <behavior name="defaultProfile"> <servicecredentials> <servicecertificate findValue="MyServerCert" x509FindType="FindBySubjectName" storeLocation="LocalMachine" storeName="My" /> <usernameauthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="Premotion.Services.UsernameValidator, App_Code" /> </servicecredentials> </behavior> </servicebehaviors> </behaviors>
There are two interesting elements in this section: serviceCertificate and userNameAuthentication. The first specifies the certificate which the service uses to encrypt and decrypt the messages. The second element specifies our custom validator.
Now make sure all your endpoints use the correct binding and behaviour. That’s all for the server!
Modifying the Client
Modifying the client could have been an easy task, if we had accesses to a valid certificate. WCF will not accept the test certificate without a bunch of tricks. First I will pretend the service certificate is valid, then I will explain how to get WCF to accept the test certificate.
The first step is to create a new binding in the application configuration:
<bindings> <wshttpbinding> <binding name="mySecureBinding"> <security mode="Message"> <message clientCredentialType="UserName" /> </security> </binding> </wshttpbinding> </bindings>
This exactly the same binding as we configured the service with.
The next is to set the username/password credentials in code. The following code should be placed next to the code which instantiates the service client:
base.ClientCredentials.UserName.UserName = "test"; base.ClientCredentials.UserName.Password = "test";
That is all. If you have a valid certificate you can run the code, if you have the test certificate perform the steps below to get the code running.
Bypass Certificate Validation
First make sure you reference the System.IdentityModel assembly. The first step is to create a class which validates the certificates and derive it from System.IdentityModel.Selectors.X509CertificateValidator. Override the Validate method. You can leave the implementation empty if you want all the certificates to pass. If you detect a wrong certificate you can throw a System.IdentityModel.Tokens.SecurityTokenValidationException.
Here is my implementation:
public class MyX509Validator: X509CertificateValidator
{
public override void Validate(X509Certificate2 certificate)
{
// validate argument
if (certificate == null)
throw new ArgumentNullException("certificate");
// check if the name of the certifcate matches
if (certificate.SubjectName.Name != "CN=MyServerCert")
throw new SecurityTokenValidationException("Certificated was not issued by thrusted issuer");
}
}
The next step is to create a new endpoint behaviour, which tells WCF to use our custom certificate validator:
<behaviors> <endpointbehaviors> <behavior name="myClientBehavior"> <clientcredentials> <servicecertificate> <authentication certificateValidationMode="Custom" customCertificateValidatorType="Premotion.Services.MyX509Validator,client" /> </servicecertificate> </clientcredentials> </behavior> </endpointbehaviors> </behaviors>
The last step is to set the DNS identity for the endpoint:
<client> <endpoint address="http://localhost:1494/services/coreservice.svc" binding="wsHttpBinding" bindingConfiguration="mySecureBinding" contract="Premotion.Services.ICoreServiceClientContact" name="CoreService" behaviorConfiguration="myClientBehavior"> <identity> <dns value="MyServerCert"/> </identity> </endpoint> </client>
Now everything is finished and you can execute the code.
You can download the sample by clicking here, make sure you create the certificate manually! I hope you gained some insight on how WCF works with username/password authentication. Thank you for reading, if you have any questions or comments post them.
74 Replies to “WCF Username Authentication”
October 17th, 2007 at 19:12
When I ran your makecert command I got the following error:
Can’t create the key of the subject (‘JoeSoft’)
please help!
October 17th, 2007 at 19:51
Hello Seba Gomez, have you tried co create the certificate with a different name? The certificate might already exists. Furthermore take a look at Microsoft’s MakeCert documentation, you might find more information there.
If you still can’t generate the certificate, feel free to ask again.
Good luck!
November 19th, 2007 at 06:19
Hi,
As we have SSL security in our prod website, it seems to me we should use transport security with user name & password. What is the difference of that with message security and how we can implement transport security?
Thanks,
Masoud
November 19th, 2007 at 09:28
Hello Masoud,
I think you can just skip the code mentioned in the section ‘Bypass Certificate Validation’. I am not sure though, please check the MSDN documentation for further details.
Greetings
April 6th, 2008 at 17:30
Great article.
I wonder if you could clear up a security problem I have, here’s the scenario:
- HTTP based WCF service hosted using IIS.
- Lot’s of client applications, ranging from Win Apps to Web Apps (ASP, PHP, etc) to BizTalk apps.
One of the business requirements is to log who is calling the service methods, and some of the methods will require role based security.
How can I securely pass the username and password to the service for authentication without adding them as parameters to every method? Will I always require a certificate?
May 8th, 2008 at 17:31
Is there any way I can have the complete source code of this article?
Thanks
May 8th, 2008 at 18:21
@MH
There is a link in the text which you can use to download the sample application or use: http://www.devatwork.nl/wp-content/uploads/wcfusername.zip.
May 8th, 2008 at 18:23
@Stuart
Sorry for the very late response to your question but nevertheless here is my answer: There is no easy way of bypassing the WPF certificate requirement. You can get around it if you write your own binding but that is complex. I hope this answer was useful to you.
May 9th, 2008 at 06:52
Bert Thanks for your response. I have another question. I have this very simple Service and Client… where I am using “wsHttpBinding” and clientCredentialType=”UserName” in the config file. Basically passing user name and password from Client side and want to capture it on the Service side. And, I am getting the following error message. Any idea what it means? Thanks a lot
Error Message:
SOAP security negotiation with ‘http://localhost:53843/WCFService5/Service.svc‘ for target ‘http://localhost:53843/WCFService5/Service.svc‘ failed. See inner exception for more details.
May 9th, 2008 at 07:53
@MH
The error message doesn’t give a clue but it suggests that it has an inner exception which contains more details. Could you look at the inner exception and give me its message and type? Maybe then I can tell you what the error is about.
May 9th, 2008 at 15:40
Thanks Bert. I am new in this kind of development. Here is the inner exception:
The X.509 certificate CN=ServerSide chain building failed. The certificate that was used has a trust chain that cannot be verified. Replace the certificate or change the certificateValidationMode. A certificate chain processed, but terminated in a root certificate which is not trusted by the trust provider.\r\n”}
May 10th, 2008 at 01:25
I think I figured it out….
May 11th, 2008 at 21:41
Ok great, let me know if you need more help!
May 23rd, 2008 at 03:53
I’m getting the same error as MH Says. Anyone know the solution around this issue? I’m hosting my service in a console app for now, but will be moving to a windows service. I’m also using wsDualHttpBinding, if that makes a difference.
Thanks!
May 23rd, 2008 at 15:11
I’ve gotten it to work. When I was constructing my service proxy on the client, I was using an overload that allows me to specify the endpoint address. I want to store that in a config file. If I used the format:
fc = new FIXServiceClient.FIX.FIXClient(new System.ServiceModel.InstanceContext(fn), new System.ServiceModel.WSDualHttpBinding(“wsHttp”),
new System.ServiceModel.EndpointAddress(uri));
This caused the above exception. The clue to solving this was that my custom X509 certificate validator would not get called. If I use the format of:
fc = new FIXServiceClient.FIX.FIXClient(new System.ServiceModel.InstanceContext(fn), “wsHttp”);
All works fine. However, I really want to specify the endpoint address from config file. When I use the format:
fc = new FIXServiceClient.FIX.FIXClient(new System.ServiceModel.InstanceContext(fn), “wsHttp”, uri);
It ignores the endpoint behavior and throws an excpetion. I did finally get it all to work with:
System.ServiceModel.EndpointAddress endpointAddress = new System.ServiceModel.EndpointAddress(new Uri(uri),
System.ServiceModel.EndpointIdentity.CreateDnsIdentity(“MYCACert”),
new System.ServiceModel.Channels.AddressHeaderCollection());
fc = new FIXServiceClient.FIX.FIXClient(new System.ServiceModel.InstanceContext(fn), “wsHttp”, endpointAddress);
fc.ClientCredentials.UserName.UserName = ConfigurationSettings.AppSettings["UserName"];
fc.ClientCredentials.UserName.Password = ConfigurationSettings.AppSettings["Password"];
whew! Thanks for the great post!
June 29th, 2008 at 07:39
Hi Guys, i have also been getting the same problem with the Security of the Certificate being rejected by the verification.
Can someone explain a way forward which has had similar issues ?
I am using TCP binding, Vista.
Cheers
System.IdentityModel.Tokens.SecurityTokenValidationException : The X.509 certificate CN=MyServerCert chain building failed. The certificate that was used has a trust chain that cannot be verified. Replace the certificate or change the certificateValidationMode. A certificate chain processed, but terminated in a root certificate which is not trusted by the trust provider.
June 30th, 2008 at 18:37
Hello Dave,
Could you please tell us a bit more about your problem. Have you tried the solution DMcRae presented in his latest post?
Cheers!
September 3rd, 2008 at 12:26
What do i do?i’m trying everything,still can’t get it to work
Server Error in ‘/uniprintWebService’ Application.
——————————————————————————–
The service certificate is not provided. Specify a service certificate in ServiceCredentials.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: The service certificate is not provided. Specify a service certificate in ServiceCredentials.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[InvalidOperationException: The service certificate is not provided. Specify a service certificate in ServiceCredentials. ]
System.ServiceModel.Security.ServiceCredentialsSecurityTokenManager.CreateServerX509TokenProvider() +2465685
System.ServiceModel.Security.ServiceCredentialsSecurityTokenManager.CreateLocalSecurityTokenProvider(RecipientServiceModelSecurityTokenRequirement recipientRequirement) +56
System.ServiceModel.Security.ServiceCredentialsSecurityTokenManager.CreateSecurityTokenProvider(SecurityTokenRequirement requirement) +47
System.ServiceModel.Security.SymmetricSecurityProtocolFactory.OnOpen(TimeSpan timeout) +2829842
System.ServiceModel.Security.WrapperSecurityCommunicationObject.OnOpen(TimeSpan timeout) +19
System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) +268
System.ServiceModel.Security.SecurityProtocolFactory.Open(Boolean actAsInitiator, TimeSpan timeout) +23
System.ServiceModel.Security.SecurityListenerSettingsLifetimeManager.Open(TimeSpan timeout) +80
System.ServiceModel.Channels.SecurityChannelListener`1.OnOpen(TimeSpan timeout) +204
System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) +268
System.ServiceModel.Dispatcher.ChannelDispatcher.OnOpen(TimeSpan timeout) +61
[InvalidOperationException: The ChannelDispatcher at 'http://localhost:2353/uniprintWebService/service.svc' with contract(s) '"Service"' is unable to open its IChannelListener.]
System.ServiceModel.Dispatcher.ChannelDispatcher.OnOpen(TimeSpan timeout) +107
System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) +268
System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan timeout) +123
System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) +268
System.ServiceModel.Channels.CommunicationObject.Open() +30
System.ServiceModel.HostingManager.ActivateService(String normalizedVirtualPath) +104
System.ServiceModel.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath) +498
[ServiceActivationException: The service '/uniprintWebService/service.svc' cannot be activated due to an exception during compilation. The exception message is: The ChannelDispatcher at 'http://localhost:2353/uniprintWebService/service.svc' with contract(s) '"Service"' is unable to open its IChannelListener..]
System.ServiceModel.AsyncResult.End(IAsyncResult result) +4413209
System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result) +183
System.ServiceModel.Activation.HostedHttpRequestAsyncResult.ExecuteSynchronous(HttpApplication context, Boolean flowContext) +205
System.ServiceModel.Activation.HttpModule.ProcessRequest(Object sender, EventArgs e) +322
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +92
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +64
——————————————————————————–
Version Information: Microsoft .NET Framework Version:2.0.50727.1433; ASP.NET Version:2.0.50727.1433
September 4th, 2008 at 20:23
The issue that post DMcRae is easy to solve, you just have configure the EndPointBehavior in the EndPoint, so, your EndPoint has to look like this:
<endpoint behaviorConfiguration=”ClientBehavior” ….
September 8th, 2008 at 01:40
I am getting error, any clue for this.
System.InvalidOperationException was unhandled
Message=”The ClientCredentials cannot be added to the binding parameters because the binding parameters already contains a SecurityCredentialsManager ‘System.ServiceModel.Description.ServiceCredentials’. If you are configuring custom credentials for the channel, please first remove any existing ClientCredentials from the behaviors collection before adding the custom credential.”
Source=”System.ServiceModel”
StackTrace:
at System.ServiceModel.Description.ClientCredentials.System.ServiceModel.Description.IEndpointBehavior.AddBindingParameters(ServiceEndpoint serviceEndpoint, BindingParameterCollection bindingParameters)
at System.ServiceModel.Description.DispatcherBuilder.AddBindingParameters(ServiceEndpoint endpoint, BindingParameterCollection parameters)
at System.ServiceModel.Description.DispatcherBuilder.InitializeServiceHost(ServiceDescription description, ServiceHostBase serviceHost)
at System.ServiceModel.ServiceHostBase.InitializeRuntime()
at System.ServiceModel.ServiceHostBase.OnBeginOpen()
at System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan timeout)
at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
at System.ServiceModel.Channels.CommunicationObject.Open()
at ServiceHostApplication.Program.Main(String[] args) in C:\WCF HOL\ServiceHostApplication\Program.cs:line 23
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
September 12th, 2008 at 21:11
Thanks for the post and downloable code sample. It helped me out.
September 17th, 2008 at 00:21
Thanks Trilobyte,
I was really in trouble to setup WCF client/server on Win2003 server machine and was brainstorming for last few days. I was able to configure it on XP and Vista but was just wondering why its not working on Win 2003 server.
Finally after lot of googeling, I saw your article and it really saved me. I saw my demo application running in 20 minutes and it was jumping.
Many thanks for such a great article and hope so that will be able to see your next great article.
There is a suggestion!. It will be great help if you can make this page printable without sliders.
One again, Thanks for this master piece.
September 30th, 2008 at 20:33
About the credentials… I need to put
base.ClientCredentials.UserName.UserName = myUserName
base.ClientCredentials.UserName.UserName = myPwd
in all services client that I instantiate or only once when my application ask the login/password?
October 1st, 2008 at 18:01
Dear Rancu,
Every time you instantiate a new service client you need to set the username/password credentials because theoretically you might want to connect to the same service using different user credentials and have that connection at the same time.
I hope this answer is clear to you, otherwise just let me know. Good luck!
November 10th, 2008 at 23:42
Hi, I’m a newbie to this world. Sorry to ask fundamental questions:
1) Why do we need to specify the client credentail’s username and password? Currently I don’t set these when I create the serviceClient proxy class?
2) If we do need to specify the user name and password, are they secure when the actual call is made from the client to the service via WCF?
3) You mentioned that the X509 certificate is required only for testing purposes. Are you saying when we deploy the client for production, we don’t need to generate X509 certificate element?
Thanks, JK
February 19th, 2009 at 11:33
Hello Trilobyte,
thanks a lot for this wonderfull tutorial!
I have search a while to find a good explanation for the WCF UserName auth and no one had worked. But this!
Without Problems and without any complications.
Very helpfully!!!
Thanks, 3ddy
March 3rd, 2009 at 22:16
[...] found a very useful step by step instruction on how to setup the X509 certificate at Dev @ Work. Thanks Bert [...]
March 3rd, 2009 at 22:24
[...] found a very useful step by step instruction on how to setup the X509 certificate at Dev @ Work. Thanks Bert Willems. Possibly related posts: (automatically generated)Pass Credentials to a Web [...]
March 10th, 2009 at 09:40
thanks a lot for your invaluable support
March 24th, 2009 at 04:56
I run this example ok.
Thanks!
But I have a question. I don`t know how about MyX509Validator certificate when get certificates MyServerCert?
March 24th, 2009 at 17:43
Hello Leonit, I want to help you but I don’t understand your question, can you please rephrase your question?
March 25th, 2009 at 03:58
Hi Bert Willems!
Thanks your reads. At client code have class MyX509Validator, have function Validate, you see param certificate. Param certificate have info of certificate CN=MyServerCert, and this param compares with ConfigurationManager.AppSettings["CertName"].
//code
if (certificate.SubjectName.Name != ConfigurationManager.AppSettings["CertName"])
So, i don`t know how about param certificate have info of certificate CN=MyServerCert in my computer store.
And then, When was project get info of certificate CN=MyServerCert in computer store to param certificate?
Please help me!
March 26th, 2009 at 01:40
Thanks for the great post! My service works properly when I’m using a custombinding, but I’m moving to wsHttpBinding using Message security and setting negotiateServiceCredential=true so that the data is set encrypted.
After doing that, I get an error that is basically the following: [InvalidOperationException: The ChannelDispatcher at ‘http://test.xxx.com/Service.svc‘ with contract(s) ‘”IxxxService”‘ is unable to open its IChannelListener.
Is this some kind of security issue? Does anyone know how to resolve this? Could it have to do with my hosting company’s architectural setup?
Thanks!
March 26th, 2009 at 16:26
Hi. Thanks for your article. I browsed through it and it seems to be easy to follow. I will study it some more and try to implement it. But first, how do I get a validated certificate? How much does it cost? Can I use the same certificate in multiple WCF services? I searched the Verisign site and could not find any information about it.
March 26th, 2009 at 17:20
[...] as the example shown in http://www.devatwork.nl/index.php/2007/05/31/wcf-username-authentication/ Possibly related posts: (automatically generated)A non-RunLocal DataPortal_Create is needed for [...]
March 28th, 2009 at 10:07
@Lee, There are a lot of certificate authority, including Verisign an Thawte, you can ask them from prices because there is no standard for those prices.
You can use one certificate in multiple services.
March 28th, 2009 at 10:09
@Leonit, do you mean to ask how the MyServerCert is created on your computer store?
April 21st, 2009 at 07:59
Hi Bert,
I ran your sample code on web application. But I want to do similar things on Microsoft Azure. So will that code run on cloud hosted application, as I know there are some problems with accessing certificate for such application on cloud. ?
Please reply.
April 21st, 2009 at 17:42
Hello Prashant,
I never tried running the code on Azure, so I honestly don’t know if it is possible. Please let me know when you figured it out, I am interested in the answer.
April 28th, 2009 at 18:45
Hi, thank you so much for the instructions!
BTW, I suppose you can bypass certificates validation by specifying PeerTrust for validation method inside configuration files.
Here’s how.
The client.
[...]
[... and you use that behavior]
The server.
[...]
[...]
May 1st, 2009 at 18:54
[...] link ????? http://www.devatwork.nl/index.php/2007/05/31/wcf-username-authentication/ ??????????? ?? ??????????: email-it! | Share on Facebook | [...]
May 6th, 2009 at 18:53
I’m using SSL with basicHttpBinding. I wish for them to pass a username and password (I will have multiple users accessing this web service). How would I go about capturing/checking against that information on the server side?
Thanks in advance!!!
May 6th, 2009 at 18:55
Forgot to show you this.
security mode=”Transport”
message clientCredentialType=”UserName”
May 7th, 2009 at 07:05
I think you scenario is possible, look at the following MSDN documentation: http://msdn.microsoft.com/en-us/library/ms731338(VS.85).aspx. You can subclass the UserNamePasswordValidator to implement the authenticatie, just like in my example above.
I hope this answer will help you, please let met know if it worked.
May 7th, 2009 at 21:01
Still having trouble. Eventually we will be using https to communicate, but for now I wish to test using http. When I try and consume the WSDL I get no errors. In my client app (to test the service) I attach my credentials (client.ClientCredentials.UserName.UserName = “two”), but I can’t get the server to check the override validate function. This override function currently resides in my web service .vb class (Inherits UserNamePasswordValidator) and not under the App_Code folder. When I call the server functions from the client, I have no problems. But it passes/ignores the validate password function. Should I put the UserNamePasswordValidator class outside of my service? Here are some other pieces of info:
*BasicHttpBinding*
security mode=”None”
message clientCredentialType=”UserName”
*ServiceCredentials*
userNamePasswordValidationMode=”Custom”
customUserNamePasswordValidatorType=”MySvc.SvcClass,SvcClass”
Also..
Eventually, when I go live and switch the security mode to Transportwithmessagecredential. Currenly my web.config doesn’t use any certificates.
May 8th, 2009 at 05:11
Hi
I want to use username and password in service methods (Service.cs).
can anyone please tell me the way how to get those values.
May 24th, 2009 at 12:06
Thank you so much for this amaziiiiing post !!! Very very useful for me, thx a lot again
September 3rd, 2009 at 07:51
to bypass the cert check, just put the server cert in trustedpeople store and set the authencationmode to peertrust and set the dns is OK.
September 3rd, 2009 at 07:52
Your explanation is wonderful, really thank you~
October 28th, 2009 at 11:43
My service account has not access to the serificate I want to use for messages encryption. I want give him access rights, but do not know how to do it. Will be you so kind to explain what to do?
October 28th, 2009 at 15:37
Hello John,
Please take a look at the following page for a guide on how to manage their permissions:
http://www.enterpriseframework.com/post/2009/10/16/Windows-7-Certificate-Permissions.aspx
Hope this helps!
Bert
November 2nd, 2009 at 20:35
I followed your example and everything works great for my wsdualhttpbinding when I run my WPF Browser application in debug. But when I publish my WPF to iis and run it from the web browser I am getting a SOAP Security negotiation with ‘http://kong/Webhost/….“.
What other configurations do I need to do to get it running?
November 2nd, 2009 at 23:30
Ok. So I didn’t make any changes but it was my wcf service that was in a faulted state, which it wasn’t working. Now I need the WPF application to run on another machine. Which it doesn’t work. It gives me:
Client is unable to finish the security negotiation within the configured timeout (00:00:00).
Here is my client app.config file.
November 3rd, 2009 at 08:12
Hello Johny, is this of any help? http://social.msdn.microsoft.com/Forums/en-US/csf/thread/21160b92-bed5-4e5d-a1a9-6fc8e84f6299
November 3rd, 2009 at 19:06
I have tried the httpManager and added the namespace and ports but it does me no good and still get the same error on a particular system.
Just a note, the client and server works on some system on the same domain and on some not on the domain. It works on one Vista system, on a 64-bit WinXP. On a WinXP 32-bit system, I get:
AddressAlreadyInUseException: HTTP could not register URL http://+:80/Temporary_Listen_Addresses/b8a65a80-151c-4770-8001-77a826d91272/because TCP port 80 is being used by another application.
Then on another syste, I get:the: Client is unable to finish the security negotiation within the configured timeout (00:00:00).
my System setup:
WinXP 64-bit
IIS 6.0
I am also running IIS 6.0 in 32-bit mode.
November 4th, 2009 at 18:20
I think the AddressAlreadyInUseException is caused by the fact that another application is already listening on port 80 of that specific address. My best guess is IIS. Did you try changing ports?
November 4th, 2009 at 18:34
I did try changing ports but that didn’t change anything. I changed it to use 8000 using the httpNamespaceManager
November 5th, 2009 at 01:59
anyhow, I just realized that for a client to use my WPF application over the internet, they would need to have a certain port open for my callbacks? Are there any way to automate this through code when the client downloads the WPF app?
February 12th, 2010 at 18:15
I generated the certificate, then when I run your app I get:
“Security negotiation failed because the remote party did not send back a reply”
Can you tell me what I am doing wrong? Thanks
February 19th, 2010 at 17:08
Hey…this actually works!
I’ve read so many articles on trying to get this setup just for development purposes, I was beginning to pull my hair out.
So, thanks a million!
February 25th, 2010 at 05:10
In terms of the client proxy setup, I would like to create the new endpoint behaviour in C#, and not define it in app.config. Do you have a pointer to how to do that?
February 25th, 2010 at 09:06
Hello Rich,
You might take a look at this article: http://en.csharp-online.net/WCF_Essentials%E2%80%94Programmatic_Client_Configuration
I think that gives you a clue on how to configure your WCF endpoint using C#
February 25th, 2010 at 20:29
Thanks. (I understood most of it already, and was given the last piece earlier today.)
This entry, even though it is nearing two years old, is very relevant and helpful!
May 16th, 2010 at 23:38
Did all the above and I still get the helpful innerexception “An error occurred when verifying security for the message.” Yeah, thanks for that.
I’ve spent DAYS reading articles like this and trying to add custom username and password authentication to my service. WCF, the wonderful show pony that makes this all so easy, is an incomprehensible mess. This is all far more complex than it needs to be. It needs a wizard or a generator or something.
Thanks for the article, it’s really very clear and well done. I don’t expect you to be my support line, just needed to rant
June 9th, 2010 at 23:20
I have to use WindowsGroups authentication for one endpoint of my service(named pipe) and also a custom user name authentication for another (wsHttpBinding, just like in your article). How would I go about configuring my service?
Thanks
August 1st, 2010 at 00:25
Hi There,
I followed your procedure, nearly to the word, and have problems connecting client to Server. My client is a Winforms application and the Server a WCF application on my Server.
When I was testing on local host prior to using Certificates everything worked fine. Unfortunately implementing the Certificates as you explained, failed for me when opening a connnection to the server. Here are my config files both Server and Client plus snippets of code on client to connect.
I was hoping that only the server required a certificate, and not the client. I don’t have a client certificate in my case, and since I am using the By pass Cert validation you mentioned in your tutorial, I did not expect this error message below. Could someone help please.
Does anybody know why I get an exception: The service certificate is not provided for target ‘http://localhost/martinlayooinc/MartinLayooChatService/MartinChatService.svc'. Specify a service certificate in ClientCredentials.
Server Config: