Click here to Skip to main content
Click here to Skip to main content

Sending Spn in secured WCF Service

By , 4 Feb 2010
Rate this:
Please Sign up or sign in to vote.
You have a WCF Service that needs a SPN from its client But We typically use client config file to send the spn using the below code:
 <endpoint address="" binding="basicHttpBinding" bindingConfiguration="basicHttp"
				 name="BasicEndPoint" bindingNamespace="TestNamespace"
            <servicePrincipalName value="HTTP/TEST"/>
But in case of .net vetsion 3.5 SP1 i is not working at all because the WCF client is not sent the spn value from config files. So it was not work at all
Use the below code to force fully send the SPN name to a WCF Service from a WCF Client:

IService proxy = null;
ChannelFactory<IService> factory = null;
EndpointIdentity identity = null;
EndpointAddress address = null;
if (!string.IsNullOrEmpty(spnName))
    identity = EndpointIdentity.CreateSpnIdentity(spnName);//  < --- HARD CODE THE SPN VALUE HERE (HTTP/TEST)
if (identity != null)
    address = new EndpointAddress(new Uri(webServiceUrl), identity);  //< ----- PROVIDE THE SERVICE URL HERE
    address = new EndpointAddress(new Uri(webServiceUrl));  
factory = new ChannelFactory<IService>(bindingName, address);
factory.Credentials.Windows.AllowNtlm = true;
factory.Credentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Delegation;
proxy = factory.CreateChannel();
use this Proxy Object you can call operations of the service and also send SPN Properly


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Palash Biswas
Software Developer Kovair Inc.
India India
I have started programming in 10 years on Fortran 77.Then it was Cobol,C,C++,JAVA 1.2, ASP,JavaScript. Now it at all C# and .NET Framework, such tehnologies as WCF, ADO.NET, ASP.NET, LINQ, ASP.NET Ajax , FLEX and another.

Comments and Discussions

-- There are no messages in this forum --
| Advertise | Privacy | Mobile
Web02 | 2.8.140415.2 | Last Updated 4 Feb 2010
Article Copyright 2010 by Palash Biswas
Everything else Copyright © CodeProject, 1999-2014
Terms of Use
Layout: fixed | fluid