Reputation: 961
I followed this guide from MSDN to host a simple WCF service.
But what is the proper way on the client side to use it?
Upvotes: 0
Views: 1080
Reputation: 13531
The most used options are:
svcutil
. This means that it is autogenerated for you, so it's very easy to use and mostly used if the client to your service is external to the system. But as it's generated code, you loose some control.Upvotes: 4
Reputation: 3429
Add a service reference to your client project and select Discover/Services in solution. Then select your service and you'll be able to access all your services methods by writing this kind of code :
using(var myClient = new YourServiceReference.YourService())
{
myClient.MyMethod()...
}
Upvotes: 1
Reputation: 5047
Personally I prefer to work with WCF service by creating ChannelFactory<T>
and then creating a channel for communication with it.
Example:
ChannelFactory<IProcessor> factory = null;
try
{
var netTcpBinding = new NetTcpBinding("netTcpBinding_BigPackets");
factory = new ChannelFactory<IProcessor>(netTcpBinding);
var processor = factory.CreateChannel(processorAddress);
var result = processor.Process(request);
return result;
}
catch (CommunicationException)
{
if (factory != null)
{
factory.Abort();
factory = null;
}
throw;
}
finally
{
if (factory != null)
{
factory.Close();
}
}
Good example can be found in MSDN: http://msdn.microsoft.com/library/ms576132.aspx
Also I would advise you to refer WCF samples from IDesign page: http://idesign.net/Downloads
Upvotes: 1
Reputation: 7042
You use it using C# code by extracting the WCF XML from it or use WCF Test Client. Go to Visual Studio and add "Service Reference" using the WCF URL to add the service and it will generate the service code for you.
Upvotes: 0
Reputation: 5666
You can continue your learning path on MSDN.
There are several options:
Note: The first 2 options requires already running service.
Upvotes: 3
Reputation: 2448
Here is nice example about usage of WCF services http://wcfbyexample.codeplex.com/
Upvotes: 0