WCF Interface and methods

2019-08-03 08:56发布

I'm creating a c# Project with WCF Service, I use 3-Tiers Architecture.

I create my WCF Service as below :

namespace MyApp.WCFService
{
    [ServiceContract]
    public interface IServiceWCF
    {
        [OperationContract]
        string SayHello(string who)
    }
}

namespace MyApp.WCFService
{
    public class ServiceWCF : IServiceWCF
    {
        public string SayHello(string who)
        {
            return "Hello" + who + "from Web Service";
        }
    }
}

This works great, but in my solution I had another project with methods.

I would like to know if it's possible to make my IServiceWCF Interface implement my methods from an other project, not in the WCF. Or should I copy my methods and paste it in the WCFService class ?

Sorry for my bad english, I'm not a native speaker!

Thanks for your help

2条回答
女痞
2楼-- · 2019-08-03 09:17

Erm, interface can never implement any details. If you need to implement some concrete logic, maybe you'd want to use an abstract class instead? (or maybe just a regular class, if that makes sense)

However, interfaces can inherit from other interfaces without any problem. Just make sure you reference the required .dlls and that your desired interfaces are publicly visible.

查看更多
放荡不羁爱自由
3楼-- · 2019-08-03 09:33

possible to make my IServiceWCF Interface implement my methods from an other project, not in the WCF

Of course. Add a reference to the other project in the WCF project, let the class in the other project implement the WCF interface and configure your service to use the OtherProject.Namespace.Class as service.

查看更多
登录 后发表回答