WCF/WF - Client - Asked By Naresh Kumar on 09-Jun-11 05:17 AM

Hi All,

Please guide me:
1. I have created a class library named WCFSample. To this library added a class ServiceSample.cs in which I have coded for the service which shown below:

namespace DemoService

{

[ServiceContract]

public interface IEval

{

[OperationContract]

string Welcome(string name);

}

[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]

public class ServiceImplementation : IEval

{

public string Welcome(string name)

{

return "Welome" + name ;

}

}

}
2. I have taken a console application to host this service. So, added the reference to the Console App. Below shows the code:

namespace HostingServer

{

class Program

{

private static System.Threading.AutoResetEvent stopFlag = new System.Threading.AutoResetEvent(false);

static void Main(string[] args)

{

ServiceHost svh = new ServiceHost(typeof(ServiceImplementation));

svh.AddServiceEndpoint(typeof(DemoService.IEval), new NetTcpBinding(), "net.tcp://localhost:8000");

svh.Open();

Console.WriteLine("SERVER - Running...");

stopFlag.WaitOne();

Console.WriteLine("SERVER - Shutting down...");

svh.Close();

Console.WriteLine("SERVER - Shut down!");

}

public static void Stop()

{

stopFlag.Set();

}

}

}


Now how can I add this service to the Client, Please kindly provide me the steps in detail.

Thanks in Advance.

Jitendra Faye replied to Naresh Kumar on 09-Jun-11 08:33 AM

How to add a WCF Service to your Client application. I am going with the genreral steps and not specific to any binding (tcp binding/wshttpbinding/wsdualhttpbinding)

Once you have your Service ready and hosted in the machine/application/IIS, fire up your Client application

1) First, right click in your solution and you should have Add a Service Reference

2) Once you click on Add Reference, you would get a dialog box asking the Service URI and the Reference Name you would like to give for that service

3) If you are sure about the Service URI , you could complete the URI and Reference Name in the above dialog box itself, else, you could Browse for your Service by clicking on the Browse button.

So this Wizard helps you add your Service and also updates the necessary changes to app.config file and creates the WCf Proxy through which your Client application interacts with the Service.

for more help follow this-

http://www.kevingao.net/wcf-java-interop/wcf-client-and-wcf-service.html
http://v4.programminghelp.com/network/consuming-a-wcf-service-with-client-side-ajax-in-c/
http://msdn.microsoft.com/en-us/library/ms734691.aspx

Hope this will help you.

Naresh Kumar replied to Jitendra Faye on 09-Jun-11 09:18 AM
Thanks for your reply.

Your code will not help for my implementation. I have added the ServiceHost in console app in #2 point.

Please take the 2 points which I have pointed and see how can I proceed further like how can I make communication between Console and App and Client.