Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Oct 14, 2010 09:11 AM by Wencui Qian - MSFT
Member
13 Points
17 Posts
Oct 11, 2010 06:10 AM|LINK
hi, i created a service like this [OperationContract (Name = "GetAllCustomer")] [WebInvoke(ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate="/View/Data?format={fr}", Method="GET" )] Customer[] GetAllCustomer(); public class Customer { [DataMember] public int CNo { get; set; } [DataMember] public string CName { get; set; } }
hi,
i created a service like this
and access my db in service.svc.cs
List<Customer> lstEmp = new List<Customer>();
String connString = ConfigurationManager.ConnectionStrings["connWebOrdering"].ConnectionString; SqlConnection sqlConn = new SqlConnection(connString); sqlConn.Open();
SqlDataAdapter da = new SqlDataAdapter("Select [cid], [cname] from [CustomerDB].[dbo].[contact] ", sqlConn); DataSet ds = new DataSet(); da.Fill(ds, "Cust"); foreach (DataRow dr in ds.Tables["Cust"].Rows) { lstEmp.Add(new Customer() { CNo = Convert.ToInt32(dr[0]), CName = Convert.ToString(dr[1]), }); sqlConn.Close(); return lstEmp.ToArray();
but if i run the service its showing server error... !! the server cannot process your request...
WCF Data Access
All-Star
56784 Points
5796 Posts
Microsoft
Oct 14, 2010 09:11 AM|LINK
ganesh1988 but if i run the service its showing server error... !! the server cannot process your request...
I think this error message doesn't mean that it's caused by the data access. Is the RESTful service workable? Or did you get any other try? Thanks.
ganesh1988
Member
13 Points
17 Posts
Access Database through WCF REST
Oct 11, 2010 06:10 AM|LINK
and access my db in service.svc.cs
List<Customer> lstEmp = new List<Customer>();
String connString = ConfigurationManager.ConnectionStrings["connWebOrdering"].ConnectionString; SqlConnection sqlConn = new SqlConnection(connString); sqlConn.Open();SqlDataAdapter da = new SqlDataAdapter("Select [cid], [cname] from [CustomerDB].[dbo].[contact] ", sqlConn);
DataSet ds = new DataSet();
da.Fill(ds, "Cust");
foreach (DataRow dr in ds.Tables["Cust"].Rows)
{
lstEmp.Add(new Customer()
{
CNo = Convert.ToInt32(dr[0]),
CName = Convert.ToString(dr[1]),
});
sqlConn.Close();
return lstEmp.ToArray();
but if i run the service its showing server error... !! the server cannot process your request...
WCF Data Access
Wencui Qian ...
All-Star
56784 Points
5796 Posts
Microsoft
Re: Access Database through WCF REST
Oct 14, 2010 09:11 AM|LINK
I think this error message doesn't mean that it's caused by the data access. Is the RESTful service workable? Or did you get any other try? Thanks.
If you have any feedback about my replies, please contact msdnmg@microsoft.com
Microsoft One Code Framework