Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: WCF
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 4:56am
Edited 18-Feb-13 5:23am
(no name)498.5K
S. M. Ahasan Habib at 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. at 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 at 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. at 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
0 OriginalGriff 7,853
1 Sergey Alexandrovich Kryukov 7,107
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,790

Advertise | Privacy | Mobile
Web03 | 2.8.1411023.1 | Last Updated 18 Feb 2013
Copyright © CodeProject, 1999-2014
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