i have created a wcf ret service using VS 2013/ using ,net 4.5 fw. which connects to a sql db and fetch records.
now i need to deploy this wcf service onto a different server with a different port number [other than 80 ] and consume it from ajax jquery html controls.
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
namespace NPDWCFService
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "NPDRESTService" in code, svc and config file together.
// NOTE: In order to launch WCF Test Client for testing this service, please select NPDRESTService.svc or NPDRESTService.svc.cs at the Solution Explorer and start debugging.
public class NPDRESTService : INPDRESTService
{
private static string strConn;
public void DoWork()
{
}
//public string GetProducts(string ProductId)
//{
// return "get all products with product id " + ProductId + " was successful";
//}
static string strConn1 = @"Data Source=srv1;Initial Catalog=Products;Integrated Security=True";
public List<Product> GetAllProducts()
{
var productList = new List<Product>();
SqlDataReader reader = null;
SqlConnection myConnection = new SqlConnection();
Product objallproducts = new Product();
//Server = myServerAddress; Database = myDataBase; User Id = myUsername; Password = myPassword;
myConnection.ConnectionString = strConn1;
SqlCommand sqlCmd = new SqlCommand();
sqlCmd.CommandType = CommandType.Text;
sqlCmd.CommandText = "Select * from tblProducts"; // where ProductId=" + id + "";
sqlCmd.Connection = myConnection;
myConnection.Open();
reader = sqlCmd.ExecuteReader();
Product prodd = null;
while (reader.Read())
{
prodd = new Product();
prodd.ProductID = Convert.ToInt32(reader.GetValue(0));
prodd.ProductName = reader.GetValue(1).ToString();
prodd.ProductCategory = reader.GetValue(2).ToString();
prodd.Price = Convert.ToInt32(reader.GetValue(3));
productList.Add(prodd);
}
// return prodd;
myConnection.Close();
return productList;
//Code logic to get all students.
}i have created a website from iis and given this url in the publish --> web deploy --> destination url as : http://localhost:8089/