0

I'm new to StuctureMap and I am writing a WCF service. In the existing code the previous developer used SturctureMap.

I get this error:

StructureMap Exception Code: 202
No Default Instance defined for PluginFamily MyCompany.SMS.Data.DataEntitys, MyCompany.SMS.Data, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null

Here is the Code:

class a
{  method aa
    {
       var db = ObjectFactory.GetInstance<nsclaimsEntities>();
    }
}

When we are calling this code from an aspx.cs file it is working fine without any error, but I tried to wrap this code in a WCF webservice and it is throwing this exception.

Here is the stack trace:

at StructureMap.BuildSession.<.ctor>b__0(Type t)
at StructureMap.Util.Cache`2.get_Item(KEY key)
at StructureMap.BuildSession.CreateInstance(Type pluginType)
at StructureMap.Container.GetInstance(Type pluginType)
at StructureMap.Container.GetInstance[T]()
at StructureMap.ObjectFactory.GetInstance[PLUGINTYPE]()
at NicorNational.SMS.CustDemographic.GetByAccountNumber(String acctNum) in C:\\Projects\\NicorNational.SMS\\CustDemographic.cs:line 105
at NicorNational.Services.eCommerce.EligibilityService.GetEligibilityById(String accountId) in C:\\Projects\\Solutions\\NicorNational.Services.eCommerce\\EligibiltyService.svc.cs:line 23
at SyncInvokeGetEligibilityById(Object , Object[] , Object[] )
at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs)
at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)"

Why do I get this exception?

4
  • My guess is that you didn't copy the relevant stuff from the config file to your wcf project... but I'm far from up2speed on StructureMap Commented Feb 10, 2011 at 23:07
  • Thanks a ton RENE!!! Im missing some values in WEB config....you saved my life. it was bugging me whole day... Commented Feb 10, 2011 at 23:17
  • Sorry, I could not get rid of this error. As you said for the existing ASPX application they were using the GLOBAL.ASAX file to configure the SturucureMap. Is there any way to add these settings to WCF Applications? Commented Feb 10, 2011 at 23:53
  • I fixed this issue by adding static constructor to the WCF service class. Find this link. stackoverflow.com/questions/739268/wcf-application-start-event/… public Service : IContract { public Service(){ // regular constructor } static Service(){ // Only called first time it's used. } } Commented Feb 11, 2011 at 15:12

1 Answer 1

2

As you've already found out, the problem migrating straight from a web application to a WCF service is where to place the bootstrapping code.

I just wanted to point out that you should move away from the service location behaviour and introduce dependency injection instead to have loose coupling and make your service easier to maintain/change.

Jimmy Bogard has written an excellent blog entry on how to bootstrap a WCF service using Structure Map. He uses a custom ServiceHostFactory instead of a static constructor to bootstrap the registry.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.