locked
Using WCF Services from 2.0 Programs RRS feed

  • Question

  •  

    Exercises in the WCF book I'm going through (Essential WCF) 1st has you create a WCF Service
    (pasted first below)  then a WCF client (pasted second below).  These both work fine with no
    surprises. 

    As you can see, the signature of the method is :  public double GetPrice(string ticker)


    Outside the exercises in the book I wanted to see how .net 2.0 clients would work
    with the WCF service so I created a windows forms program (pasted third below) in VS2005
    and added a "web reference" to the WCF Service.  However, in that wsdl the signature of
    the method was :
    public void GetPrice(string ticker, out double GetPriceResult, out bool GetResultPriceSpecified)

    My question is : Why is the signature changed when the web reference is added by a 2.0 program?
    Thanks,
    Gary


    WCF SERVICE ------------------------------------------------------------------------

    using System;
    using System.ServiceModel;

    namespace EssentialWCF
    {

        [ServiceContract]
        public interface IStockService
        {
            [OperationContract]
            double GetPrice(string ticker); // C, the contract
        }
        public class StockService : IStockService
        {
            public double GetPrice(string ticker)
            {
                return 94.85;
            }
        }

        public class service
        {
            public static void Main()
            {
                ServiceHost serviceHost = new ServiceHost(typeof(StockService));
                serviceHost.Open();
                Console.WriteLine("Press <ENTER> to terminate.\n\n");
                Console.ReadLine();
                serviceHost.Close();
            }
        }
    }

    END WCF SERVICE---------------------------------------------------------------------

    WCF CLIENT--------------------------------------------------------------------------
    using System;
    using System.ServiceModel;

    namespace EssentialWCF
    {
        class Client
        {
            static void Main(string[] args)
            {

                wcf07client.ServiceReference.StockServiceClient proxy = new
                    wcf07client.ServiceReference.StockServiceClient();
                double p = proxy.GetPrice("msft");
                Console.WriteLine("Price:{0}", p);
                proxy.Close();
                Console.ReadLine();
            }
        }
    }
    END WCF CLIENT----------------------------------------------------------------------

    2.0 Web Service Client--------------------------------------------------------------
    using System;
    using System.Windows.Forms;
    namespace client2005
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
               
            }

            private void button1_Click(object sender, EventArgs e)
            {
                localhost.StockService myStockService = new client2005.localhost.StockService();
                bool mybool = false;
                double p = 0;
                myStockService.GetPrice("msft", out p, out mybool); <-------------- 3 Args!!
                lblPrice.Text = p.ToString("c");
            }
        }
    }
    ---------------------------------------------------------------------------------

    Monday, September 22, 2008 4:25 PM

Answers