Skip to content
Advertisement

Retrive DataSet from WCF application

I got the result in WCF Test Client while debugging, not sure how to get dataset value in browser. am working for the first time on wcf project

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

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

i think, i need to mention some bindings in config file to make it work. Not sure how to configure

Any Suggestions

Advertisement

Answer

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.
WCF webservice hosted on IIS returns empty xml response
Second, by default DataSet could be returned properly without specifying the name, this point is different from DataTable type.
Passing an inherited “Data Contract” through WCF call?
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.
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.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement