【问题标题】:Web service send id to another source and return informationWeb 服务将 id 发送到另一个源并返回信息
【发布时间】:2020-11-11 18:47:53
【问题描述】:

所以我对 Web 服务有点陌生,我正在努力了解它是如何工作的。

基本上,我需要从一侧接收一个 ID,将其传递给另一个返回员工信息的来源。

现在,这就是我到目前为止所做的:

[WebMethod(Description = "Returns employee object for id")]
    public Employee GetEmployeeById(int Id)
    {
       // how to ?
        return new Employee( // data from outer source);
    }

我看到了 wsdl,您可以在其中将 id 发送给函数。

其他来源如何从我的服务中获取信息?

【问题讨论】:

    标签: asp.net .net web-services


    【解决方案1】:

    另一个来源意味着您想连接的任何地方。也许它是一个数据库、其他网络服务,或者只是一个文本文件......

    例如,您有一个保存员工数据的数据库。您可以使用实体框架从数据库中获取员工数据。

    像这样:

    [WebMethod(Description = "Returns employee object for id")]
    public Employee GetEmployeeById(int Id)
    {
        using(var context = new MyDbContext())
        {
            var emp = context.Employees.Where(x => x.Id == Id).FirstOrDefault();
            return emp;
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-07-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多