Search code examples
asp.net.netrestwcfrestful-architecture

Rest service .net operation contracts during runtime


Is it possible to add operation contracts to a rest service during the runtime?

For instance we have a service which is available under the endpoint: www.mywebsite.com has already one operationContract: getName.

But now I want to add during the runtime two additional operationContracts: like getAdress and GetNumber.


Solution

  • The main problem is how to let clients to know about new service contracts. I think you can add new service endpoints at runtime by creating ServiceHost instances. Service will listenting to some different addresses. Those endpoints will use different service contracts (interfaces). I don't think you will construct and implement interfaces dynamically (but you can in .net). You will probably use some predefined interfaces. In this case you should inform clients somehow about new service contract and address. To pass and consume such metadata you can:

    1) Use duplex methods (service to client call direction) of some 'static' maintenance service - to bring service metadata to client in custom format;

    2) Use periodical client calls (polling) to this maintenance service - for same purpose;

    3) Use periodical web scanning (by address range) and parse wsdl to build client proxy at runtime. You can run "svcutil /sc ..." at runtime to generate code or use custom technic (this or this can help);

    4) Use intermediate service to orchestrate both service and clients (complex but powerful approach, this can help);

    5) Use wcf discovery in addition (not an easy way too);

    6) Use combination of those methods.

    p.s. You can use one interface but inform client when service supports (implements) certain method. It would be the easiest way.