0

I am updating some legacy code that was originally written in VB to C#. I am testing it locally with a test client that I created. I would like to get the name of the client application within in the web service application.

The legacy code uses the following property to retrieve the client application name:

AppID = ServiceSecurityContext.Current.PrimaryIdentity.Name;

However, I am testing this code locally, it throws a Null Exception error.

Is there something in the configuration file or maybe the IIS virtual directory that has the web service that needs to be set in order for this property to be set?

Thanks.

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
Gloria Santin
  • 2,066
  • 3
  • 51
  • 124
  • Did you debug your code? Take a look at http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it – Soner Gönül Feb 18 '14 at 13:56
  • yes. when the debugger gets to the AppID line it throws a null exception error – Gloria Santin Feb 18 '14 at 13:57
  • Break apart your line, do something like `var context = ServiceSecurityContext; var current = context.Current; var primaryIdentity = current.PrimaryIdentity; AppID = primaryIdentity.Name;` and tell us which one of those variables returns null. Also you say "I am testing this code locally", how are you testing it locally, are you just calling the function in a console application, using the built in IIS Express from Visual Studio, or a local instance of IIS on your machine? – Scott Chamberlain Feb 18 '14 at 14:03
  • My test client is a web form to better simulate the prod. apps that will be using the service application. Using a local instance of IIS on my machine, I created an application pool that hosts the web service that I am testing. Using your suggestion, 'var current = ServiceSecurityContext.Current' is null. – Gloria Santin Feb 18 '14 at 14:42
  • Maybe a bit late, but ServiceSecurityContect.Current.PrimaryIdentity is the one you reference too when you are using certificate base authentication. Do you have a valid local certificate to debug your app? – Jif Aug 25 '16 at 07:53

0 Answers0