English 中文(简体)
服务合同
原标题:Service Contract Implements another Interface

Please tell me if this is possible. I have a client win form app and a wcf app in C#. This is my model.

Common Project

public interface IServiceA
{
     string DoWorkA();
}

我没有在共同项目中使用服务合同或合同属性。

Now, ClientProject references the Common Project. ServiceProject also references the Common Project.

在服务项目中,我使用以下服务合同:

[ServiceContract]
public interface IGetData : IServiceA
{
   // Implements IServiceA method
   [OperationContract]
   string DoWorkA();
}


public class MyService : IGetData
{
    string DoWorkA()
     {

     }
}

In the Client side

public class MyClass : IServiceA
{
    // Implements the IServiceA method
    string DoWorkA()
     {
        // Inside this I will call the MyService using DuplexChannel proxy
     }
}

[请假设退约在本模式中执行]

我为什么问这个问题,在我的申请中,我有许多单元,每个单元都需要用自己的方法从服务中获得数据。 因此,我正计划采用类似学校模式。 请告诉我,这是否正确?

问题回答

由于<代码>IGetData>_DoWork()方法隐藏了<代码>ISERA/code>。

为了消除你需要添加新的关键词的警告:

[ServiceContract]
public interface IGetData : IServiceA
{
   // Implements IServiceA method
   [OperationContract]
   new string DoWorkA();
}

但我认为,你想要做的是把较小的接口集中到一个更大的服务中。 然后,你的模块可以与其易于理解的界面(这是服务接口的一个子集)互动。

例如:

public interface IWarehouse : IShipping, IReceiving, IInventory, IMovement {}

我们采取了类似的做法。

  • We defined all of our service contracts in a shared assembly and used the interfaces on both the client and the server.
  • We created client proxies that implemented those interfaces.

然后,客户可以与整个服务接口的更简单的子体互动。

第一界定接口:

[ServiceContract]
public interface IServiceA
{
    [OperationContract]
    string DoWorkA(); 
}

[ServiceContract]
public interface IServiceB
{
    [OperationContract]
    string DoWorkB();
}

[ServiceContract]
public interface IGetData : IServiceA, IServiceB
{
}

由此形成轴心(也可在此使用):

public class ServiceClientA : ClientBase<IGetData>, IServiceA
{
    public string DoWorkA()
    {
        return Channel.DoWorkA();
    }
}

public class ServiceClientB : ClientBase<IGetData>, IServiceB
{
    public string DoWorkB()
    {
        return Channel.DoWorkB();
    }
}

以上情况与你的我的地图集无关。

然后,客户可以使用个人接口:

IServiceA clientA = new ServiceClientA();
string result = clientA.DoWorkA();

IServiceB clientB = new ServiceClientB();
result = clientB.DoWorkB();

如果你想要,你也可以在这里建立一个服务工厂。

我希望这给你一些想法。

要点汇编:

  • Your client does not need to implement IServiceA. Why is that? Your client can consume the service by just having reference to your WCF service.
  • Your interface IServiceA seems to be redundant in a given scenario. It is not bringing any benefit with it. IMO you can live IGetData. This is where you are implementing the service contract. If you wish you can rename this interface as IServiceA.

To answer your point where you have lots of module which need to get data from service, can you categorize these modules in business/function nature? If yes, then you can create different WCF service for each of those business/function and respective modules will call respective service. Further to this I don t see a point why one module should not be allowed to gather data from more than one service. That is perfectly acceptable scenario.

HTH





相关问题
WCF DataMember Serializing questions

Ok, so I was part way through the long winded process of creating DTOs for sending my model over the wire and I don t feel like I m going down the right route. My issue is that most of the entities ...

Access WCF service on same server

I have a .NET website with a WCF service. How do I access the current operations context of my service? One possible work around is to just make a call to the service within the app...but that seems ...

WCF binding error

So I got into work early today and got the latest from source control. When I try to launch our ASP.NET application, I get this exception: "The binding at system.serviceModel/bindings/wsHttpBinding ...

The service operation requires a transaction to be flowed

I am facing strange issue with our WCF service. The same code was working fine until recently we added more OperationContracts(Web Methods). We have common 3 tier architecture. DAL (WCF) BLL Web ...

热门标签