Search code examples
c#wcfmodel-view-controller

How to create new method into existing WCF services?


I have one existing WCF services project. I want to create new method as per my new requirement. How can I create new method inside my WCF service? Also I want to access the database through a Stored Procedure.


Solution

  • You could add a new OperationContract into your ServiceContract like:

    [ServiceContract()]
    public interface IMyService
    {
        [OperationContract]
        bool DoSomething(string param);
    }
    

    and implement the method then in the ServiceBehavior:

    [ServiceBehavior()]
    public class MyService
        : IMyService
    {
        public bool DoSomething(string param)
        {
           //Do Something....
        }
    }
    

    or in MVC add an new method to your ApiController like:

    public class MyController : ApiController
     {
            [Route("api/DoSomething/")]
            [HttpGet]
            public bool DoSomething(string param)
            {
                 //Do Something...
            }
      }
    

    Maybe you can show some of your code ...