WCF-Service-via-IIS7 - Winform-Client-problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • StevenSchultz
    New Member
    • Mar 2010
    • 1

    WCF-Service-via-IIS7 - Winform-Client-problem

    I have a Winforms client with a service referance to a WCF service that have created and is being hosted on IIS7. There is nothing else in the Form, I just added code to Form_Load event to test. In the winforms client, if I call the defualt operation GetData(int) it returns correct value.. Calling my own I always get null.... (No exceptions)

    Now, the WCF service is using Linq To SQL DataContext.. In the WCF Test Client my operations work as expected when they are invoked... (as well as the default operations).

    Any help would be greatly appreciated!


    Code:
            [OperationContract]
    
            Employee GetEmployee(string employeeID);
    
    
    
    /////////////////// Sample from Service Code ////////////////
           public Employee GetEmployee(string employeeID)
            {
                Employee emp = new Employee();
    
                using (DataClasses1DataContext dc = new DataClasses1DataContext())
                {
                    try
                    {
                        emp = dc.Employees.Where(e => e.EmployeeID == employeeID).First();
                        dc.Dispose();
                    }
                    catch (Exception msg)
                    {
                        System.Diagnostics.Debug.Print(msg.Message);
                        dc.Dispose();
                    }
                }
                return emp;
            }
    
    ///////////////////////// Code in Winform /////////////////////
    
    
            private void Form1_Load(object sender, EventArgs e)
            {
                ServiceReference1.Employee emp = new WindowsFormsApplication1.ServiceReference1.Employee();
    
                ServiceReference1.Service1Client client = new WindowsFormsApplication1.ServiceReference1.Service1Client();
    
                string str = client.GetData(1); // Returns "You Entered 1"
                emp = client.GetEmployee("John Q Public"); // Returns NULL....
    
                client.Close();
            }
  • Christian Binder
    Recognized Expert New Member
    • Jan 2008
    • 218

    #2
    At line 25, where you return the emp-object, does the emp-object have a value or is it already null?
    Maybe the disposal of the DataClasses1Dat aContext-object causes the emp to be null. (By the way: you don't have to call dc.Dispose(), it's done implicitely when using the using-statement.)

    Did you specify the [DataContract] and [DataMember] attributes for Employee-class and it's members (properties)?

    You could try returning a native type like string or int instead of complex Employee-type (e.g. the Employee's name or the Employee's age)

    Comment

    Working...