tags:

views:

37

answers:

1

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?

+1  A: 

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 with svcutil, you should also get a .cs file that contains the classes needed.

svcutil http://yourserver/yourservice 

would create a file called (your WSDL name).cs and an output.config in that directory where you run this command.

You can also specify a file name for the C# file:

svcutil http://yourserver/yourservice /out:MyService.cs

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 .....Client class and use it to call the WCF service.

Example:

  • Grab info from URL

    svcutil http://www.ecubicle.net/iptocountry.asmx?wsdl /out:IP2CountryClient.cs
    
  • Include the resulting IP2CountryClient.cs in your project; by default, the classes in that file are in no particular namespace, so they're globally visible

  • Instantiate the client class iptocountrySoapClient

    iptocountrySoapClient  client = new iptocountrySoapClient();
    
  • Call methods - e.g. this one here:

    string result = client.FindCountryAsString("82.82.82.82");
    
marc_s
didnt get u ..my question is when i am creating proxy using svcutil.exe, inthat case how to access wcf methods.If I do a add service ref things are workig fine, but what are the steps in case of svcutil.exe generated proxy
Cloud2010
@Cloud2010: added an update for svcutil.exe
marc_s
yes..it's working now.Thanks marc_s
Cloud2010