Click here to Skip to main content
15,893,508 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all,

i have a sql table as (EMP), columns are (empid int,empname string,salary varchar,deptno int). here empid as primary key. (some rows are inserted already).for that i need to create wcf service i.e wcf service accepts empid and return the remaining values like empname,salary,deptno. and also in that wcf service able to insert the employee details.[insert details will save into sql EMP table). for that requirement how can i write WCF Service in .net. please any one help to me.

thnaks in advance.

nareshrajuu.
Posted
Updated 18-Apr-12 17:44pm
v2
Comments
[no name] 18-Apr-12 22:46pm    
"i want to create wcf service"... Well, you have my permission. Please come back when you have a specific question to a specific proplem.

Create a data model (for employee) that is shared across the server and the client.
Return a collection of this data model.

Or you can always return multiple values via an xml.
 
Share this answer
 
Comments
VJ Reddy 19-Apr-12 20:00pm    
Good suggestion. 5!
What you need to do is create a class deoorated with the DataContract attribute. This class contains all information you need to tranfer, which can include everything you want to transfer using wcf. Best to look at the following CodeProject article on WCF: A Windows Communication Foundation (WCF) Overview[^]
 
Share this answer
 
Comments
VJ Reddy 19-Apr-12 20:00pm    
5!
Abhinav S 19-Apr-12 21:59pm    
Thanks.
It might help,

C#
using System.ServiceModel;

namespace Example
{
    public class EmployeeDetailsResponse
    {
        public string Name { get; set; }
        public string Salary { get; set; }
    }

    public class EmployeeSaveDetailsRequest
    {
        public string Name { get; set; }
        public string Salary { get; set; }
    }

    [ServiceContract]
    public interface ISomeoperation
    {
        [OperationContract]
        public EmployeeDetailsResponse GetEmpDetails();
        [OperationContract]
        public void SaveEmployeeDetails(EmployeeSaveDetailsRequest employeeSaveDetailsRequest);
    }

    public class SomeOperation : ISomeoperation
    {
        public EmployeeDetailsResponse GetEmpDetails()
        {
            //Implemet the operation
            return new EmployeeDetailsResponse(); // by filling the EmployeeDetailsResponse
        }

        public void SaveEmployeeDetails(EmployeeSaveDetailsRequest employeeSaveDetailsRequest)
        {
            //Implemet the operation
        }
    }

}


:)
 
Share this answer
 
Hi,

This link fulfills your both needs, returning matching value of an id and inserting using a WCF service

http://nareshkamuni.blogspot.in/2012/04/inserting-and-retrieving-data-from.html[^]
 
Share this answer
 
Comments
Unareshraju 19-Apr-12 7:12am    
thanks deepak.....
https://www.windowsazure.com/en-us/develop/net/how-to-guides/table-services/

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900