如何使用WCF返回多个值 [英] How to return more than one value using WCF

查看:108
本文介绍了如何使用WCF返回多个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有一个(EMP)的sql表,列是(empid int,empname字符串,salary varchar,deptno int).这里以empid作为主键. (已经插入了一些行).为此,我需要创建wcf服务,即wcf服务接受empid并返回剩余的值,例如empname,salary,deptno.并在该wcf服务中能够插入员工详细信息.[插入详细信息将保存到sql EMP表中).对于该要求,我如何在.net中编写WCF服务.请任何人帮我.

提前打个招呼.

nareshrajuu.

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.

推荐答案

创建在服务器和客户端之间共享的(员工)数据模型.
返回此数据模型的集合.

或者,您始终可以通过xml返回多个值.
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.


您需要做的是创建一个使用DataContract属性清除的类.此类包含您需要转移的所有信息,其中包括您想使用wcf进行传输的所有信息.最好查看WCF上的以下CodeProject文章: Windows Communication Foundation(WCF)概述 [ ^ ]
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[^]


可能会有所帮助,

It might help,

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
        }
    }

}



:)



:)


这篇关于如何使用WCF返回多个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆