【问题标题】:Retrive DataSet from WCF application从 WCF 应用程序中检索数据集
【发布时间】:2020-01-23 22:53:36
【问题描述】:

我在调试时在 WCF 测试客户端中得到了结果,不知道如何在浏览器中获取数据集值。我是第一次在 wcf 项目上工作

IService.cs

[ServiceContract]
    public interface IService
    {
        [OperationContract]
        DataSet Permit(getPermit name);
    }

    [DataContract]
    public class getPermit{

        string name = string.Empty;

        [DataMember]
        public string Name
        {
            get { return name; }
            set { name = value; }
        }
    }

服务.SVC

public System.Data.DataSet Permit(getPermit name)
        {
            DataSet ds = new DataSet();
            string connection = ConfigurationManager.ConnectionStrings["xyz"].ConnectionString.ToString();
            string cmdText = "sql Query";
            SqlConnection con = new SqlConnection(connection);
            con.Open();
            SqlCommand cmd = new SqlCommand(cmdText, con);     
            cmd.ExecuteNonQuery();
            using (SqlDataAdapter da = new SqlDataAdapter(cmd))
            {
                da.Fill(ds);
                return ds;
            }
        }

部署到IIS后,将参数作为查询字符串传递后没有任何结果

我想,我需要在配置文件中提及一些绑定以使其工作。 不知道如何配置

任何建议

【问题讨论】:

  • 为什么不将数据集更改为 List,并将数据成员用于 T 的属性,完全基于 C# 的数据集,使用哪个 WCF 绑定?基本http或web
  • 我正在使用网络 @AkshayJoy

标签: c# sql wcf


【解决方案1】:

起初,问题与数据集无关。连接数据库失败是问题所在。我建议您检查连接字符串是否使用集成安全来建立连接。当我们将项目部署到 IIS 时,应用程序池标识将替换运行 VS 的标识,从而导致数据库连接无效。
WCF webservice hosted on IIS returns empty xml response
其次,默认情况下DataSet可以在不指定名称的情况下正确返回,这点与DataTable类型不同。
Passing an inherited "Data Contract" through WCF call?
最后,除了返回的数据太大外,与绑定配置无关。正如 Akshay 所说,返回数据集并不是传输数据的最佳实践,我们最好考虑使用 List 并使用 DataContract 自定义用户类。
https://docs.microsoft.com/en-us/dotnet/framework/wcf/feature-details/using-data-contracts
如果问题仍然存在,请随时告诉我。

【讨论】:

    猜你喜欢
    • 2021-07-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-30
    • 2016-06-12
    • 1970-01-01
    • 2020-04-24
    • 1970-01-01
    相关资源
    最近更新 更多