简体   繁体   English

从 WCF 应用程序中检索数据集

[英]Retrive DataSet from WCF application

I got the result in WCF Test Client while debugging, not sure how to get dataset value in browser.我在调试时在 WCF 测试客户端中得到了结果,不知道如何在浏览器中获取数据集值。 am working for the first time on wcf project我第一次在 wcf 项目上工作

IService.cs 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; }
        }
    }

Service.SVC服务.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;
            }
        }

After deploying to IIS, I didn't got any result after passing parameter as query string部署到 IIS 后,将参数作为查询字符串传递后没有任何结果

i think, i need to mention some bindings in config file to make it work.我想,我需要在配置文件中提及一些绑定以使其工作。 Not sure how to configure不知道怎么配置

Any Suggestions有什么建议么

At first, the problem doesn't relate to dataset.起初,问题与数据集无关。 The failure of connecting the database is the issue.连接数据库失败是问题所在。 I suggest you check whether the connection string use the integrated security to build the connection.我建议你检查连接字符串是否使用集成安全来建立连接。 When we deploy the project to IIS, Application pool identity will replace the identity that running VS, thereby the database connection will be invalid.当我们将项目部署到 IIS 时,应用程序池标识将替换运行 VS 的标识,从而导致数据库连接无效。
WCF webservice hosted on IIS returns empty xml response WCF 托管在 IIS 上的 Web 服务返回空 xml 响应
Second, by default DataSet could be returned properly without specifying the name, this point is different from DataTable type.其次,默认情况下DataSet可以在不指定名称的情况下正确返回,这点与DataTable类型不同。
Passing an inherited "Data Contract" through WCF call? 通过 WCF 调用传递继承的“数据合同”?
At last, the issue has none business with binding configuration except the returned data is too large.最后,除了返回的数据太大外,与绑定配置无关。 As Akshay mentioned, returning a dataset is not a best practice of transmitting data, we had better consider List and custom the user class with DataContract.正如 Akshay 所提到的,返回数据集并不是传输数据的最佳实践,我们最好考虑 List 并使用 DataContract 自定义用户 class。
https://docs.microsoft.com/en-us/dotnet/framework/wcf/feature-details/using-data-contracts https://docs.microsoft.com/en-us/dotnet/framework/wcf/feature-details/using-data-contracts
Feel free to let me know if the problem still exists.如果问题仍然存在,请随时告诉我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM