Transport layer security implementation
=>note: keeping in mind that this program is tested on vs 2010 framework 4.0.step 1:
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="TP">
<security mode="Transport">
<transport clientCredentialType="Basic">
</transport>
</security>
</binding>
</wsHttpBinding>
</bindings>
<services>
<service name="Service" behaviorConfiguration="Service
<endpoint address="" binding="wsHttpBinding" bindingConfiguration="TP" contract="IService">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="tr
</system.serviceModel>
Step 2:in Interface
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
[ServiceContract]
public interface IService
{
[OperationContract]
string GetData();
}
Step 3:In Service class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
public class Service : IService
{
public string GetData()
{
return "DWARIKA PRASAD";
}
}
step4:
open iisdouble click on authentication
check Anonymous Authentication is enabled and
basic Authentication is Enabled if not
please Enabled
Step5:Again in iis
double click on server certificatenow click on create self signed certificate
write something in textbox like your name anything
click ok
step 6:again in iis
click on triangle sign of sitesnow double click on default web site
select your service(means wcf application name)
right click on default web site
choose Edit binding
now click on add button
choose https from Type and and choose your name from ssl certificate which has write at create time of "create self signed certificate"
click ok
step 7
write following on notepadnetsh http add sslcert ipport=0.0.0.0:8080 certhash=66be7f467713c296ae2fb
this is my tested code
but for you
for certhash open again iis
double click on server certificate
now
double click on your certificate which has already created by you
now go to Details tab
choose Thumbprint only
now copy data from below box
paste this on another notepad
choose empty space
press ctrl h
now take one space in find what
click on replace all
now copy this code in certhash in previous notepad
Step 8 :forappid
=>open vs ide
click on tools
choose create guid
click on guid
choose 4th option and copy data from result
paste this info in appid as above mention
now copy full line netsh wali from step 7
and go on command prompt of vs
in cd\:
paste all code
now press enter
you get following message
"ssl certificate successfull added"
if ssl certificate already exist write followinig on command prompt to delete
netsh http delete sslcert ipport=0.0.0.0:8080
now debug yor wcf application
=> copy the address from url
step9:at client site
take proxykeeping in mind that your computer should be password protected because
this ask user name and password of your computer
now take a label and a button
on button click write following code
ServiceReference1.ServiceClien
s.ClientCredentials.UserName.U
s.ClientCredentials.UserName.P
Label1.Text= s.GetData();
=>debug your application
No comments:
Post a Comment