A way to unify calls in WCF Service?

Asked

Viewed 234 times

0

Greetings to you all. Currently I have a WCF Service Application running on IIS with many services, to each new service created I need a new update and a new reference on the client side. As I am new to WCF, I wonder if it is possible to centralize all these services in a single service? I know the question may be very relative, because it depends a lot on what each method returns and such, but I accept any suggestion, because I wish there was only one service and one method and everything went through the same channel, is it possible? Can I have lost requests or is a queue generated? I’m sorry if I didn’t express myself in a correct or more technical way, as I said I’m new, thank you!

Paulo Balbino

2 answers

1


Paul,

If the main goal is to call methods without updating the client, following the example, I can suggest the following:

    enum Metodos { MetodoA, MetodoB };

    [ServiceContract]
    public interface IMeuServico
    {
        string MetodoA();
        string MetodoB();

        [OperationContract]
        string MetodoPrincipal(Metodos metodo);
    }

and the class implementing the above interface:

public class Service1 : IMeuServico
{
    public string MetodoA()
    {
        throw new NotImplementedException();
    }
    public string MetodoB()
    {
        throw new NotImplementedException();
    }
    public object MetodoPrincipal(Metodos metodo)
    {
        switch (metodo)
        {
            case Metodos.MetodoA: return MetodoA();
            case Metodos.MetodoB: return MetodoB();

            default:
                return null;
        }
    }
}
  • Thank you for your help Alexandre, I will implement your example for testing.

0

It is possible to centralize all these services in a single service. You can have a WCF service with all methods.

[ServiceContract]
public interface IMeuServico
{
    //Disponibilizar todos os métodos que deseja expor no seu serviço
    [OperationContract]
    string MetodoA();

    [OperationContract]
    string MetodoB();
}

However, if you need to create a new method, you will still need to update the customer’s reference to your service so that they can see this new method and use it.

Try creating services based on one feature. You’ll get less code, easier maintenance.

Example:

[ServiceContract]
public interface IMeuServicoFuncionalidadeA
{
    //Disponibilizar todos os métodos que deseja expor no seu serviço
    [OperationContract]
    string MetodoA();
}

[ServiceContract]
public interface IMeuServicoFuncionalidadeB
{
    //Disponibilizar todos os métodos que deseja expor no seu serviço
    [OperationContract]
   string MetodoB();
}

About: "...wanted there to be only one service and one method and Everything goes through the same channel, is it possible? I may have lost requests or a queue is generated?"

With all methods in only one service a yes queue can be generated. For example, if your instance management mode is Persession (way default), the service will be able to serve only a single thread and thus the other threads will have to wait for release to be processed.

For details on managing instances take a look at this link.

  • First thank you for the reply Renan. My intention is to have only one method within a service, I need to do it in a way that the service does not know who it is travelling (dealing), so it would not need to keep creating typed methods and would not have to update the service. Thanks! Vlw for the link, I’ll study it!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.