无法将WCF服务部署到IIS 8.0-VS 2013,FRAMEWORK 4.5中的新网站上

问题描述:

我已经使用VS 2013,IIS 8.0和ASP.NET Framework 4.5创建了wcf restservice.

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

当我按F5键时,服务正在运行,但是我无法将wcf服务发布到本地iis网站.

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>

这是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);

               

    }

我的product.cs代码:

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.
        }

我去了soln Explorer,单击发布"并选择了文件系统,然后在"E:\ wcf1"文件夹,从而创建了它的bin文件夹,服务文件和  .config文件.

 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.

现在我去了IIS管理器,并添加了一个新网站并选择.net 4.5作为应用程序池,并选择了路径e:wcf1文件夹.

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."

我需要在Web配置中添加/更改/或更改代码中的哪些设置,以便能够在IIS中部署正确的服务.

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 .

我需要获取这些文件并在其他服务器上创建相同的文件,以便与另一个.net Web appln html文件集成.

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

   

   









SaMolPP,

Hi SaMolPP,

>>但是当我尝试导航到该服务时,它会给我找不到端点错误."

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

您是如何导航到该服务的?您是否在IIS或VS中打开svc文件?根据您在IE中的地址,似乎您在VS中打开了svc文件. IIS中网站的端口号是什么?

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?

当您在IIS中托管WCF服务时,基本地址不会影响WCF服务的地址.您需要使用IIS中的地址.如果您在端口为80的默认网站上托管,则服务地址应为 http://localhost/WCFRest/RestService.svc .

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.

我建议您从IIS管理器中打开svc文件.

I suggest you to open svc file from IIS manager.

最好的问候,

爱德华