Basic WCF Service C#

This post explains Basic WCF Service C#. Let’s start with WCF service library

basic-wcf-service

Then, to existing solution add new project

add-new-project-to-existing-solution

Choose Windows forms application

03wcfservicenastavak

Now, we need to add reference to this new Windows forms application

add-wcf-reference-to-windows-forms-application

Choose in Projects -> Solution

wcf-service-library-basic-added-as-reference

Then, go to IService1 interface class, and there add declaration for “add” method:

// TODO: Add your service operations here
[OperationContract]
double Add(int number1, int number2);

iservice1-to-do-operation-contract

Now, implement new method in Service.CS:

public double Add(int number1, int number2)
{

return number1 + number2;

}

service1-method-implementation

In order to implement code in main project, we need to use namespace:

using WcfServiceLibraryBasic;

And then implement it:

var cal = new Service1();
MessageBox.Show(cal.Add(1,1).ToString());

service-implementation-in-formload

Posted in c-sharp-code-examples Tagged with:

Leave a Reply

Your email address will not be published. Required fields are marked *

*