Hi Team,
I am developing a sample WCF service with security, as i am new to WCF i just to establish a connection through username and password(Note: no need of SSL certificate).
I am using the following code,
In service the code is
The interface contains the code,
namespace WcfService
{
[ServiceContract]
public interface IWcfService
{
[OperationContract]
string GetData();
}
}
the inherited class has
namespace WcfService
{
public class WcfService : IWcfService
{
public string GetData()
{
return "Sample Service";
}
}
public class CustomValidator : UserNamePasswordValidator
{
public override void Validate(string userName, string password)
{
if (userName == "manikandan" && password == "manikandan")
{
}
else
{
}
}
}
}
The web.config in the service is
<system.serviceModel>
<services>
<service behaviorConfiguration="WcfService.WcfServiceBehavior" name="WcfService.WcfService">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="MyBinding" contract="WcfService.IWcfService">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="WcfService.WcfServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="MyBinding">
<security mode="None">
<message clientCredentialType="UserName"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
</system.serviceModel>
And i am consuming the service in the web application as follows,
I am just adding the service reference and invoke the service using the following code,
ServiceReference1.WcfServiceClient client = new WcfServiceClient();
client.ClientCredentials.UserName.UserName = "manikandan";
client.ClientCredentials.UserName.Password = "manikandan";
string state= client.State.ToString();
string val= client.GetData();
txtEmpId.Text = val;
where ServiceReference1 is the name for my service
Could you guys see the code and tell me what mistake i made, i placed debugger on every method, the CustomValidator is not firing, so it is not authenticated. How can i secure it, with just username and password without certificate.
Thanks in advance.