Click here to Skip to main content
15,884,096 members
Articles / Security
Tip/Trick

Sending Spn in secured WCF Service

Rate me:
Please Sign up or sign in to vote.
4.00/5 (1 vote)
4 Feb 2010CPOL 14.6K  
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" ...
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"
                contract="IService">
         <identity>
           <servicePrincipalName value="HTTP/TEST"/>
         </identity>
       </endpoint>

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
else
    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

License

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


Written By
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 --