none
Unable to deploy WCF Service onto a new website in IIS 8.0 - VS 2013, FRAMEWORK 4.5 RRS feed

  • Question

  • I have created a  wcf restservice with VS 2013,  IIS 8.0, and  using the asp.net framework 4.5.

    when i press F5 , service is working but i am unable to publish the wcf service into a the local iis  web site.

    <?xml version="1.0"?>
    <configuration>
    
      <appSettings>
        <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
      </appSettings>
      <system.web>
        <compilation debug="true" targetFramework="4.5" />
        <httpRuntime targetFramework="4.5"/>
        <customErrors mode="Off"></customErrors>
      </system.web>
      <system.webServer>
        <httpErrors errorMode="Detailed" />
      </system.webServer>
      <system.serviceModel>
        
        <behaviors>
          <serviceBehaviors>
            <behavior name="ServiceBehavior">
              <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
              <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
              <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
              <serviceDebug includeExceptionDetailInFaults="false"/>
            </behavior>        
          </serviceBehaviors>
    
          <endpointBehaviors>
            <behavior name="web">
              <webHttp/>
            </behavior>
          </endpointBehaviors>
          </behaviors>
        <services>
          <service name="NPDWCFService.NPDRESTService" behaviorConfiguration="ServiceBehavior">
            <host>
              <baseAddresses>
                <add baseAddress="http://localhost:8090/"/>
          </baseAddresses> 
        </host>
            <endpoint address="" binding="webHttpBinding" contract="NPDWCFService.INPDRESTService" behaviorConfiguration="web">
            </endpoint>
          </service>
        </services>
        <protocolMapping>
            <add binding="basicHttpsBinding" scheme="https" />
        </protocolMapping>    
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
      </system.serviceModel>
      <system.webServer>
        <modules runAllManagedModulesForAllRequests="true"/>
        <!--
            To browse web app root directory during debugging, set the value below to true.
            Set to false before deployment to avoid disclosing web app folder information.
          -->
        <directoryBrowse enabled="true"/>
      </system.webServer>
    
    </configuration>

     here is the inpd

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Runtime.Serialization;
    using System.ServiceModel;
    using System.ServiceModel.Web;
    using System.Text;
    
    namespace NPDWCFService
    {
        // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "INPDRESTService" in both code and config file together.
        [ServiceContract]
        public interface INPDRESTService
        {
            [OperationContract]
            void DoWork();
    
              [OperationContract]
            [WebInvoke(Method = "GET", UriTemplate = "/GetProducts/{ProductId}", BodyStyle = WebMessageBodyStyle.Wrapped, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
            List<Product> GetProducts(string ProductId);
    
    
            [OperationContract]
            [WebInvoke(Method = "GET", UriTemplate = "/PayBill/{PayId}", BodyStyle = WebMessageBodyStyle.Wrapped, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
            string PayBill(string PayId);
    
    
    
            [OperationContract]
            [WebInvoke(Method = "GET", UriTemplate = "/GetAllProducts", BodyStyle = WebMessageBodyStyle.Wrapped, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
            List<Product> GetAllProducts();
    
            [OperationContract]
            [WebInvoke(Method = "GET", UriTemplate = "/GetProductByID/{pproductID}", BodyStyle = WebMessageBodyStyle.Wrapped, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
            Product GetProductByID(string pproductID);
    
            [OperationContract]
            [WebInvoke(Method = "GET", UriTemplate = "/GetProductPriceByID/{pproductID}", BodyStyle = WebMessageBodyStyle.Wrapped, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
            int GetProductPriceByID(string pproductID);
    
                   
    
        }

    my product.cs code:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    
    namespace NPDWCFService
    {
        public class Product
        {
            public int ProductID { get; set; }
            public string ProductName { get; set; }
            public string ProductCategory { get; set; }
            public int Price { get; set; }
    
                private int mprodid;
                private string mprodname;
                private string mprodcat;
                private int mprice;
    
               public Product() { }
    
               public  Product(int mprodid,string mprodname,string mprodcat,int mprice)
                {
                    this.mprodid = mprodid;
                    this.mprodname = mprodname;
                    this.mprodcat = mprodcat;
                    this.mprice = mprice;
    
                }
        }
    }
     
    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=Vsrvr1;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;
    
                 try
                {
                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);
                }
    
                }
                catch (Exception exp11)
                {
                    throw new Exception(exp11.Message.ToString() + " __ " + exp11.StackTrace.ToString());
                }
                // return prodd;
    
    
                myConnection.Close();
    
                return productList;
                //Code logic to get all students.
            }

     i went to soln explorer and clicked on publish and selected the filesystem and published on  "E:\wcf1" folder , thus its created bin folder, service file and and  .config file.

    now i went to the IIS manager , and added a  new web site and selected the .net 4.5 as the application pool and selected the path e:wcf1 folder.

    but when i tried to navigate to the service, it gives me " end point not found error."

    what settings i need to add / change in web config / or in code such that i am able to get the correct service deployed in IIS .

    I need to take these file and create the same i another server for the purpose integrating with another .net web appln html files.

       wcf-requesterror






    • Edited by SaMolPP Monday, March 6, 2017 8:14 AM
    Monday, March 6, 2017 7:15 AM

All replies

  • Hi SaMolPP,

    >> but when i tried to navigate to the service, it gives me " end point not found error."

    How did you navigate to the service? Did you open svc file in IIS or in VS? Based on your address in IE, it seems you open the svc file in VS. What is the port number for web site in IIS?

    When you host WCF Service in IIS, the base address would not affect the address for WCF Service. You need to use the address in IIS. If you host in default web site whose port is 80, the service address should be http://localhost/WCFRest/RestService.svc.

    I suggest you to open svc file from IIS manager.

    Best Regards,

    Edward


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, March 7, 2017 4:26 AM
  • i dont want to use localhost port for this wcf service  hosting.

    because this is  sharepoint farm and sharepoint web appln is running on 80 port,

    so i wanna  avoid that scenario and would like to  run this wcf on a different pot number. so i created a new website from iis , iis manager and created a new port number 8091 and mapped the deployed wcf service to this directory.

    and checked the checkbox for "start website immediately" .

    but that also failed! so what must be done in order to make this wcf hosted in a different port number and set it running. 

    i am using the  IIS web site  craeted by me, thats localhost:8091 port number with a ppln pool set as

    .net 4.5 and copied the bin, .svc file, web config file on the folder.

    After performing this, if i navigate to this service, am getting the endpoint not found error.

    when i tested this business logic in a  separate console appln , it works peRFectly without any issues / errors.

    when in its clubbed inside this WCF Service, its throwing errors, so i am sure something must be wrong with WCF Service. Am not sure whether its a web config  entry missing issue or any IIS settings issue or something else.

    • Edited by SaMolPP Tuesday, March 7, 2017 12:12 PM
    Tuesday, March 7, 2017 7:26 AM
  • Hi,

    It seems you encountered different errors. In original post, it is “The server encountered an error processing the request”. And now, it seems to be “getting the endpoint not found error”. Did you make a test with the same folder “E:WCF1”?

    The steps seem OK. Could you share us a screen shot about your published Folder and web application contents in IIS?

    If you access http://localhost:8091/NPDRESTService.svc, will you get the same error? If not, I assume your URL is wrong, and I suggest you check method name and parameter name.

    If you add a new HTML file in published folder, and then access it from IE, will it show correctly?

    Best Regards,

    Edward


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, March 8, 2017 2:31 AM