WCF Interface and methods

对着背影说爱祢 提交于 2019-12-13 01:25:24

问题


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


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/19835505/wcf-interface-and-methods

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!