Database Reference
In-Depth Information
When the WCF application project is created, a service class and corresponding
interface template are added to the project. Declare the Service Contract and Operation
Contract (as shown below) interface class that will be implemented in your derived
class. Because the intention is to retrieve a data table from this service, the data contract
method will be of type DataTable:
[ServiceContract]
public interface IServerStatus
{
[OperationContract]
DataTable GetServerStatusDetails();
}
Under the derived class in the implemented method GetServerStatusDetails, create
the data objects needed for the output:
DataSet dataSet = new DataSet();
Next, create the SQL Connection using the connection string from Web.config:
SqlConnection connection = new SqlConnection(ConfigurationManager.Connection
Strings["VisioServicesConnectionString"].ConnectionString);
Create the command object by calling the stored procedure with the help of the SQL
Connection and set the command type to StoredProcedure:
SqlCommand command = new SqlCommand("uspGetServerDetails", connection);
command.CommandType = CommandType.StoredProcedure;
Finally, create the data adapter, load the command, and fill the data set using the
data adapter:
SqlDataAdapter dataAdapter = new SqlDataAdapter(command);
dataAdapter.Fill(dataSet);
Close the connection and return the output:
connection.Close();
return dataSet.Tables[0];
If you are a novice wCF developer, simply start from here:
http://blah.winsmarts.com/2008-4-Writing_the_WCF_Hello_World_App.aspx .
Tip
 
 
Search WWH ::




Custom Search