locked
deploy wcf service on a different server and consume it from ajax, jquery controls RRS feed

  • Question

  • User751840860 posted

    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.

     wcf1

    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/

    Thursday, March 2, 2017 6:36 AM

Answers

All replies

  • User-1509636757 posted

    What is the issue that you are facing?

    Thursday, March 2, 2017 8:53 AM
  • User751840860 posted

    How to publish this web service onto a  different server, and  consume it from jQuery ajax,  html controls and bind those values.

    Thursday, March 2, 2017 11:06 AM
  • User-1509636757 posted

    There is no difference in publishing WCF to publishing a website. You can create a website/virtual directory and point to WCF application folder.

    Here is a step by step guide: IIS 8.0 Using ASP.NET 3.5 and ASP.NET 4.5 : The Official Microsoft IIS Site

    Thursday, March 2, 2017 11:38 AM
  • User751840860 posted

    Am getting the error :

    Request Error

    The server encountered an error processing the request. See server logs for more details.

    when i tried to publish this service.

    Thursday, March 2, 2017 12:40 PM
  • User-1509636757 posted

    can you provide detail on when exactly this happens? Is the error occurring when you try to browse? You may look below links on similar topic:

    1. Error: The server encountered an error processing the request. See server logs for more details
    2. wcf - The server encountered an error processing the request. See server logs for more details
    3. WCF Data Service Error – Request Error
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, March 2, 2017 12:55 PM
  • User751840860 posted

    am sorry, I am unable to see asp.net 4 / asp.net 4.5  application pool in y IIS 8.0

    I checked this  video : https://www.youtube.com/watch?v=g-w1GvkwErk

    https://www.youtube.com/watch?v=PBAs3zw6rq0 

    so, I need to select asp.net 4.0 as the appln pool , which I have not done previously.

    so I am trying to configure asp.net 4.0 appln pool :

     I have win server 2012 r2 STD as the windows os . I have configured iis  long back including the asp.net 3.5 and 4.5 extensibility etc.

    but when I tried to  add a website for this wcf service in IIS,  and when I tried to select application pool, am not able to see , asp.net 4.0 / 4.5 in the list.

     went to  net framework 4.0.030319 directory and tried to run the aspnet_regiis  -ir command . but it gave me a message . but the appln pool is not created.   

     C:\Windows\Microsoft.NET\Framework\v4.0.30319>iisreset

    Attempting stop... Internet services successfully stopped Attempting start... Internet services successfully restarted

    C:\Windows\Microsoft.NET\Framework\v4.0.30319>ASPNET_regiis.exe -i

    Microsoft (R) ASP.NET RegIIS version 4.0.30319.33440 Administration utility to install and uninstall ASP.NET on the local machine. Copyright (C) Microsoft Corporation.  All rights reserved. Start installing ASP.NET (4.0.30319.33440). This option is not supported on this version of the operating system.  Administr ators should instead install/uninstall ASP.NET 4.5 with IIS8 using the "Turn Win dows Features On/Off" dialog,  the Server Manager management tool, or the dism.e xe command line tool.  For more details please see http://go.microsoft.com/fwlin k/?LinkID=216771. Finished installing ASP.NET (4.0.30319.33440).

    C:\Windows\Microsoft.NET\Framework\v4.0.30319>

    Thursday, March 2, 2017 1:04 PM
  • User-1509636757 posted

    am not able to see , asp.net 4.0 / 4.5 in the list.

    There are only two base CLR version that you should be able to see:

    Since you are working with framework 4.5, you should select CLR Version v4.0.30319.

    Thursday, March 2, 2017 1:12 PM
  • User1168443798 posted

    >> Administr ators should instead install/uninstall ASP.NET 4.5 with IIS8 using the "Turn Win dows Features On/Off" dialog,  the Server Manager management tool, or the dism.e xe command line tool

    Per this error message, it seems you did not install Asp.net 4.5 under IIS 8. I suggest you follow the link from kaushalparik... to configure your IIS before publishing service to IIS.

    # IIS 8.0 Using ASP.NET 3.5 and ASP.NET 4.5

    https://www.iis.net/learn/get-started/whats-new-in-iis-8/iis-80-using-aspnet-35-and-aspnet-45

    Friday, March 31, 2017 7:00 AM