locked
Doubt on IService.cs in WCF service RRS feed

  • Question

  • User269846090 posted

    Hi, I have created a simple website using WCF service, and i created a method in Service.cs and called that in a webform(default.cs).

    and then i run that application it working... But my doubt is while i reading about WCf through net they says U have to call that method in IService.cs file also...I did not call the method written inside Service.cs in IService.cs but its working... So what is the purpose of IService.cs File in WCF service.?

    This is how i done that...

    Service.cs

    ------------------

    public string SampleMethod(string Name)
    {
    return "First WCF Sample Program " + Name;
    }

    Default.cs

    ----------------

    protected void Page_Load(object sender, EventArgs e)
    {
    Service obj = new Service();
    lblMsg.Text= obj.SampleMethod("By Ganesh");
    }


    Tuesday, May 28, 2013 5:33 AM

Answers

  • User220959680 posted

    So what is the purpose of IService.cs File in WCF service.?

    As the name indicates IService.cs is an Interface that consists all service methods and is a service contract.

    Service.cs inherits and implements the methods that are defined in IService.cs.

    Client interacts with WCF service through the contract i.e., IService.cs to access methods.

    When the method is NOT declared in the IService.cs it won't be accessible from client.

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, May 28, 2013 5:50 AM
  • User-488622176 posted

    What you have done is creating a WCF service. This contains a service interface (IService.cs) and an implementation class (Service.cs). Next to that, a SVC file that exposes the IService to the outside world, using the configuration settings in the web.config file.

    In your code sample, you directly create a new Service class. This works, but you are not useing WCF, but directly addressing the service class.  You are not "consuming the WCF service" :-)

    Please check these articles on how to do so correctly:

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, May 29, 2013 4:58 AM

All replies

  • User-738028663 posted

    To understand that first read why contracts/interfaces needed? what's the use of that. you will get your answer. That's true it will work without that also. But read what i told.

    Tuesday, May 28, 2013 5:47 AM
  • User220959680 posted

    So what is the purpose of IService.cs File in WCF service.?

    As the name indicates IService.cs is an Interface that consists all service methods and is a service contract.

    Service.cs inherits and implements the methods that are defined in IService.cs.

    Client interacts with WCF service through the contract i.e., IService.cs to access methods.

    When the method is NOT declared in the IService.cs it won't be accessible from client.

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, May 28, 2013 5:50 AM
  • User-488622176 posted

    What you have done is creating a WCF service. This contains a service interface (IService.cs) and an implementation class (Service.cs). Next to that, a SVC file that exposes the IService to the outside world, using the configuration settings in the web.config file.

    In your code sample, you directly create a new Service class. This works, but you are not useing WCF, but directly addressing the service class.  You are not "consuming the WCF service" :-)

    Please check these articles on how to do so correctly:

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, May 29, 2013 4:58 AM