Registering type mapping to work across console and web

Aug 10, 2010 at 2:09 AM

I have a console app that registers a type mapping and then calls a web service. The web service is unable to find the type mapping, I think because they are at different "levels".

Is there any way to set a type mapping and have it use that across console and winform apps, as well as in the web level?

If not, what is this reason please?

Thank you.

Aug 10, 2010 at 3:34 PM


As long as the web service and the console application are ran in an environment where they have access to the same farm, this should not matter.  If you don't provide an SPSite to service location configuration, then the typemapping will be stored at the farm level.  Are you certain that in both the console application and the web application are running on a WFE running in the same farm?


Aug 11, 2010 at 1:51 AM

I'm running this all on the same server in a development VM. Also please note that I'm using SPG2007 for this test.

I've created a test project as follows:

  • ServiceLocatorTestCommon: Contains IFruitProvider interface with AppleProvider and BananaProvider. Consists of a GetFruit() method returning a simple string.
  • ServiceLocatorTest: WSPBuilder project that contains a SOAP web service. The service gets the current instance of IFruitProvider from the service locator and returns the output from GetFruit().
  • ServiceLocatorTestConsole: Registers the IFruitProvider to use with the service locator and then calls the web service.

When running the console app I get:

System.Web.Services.Protocols.SoapException: Server was unable to process reques t. ---> Activation error occured while trying to get instance of type IFruitProv ider, key "" ---> No type mapping was registered for type 'IFruitProvider' and k ey ''. at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClie ntMessage message, WebResponse response, Stream responseStream, Boolean asyncCal l) at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodN ame, Object[] parameters) at ServiceLocatorTestConsole.TestWebSvc.TestWebService.Hello() in C:\Projects \ServiceLocatorTest\ServiceLocatorConsole\Web References\TestWebSvc\Reference.cs :line 78 at ServiceLocatorTestConsole.Program.Main(String[] args) in C:\Projects\Servi ceLocatorTest\ServiceLocatorConsole\Program.cs:line 22

Why wouldn't this work?

It looks like I can't attach the example project to the discussion but I can e-mail it if wanted.

Thanks for the help, Alex.

Aug 11, 2010 at 3:43 PM

Hi Alex,

 How are you registering the type mapping?  Can you paste that code?  Also, can you load the type in the console application you are registering right after registration?  Try the following if you can:

Register the type mapping.

Get an instance of the type.  Verify it works.

Call SharePointServiceLocator.Reset (this will uncache all information and force a reload of the type mappings from configuration)

Get an instance of the type again.  Verify it worked.


IF you are using SPG2007, we only register typemappings at the farm level, so the level should matter as long as both are accessing the same farm.  You can send your repro to my email (



Aug 12, 2010 at 3:39 PM

Hi Alex,

As we discussed offline you need to register the services using IServiceLocatorConfig.  The method on the ActivatingServiceLocator is reserved for unit testing.  We outline this in the documentation, where we have separate scenarios for using the service locator with unit testing and registering services.  I'll take add a backlog item to take a deeper look at the design next time to see if we can take another approach and remove the method altogether on ActivatingServiceLocator.

I'm not sure why the service would not be seeing the service registration still if it is deployed within the same farm on the same WFE you ran the console app.  I'll see if I can repro, but the logic is pretty straightfoward.  The only reason I can see it would not pick this up is that it's not accessing the same farm configuration store.


Aug 12, 2010 at 3:42 PM

Also please post the error you are receiving in the web service.  The more likely case at this point in my opinion is that its not finding the assembly that contains the interface and types rather than not finding the config if an exception is still being thrown.  Lets verify its the same exception.



Aug 13, 2010 at 6:35 AM

Hi Chris,

I went to run this again to get more information for you and it's all working. *Sigh!*

The only thing I'm aware of that changed is that I rebooted the machine. Perhaps there was some caching going on that I needed to reset?

Anyway, thanks for looking at this one.

Best regards, Alex.