Click here to Skip to main content
12,399,362 members (59,049 online)
Rate this:
 
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.
   [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:56am
Updated 18-Feb-13 4:23am
v2
Comments
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.
Rajarajan.here 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.
Rajarajan.here 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


Advertise | Privacy | Mobile
Web02 | 2.8.160721.1 | Last Updated 18 Feb 2013
Copyright © CodeProject, 1999-2016
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