Click here to Skip to main content
12,945,933 members (57,058 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Hi there,

I'm a beginner to WCF and now trying a sample application. I cannot create instance of a datacontract class at my client side code. Please help me.

Below is the WCF service code.
    public interface IArithmetic
        // TODO: Add your service operations here
        int Add();
        int Sub();
        int Mult();
        double Div();


    public class ArithData
        private int numb1;
        private int numb2;
        public int Numb1
            get{ return numb1;}
            set{ numb1 = value;}
        public int Numb2
            get{return numb2;}
            set{numb2 = value;}
public class Arithmetic : IArithmetic
        ArithData objArithData = new ArithData();
        int numb1;
        int numb2;
        public Arithmetic()
            numb1 = objArithData.Numb1;
            numb2 = objArithData.Numb2;
        public int Add()
            return numb1 + numb2;
        public int Sub()
            return numb1 - numb2;
        public int Mult()
            return numb1 * numb2;
        public double Div()
            return numb1 / numb2;
//my client side code
protected void Page_Load(object sender, EventArgs e)
            int numb1 = Convert.ToInt32(this.txtnumb1.Text);
            int numb2 = Convert.ToInt32(this.txtnumb2.Text);
            ArithmeticFunc.ArithmeticClient ArithClient = new ArithmeticFunc.ArithmeticClient();
//I want to create instance of Datacontract - "ArithData" class that i can pass numb1 and numb2 parameters to the ArithData Constructor.
Posted 18-Feb-13 3:56am
Updated 18-Feb-13 4:23am
S. M. Ahasan Habib 19-Feb-13 6:13am
What type of problem you face to crate instance of ArithmeticClient datacontract object? Any compilation error? Please post error details. 19-Feb-13 6:25am
Hi Ahasan, Thanks for your comment. I'm not getting any error. My problem here is that when I put . next to the ArithClient, it doesn't show up the Datacontract "ArithData" class. It only shows the OperationContracts defined in the iArithmetic interface. I want to create an instance of "ArithData" datacontract class so that i can assign values to its public variables numb1 and numb2.
S. M. Ahasan Habib 19-Feb-13 6:37am
Then make sure datacontract class dll reference in your project. DataContract class dll need to refer to your project, otherwise it do not find that datacontract class. 19-Feb-13 7:00am
Thanks!! It works now :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 4,899
CHill60 3,205
Maciej Los 2,453
Jochen Arndt 1,935
ppolymorphe 1,795

Advertise | Privacy | Mobile
Web02 | 2.8.170518.1 | Last Updated 18 Feb 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100