WCF with spring - wcf

I'm fairly new to wcf (we have yet to upgrade to .net 3.0 in my workplace) and I'm working on a little home project to bring myself up to speed with some of the 'newer' features of .net.
I tend to use spring.net in most of my projects and so after creating my first WCF service I started to look at configuration via spring.net
So far my service is configured via spring (I'm injecting objects into it) however I would like to avoid adding attributes to the service contract interface i.e. I would prefer to not have to add [ServiceContract] and [OperationContract] attributes to what should be a pono interface.
Is this possible with spring.net out of the box?

According to the reference manual it should be possible Chapter 28.5

Related

how to develop N-Tier Layer for WCF Service by using Entity framework 6.0.. Suggest me exposing Entities as datacontract is good or bad?

Could you please help in creating N-Tier Arch for WCF Service which will uses Entity framework 6.0 for data access.
I have worked in Creating N-Tier Arch for WCF using Software factory with Enterprise library....for data access and exception logging in database as well as in file system
But am really confused whether I can expose the Entities which generated as part of the Entity framework in the WCF Service data contract... also suggest me how to implement other activities like exception logging in database using the entity framework...
If possible please guide me by creating Sample or demo N-TIER Arch for WCF using Entity framework...
I have seen lot of articles saying need to use repository pattern when using Entity framework
Do we really need to implement or use repository pattern when using Entity framework
Is using Trackable Entities a good idea for WCF? Also please explain how the Trackable Entities works?
This blog is not only about exposing entities via WCF but also about implementing business logic as part of those entities and sharing it via shared assemblies on .NET clients and servers.
Concerning n-tier architecture and respective implementation you may well be interested in using the N-Tier Entity Framework which perfectly addresses your needs. The framework provides Visual Studio templates to create required components for the different tiers. Then it provides T4 code generation templates to generate client and server code based on entity models (edmx). You may also find sample applications and a user guide for download on codeplex.
Logging exceptions and other information is done best using a logging framework like log4net or NLog. If you need to send log messages from client to server you should do so using async messaging which can be done with WCF using MSMQ binding.

Web Hosted WCF REST Service with plugable endpoints (is this possible)?

I'm a bit new to WCF, so please bear with me. I have a very simple REST Service written up using .NET 3.5, which is exposed through a asp.net web application through a SVC file. Everything is working as expected.
What I would like to know is if it is possible for me to create a plugin structure in WCF, so that I can have third party developers write up expose their functionality through my service. I'm hoping it's possible to dynamically create my endpoints through code, at the moment everything is in my web.config and service.svc files (as far as exposing the contract).
In the end, what I would like to have an active running service that auto checks for new assemblies (if added to the plugins directory), and would automatically add new endpoints, which could have completely different functionalities. One could be a file transfer plugin, another could be a calculator, etc.
But first I need to know if it's even feasible... currently I'm looking into MEF to see if that might help out, as I'm used to just loading DLLs manually (in Desktop apps).
It is possible to use MEF through WCF, I have worked on a similar project in the past. You could expose functions from the plugin DLL's through MEF assume the implementer of the MEF interface is implimenting a function that starts a new WCF service with it's own end points, then call that function from the main service.
See some sample projects below, although none of them are doing what you are asking it is possible that the MEF plugins could have a service host that's starting their very own service with their own end points.
Creating WCF Service Extensibility through MEF
A sample demonstrating how WCF and MEF play together

How to a structure a WCF Project

I am going to write a WCF service and need help in structuring the project for the below scenario:
Client and Service are going to share data contracts assembly-> http://code-magazine.com/Article.aspx?quickid=0809101
WCF is in turn gonna call multiple services to populate data contract using Automapper.
What are the best practices to structure a WCF project? and how to best wire-up automapper in the middle of WCF project?
I like to structure my WCF solutions like this:
Contracts (class library)
Contains all the service, operations, fault, and data contracts. Can be shared between server and client in a pure .NET-to-.NET scenario
Service implementation (class library)
Contains the code to implement the services, and any support/helper methods needed to achieve this. Nothing else.
Service host(s) (optional - can be Winforms, Console App, NT Service)
Contains service host(s) for debugging/testing, or possibly also for production.
This basically gives me the server-side of things.
On the client side:
Client proxies (class library)
I like to package my client proxies into a separate class library, so that they can be reused by multiple actual client apps. This can be done using svcutil or "Add Service Reference" and manually tweaking the resulting horrible app.config's, or by doing manual implementation of client proxies (when sharing the contracts assembly) using ClientBase<T> or ChannelFactory<T> constructs.
1-n actual clients (any type of app)
Will typically only reference the client proxies assembly, or maybe the contracts assembly, too, if it's being shared. This can be ASP.NET, WPF, Winforms, console app, other services - you name it.
That way; I have a nice and clean layout, I use it consistently over and over again, and I really think this has made my code cleaner and easier to maintain.
This was inspired by Miguel Castro's Extreme WCF screen cast on DotNet Rocks TV with Carl Franklin - highly recommended screen cast !

Ninject Di bindings using a WCF service

I recently created a WCF service library. I am planning on hosting it in IIS. Since I want to reuse my repository layer I decided to go use Ninject in my WCF service as well (I use it in other projects in the solution).
I installed the Ninject Wcf Extensions. I configured it using the NinjectServiceHostFactory in the svc file. I added a Global.asax file to override the CreateKernel() that inherits from NinjectWcfApplication but I am not sure if I am using the bindings correctly. I first started with:
Bind<IUnitOfWork>().To<UnitOfWork>().InRequestScope();
But I quickly realized that this does not work since no data was saved to my database. It appears that the WCF service does not use the ASP.NET pipeline. I went ahead and tried both of these as well just to see if my data was committed to the database:
Bind<IUnitOfWork>().To<UnitOfWork>().InThreadScope();
Bind<IUnitOfWork>().To<UnitOfWork>().InTransientScope();
No luck. I then decided to try:
Bind<IUnitOfWork>().To<UnitOfWork>().InSingletonScope();
This worked but I don't want my database context to be shared by every single request that comes in to the WCF service. I then did some research and found the following approach:
Bind<IUnitOfWork>().To<UnitOfWork>().InScope(c => OperationContext.Current);
This works but is it correct? I wan t something to resemble the InRequestScope for a MVC application. Each request to the service should get its own Database context.
I suggest to have a look at the latest build from the CI-Server http://teamcity.codebetter.com
You need Ninject, Ninject.Web.Common, Ninject.Extensions.Wcf
With this version you can use InRequestScope for Wcf.
I am new to Ninject, but I can tell you that OperationContext.Current is the equivalent to HttpContext.Current for web application.
So your first thought was to use .InRequestScope(); (which is equivalent to .InScope(c => HttpContext.Current);)
so I guess that using .InScope(c => OperationContext.Current); for WCF is pretty correct.

WCF WinService with Plugins

I have a win32 application that uses client side plugins and uses a Win32 Service via TCP/IP. I would like to also dynamically load assemblies on the WCF service based on the addition of new plugins. Currently I have to add the the ServiceContract and OperationContract to the Services class and IService interface and then re-compile. Is there a way to dynamically load the WCF assemblies and not have to generate the class and interface references? Can these be moved out of the WCF Win32 service into external classes?
I was wondering about this as well, but came to the conclusion that this was not a question of whether or not its possible, but should you do it? Even if you could generate the contract definitions dynamically, you still need to notify the client of the change, they in turn would need to regenerate the proxy in order to interact with the new service definition, and then provide an implementation dynamically. A better approach is to redesign your service so it implements a particular strategy (read Strategy pattern). The contract remains static, but the implementation changes based on client input. That way your service can dynamically load modules without your client being aware of it.
HTH.
Steve