Click here to Skip to main content
Sign Up to vote bad
good
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.
   [ServiceContract]
    public interface IArithmetic
    {
 
        // TODO: Add your service operations here
        [OperationContract]
        int Add();
 
        [OperationContract]
        int Sub();
 
        [OperationContract]
        int Mult();
 
        [OperationContract]
        double Div();
 

    }
 

    [DataContract]
    public class ArithData
    {
 
        private int numb1;
        private int numb2;
 
        [DataMember]
        public int Numb1
        {
            get{ return numb1;}
            set{ numb1 = value;}
        }
 
        [DataMember]
        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 here...so that i can pass numb1 and numb2 parameters to the ArithData Constructor.

        }
Posted 18 Feb '13 - 3:56
Edited 18 Feb '13 - 4:23

Comments
S. M. Ahasan Habib - 19 Feb '13 - 6:13
What type of problem you face to crate instance of ArithmeticClient datacontract object? Any compilation error? Please post error details.
Rajarajan.here - 19 Feb '13 - 6:25
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:37
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.
Rajarajan.here - 19 Feb '13 - 7:00
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
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 239
1 OriginalGriff 188
2 Mahesh Bailwal 139
3 Maciej Los 135
4 Aarti Meswania 98
0 Sergey Alexandrovich Kryukov 10,214
1 OriginalGriff 7,819
2 CPallini 4,181
3 Rohan Leuva 3,522
4 Maciej Los 3,089


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