This sample works fine alone but when I want to add authentication to it, it fails.
I have set the diagnostic trace for this Wcf service but the messages I get are only :"Fail to open System.ServiceModel.ServiceHost", "System.ServiceModel.ServiceHost has generated errors" and "An error System.ServiceModel.ServiceHost has appened.
I have been based on a simple example I found on the net and I think I have reproduced it correctly.
Here is the web.config file for my Wcf service :
xml version="1.0" encoding="utf-8"?>debug="true"targetFramework="4.0"/>>name="basicHttpServiceBinding">mode="TransportCredentialOnly">clientCredentialType="Basic"/>name="customBehavior">httpGetEnabled="true"httpsGetEnabled="true"/>includeExceptionDetailInFaults="true"/>userNamePasswordValidationMode="Custom"customUserNamePasswordValidatorType="WcfService1.UserAuthentication,WcfService1"/>name="WcfService1.Service1"behaviorConfiguration="customBehavior">address="http://localhost/TestServiceWCF/Service1.svc"binding="basicHttpBinding"bindingConfiguration="basicHttpServiceBinding"contract="WcfService1.IService1">value="localhost"/>address="mex"binding="mexHttpBinding"contract="IMetadataExchange"/>baseAddress="http://localhost/TestServiceWCF/"/>wmiProviderEnabled="true">logEntireMessage="true"logMalformedMessages="true"logMessagesAtServiceLevel="true"logMessagesAtTransportLevel="true"maxMessagesToLog="3000"/>multipleSiteBindingsEnabled="true"/>autoflush="true"indentsize="4"/>name="System.ServiceModel"switchValue="All"propagateActivity="true">name="xml"/>name="System.ServiceModel.MessageLogging">name="xml"/>name="myUserTraceSource"switchValue="Information, ActivityTracing, Warning, Error">name="xml"/>name="xml"type="System.Diagnostics.XmlWriterTraceListener"initializeData="E:\ldiep\Projets\Wcf\IIS_Logs\messages.svclog"/>runAllManagedModulesForAllRequests="true"/>
Here is the App.config for my client application :
xml version="1.0" encoding="utf-8"?>name="DefaultBinding_IService1">mode="TransportCredentialOnly">clientCredentialType="Basic"/>address="http://localhost/TestServiceWCF/Service1.svc"binding="basicHttpBinding"bindingConfiguration="DefaultBinding_IService1"contract="ServiceReference1.IService1"name="ServiceReference1"/>
Here is the UserAuthentication.cs :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ServiceModel;
using System.IdentityModel.Selectors;
namespace WcfService1//namespace Service{publicclassUserAuthentication:UserNamePasswordValidator{publicoverridevoidValidate(string userName,string password){try{if(userName =="test"&& password =="test123"){Console.WriteLine("Authentic User");}}catch(Exception ex){thrownewFaultException("Unknown Username or Incorrect Password");}}}}
if you are using user like "test" then on the host machine of the wcf service you need to create local user "test" after creating it will work properly.
Finally, for several reasons, I cannot use certificates.
I have study how Yaron Naveh's (ClearUsernameBinding) does to do without certificates but it doesn't suit to my needs because the custom binding mode forces to run the service in an application in order to access to the service.
Is there another way to make Wcf authentications without certificates ?
Eric BryanPosted Jun 18, 2015, 4:38 AM
Thank you Abrar,
I will test what you said.
Khan Abrar AhmedPosted Jun 17, 2015, 3:01 AM
Khan Abrar AhmedPosted Jun 17, 2015, 2:59 AM
Eric BryanPosted Jun 16, 2015, 11:07 AM
I have study how Yaron Naveh's (ClearUsernameBinding) does to do without certificates but it doesn't suit to my needs because the custom binding mode forces to run the service in an application in order to access to the service.
Is there another way to make Wcf authentications without certificates ?
Eric.
Eric BryanPosted Jun 15, 2015, 9:43 AM
Abrar,
I have tested your solution, but it is the same.
receiveTimeout="00:10:00"
sendTimeout="00:10:00"
openTimeout="00:10:00"
closeTimeout="00:10:00"
maxReceivedMessageSize="65536"
maxBufferSize="65536"
maxBufferPoolSize="524288"
transferMode="Buffered"
messageEncoding="Text"
textEncoding="utf-8"
bypassProxyOnLocal="false"
useDefaultWebProxy="true" >
contract ="WcfAvecCertificat.IService1">
address="mex" />
logMalformedMessages="false"
logMessagesAtServiceLevel="true"
logMessagesAtTransportLevel="true"
maxMessagesToLog="300000"
maxSizeOfMessageToLog="200000"
/>
propagateActivity="true" >
initializeData="E:\ebryan\Projets\Wcf\IIS_Logs\messages.svclog" />
Eric BryanPosted Jun 14, 2015, 10:14 AM
Thank you very much for your answer Abrar.
I will test your solution tomorrow, on Monday.
Khan Abrar AhmedPosted Jun 14, 2015, 6:09 AM
serviceProxy.ClientCredentials.UserName.UserName = "test";
serviceProxy.ClientCredentials.UserName.Password = "test123";
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(delegate { return true; });
string sReturned = serviceProxy.GetData(14);