I have created one WCF service , which is working fine, now i want to consume it in a client application.
using SVCutil.exe i have generated proxy and aap.settings for that service and added that to the client sln(console application)
But the problem is i am unable to access the wcf methods.
using System.ServiceModel;
namespace WCFClient
{
class Program
{
static void Main(string[] args)
{
Program p = new Program();
p. // not getting the wcf methods
}
}
}
what I am doing wrong?
Depends on how your service is called. When you created the service reference, you gave it a namespace name – in that namespace, there should be a class called (yourservicename)Client – instantiante one of those and get going.
You should find those files under the Service Reference – if you click on the “show all files” button in the Solution Explorer, you’ll start seeing a ton of files under your service reference – one in particular should be
Reference.cs. Those classes are defined in that file – you can check it out, it’s a regular C# file.Update: If you create your proxy using
svcutil.exe, depending on your options used withsvcutil, you should also get a .cs file that contains the classes needed.would create a file called
(your WSDL name).csand anoutput.configin that directory where you run this command.You can also specify a file name for the C# file:
and then your file is called
MyService.cs.SvcUtil has a ton of options – can’t explain them all to you, play around with them, read up on the MSDN docs for it.
Again, one of them will be called
(your service name)Client. Include that *.cs file in your project, check the namespace, create an instance of the.....Clientclass and use it to call the WCF service.Example:
Grab info from URL
Include the resulting
IP2CountryClient.csin your project; by default, the classes in that file are in no particular namespace, so they’re globally visibleInstantiate the client class
iptocountrySoapClientCall methods – e.g. this one here: