Farshid Farshid - 1 year ago 80
C# Question

Passing class from console application to WCF service

I'm newbie to WCF and I created a WCF service library and a console application project. I use Entity Framework (database-first) for connecting to the database in my WCF service library project. I want to send a class to the WCF service (my problem). In my WCF project I created a

that like are below:


bool GetData(role rr);


public bool GetData(role rr)
iFlowEntities db = new iFlowEntities();
return true;
return false;

and I add this service reference to my console application project reference and I create my DB class model in console application then use this service like :

Role rr = new Role();
rr.role1 = 10;
rr.title = "sdsafas";
TestClient client = new TestClient();
bool re = client.GetData(rr); //This line has error

but in this
bool re = client.GetData(rr);
I have this errors:

Error 1

The best overloaded method match for 'ConsoleApplication1.ServiceReference3.TestClient.GetData(ConsoleApplication1.ServiceReference3.role)' has some invalid arguments

Error 2

Argument 1: cannot convert from 'ConsoleApplication1.Role' to 'ConsoleApplication1.ServiceReference3.role'

I googled but any example hasn't solution for my problem.

Answer Source

You must use This DataContract in your entity model Class in WCF Model :

Public Class role
public int role1;
public string title;

But not use from client model.

And use this parameter for passing Class Object to your WCF service OerationContract from your ConsoleApplicatione :

ServiceReference3.role role = new ServiceReference3.role();

role.title="Your Title";

TestClient client = new TestClient();
bool re = client.GetData(role);