Click here to Skip to main content
Rate this: bad
good
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
Edited 18-Feb-13 4:23am
495.6K
v2
Comments
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.
Rajarajan.here 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.
Rajarajan.here 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 375
1 Sergey Alexandrovich Kryukov 170
2 CHill60 160
3 RyanDev 135
4 Richard MacCutchan 115


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