locked
Publish WCF in IIS 7 RRS feed

  • Question

  • Hello, I just wrote a simple WCF. The corresponding files are:

    IService.cs

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Runtime.Serialization;
    using System.ServiceModel;
    using System.ServiceModel.Web;
    using System.Text;
    
    namespace WcfService1
    {
        // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together.
        [ServiceContract]
        public interface IService
        {
            [OperationContract]
            List<ActiveSP> GetActiveSP();
        }
    
        [DataContract]
        public class ActiveSP
        {
            [DataMember]
            public string DESCR { get; set; }
        }
    }

    Service.svc.cs:

    using System; using System.Collections.Generic; using System.Linq; using System.Runtime.Serialization; using System.ServiceModel; using System.ServiceModel.Web; using System.Text; using System.Data.SqlClient; namespace WcfService1 { public class Service : IService { SqlConnection Conn; SqlCommand Cmd; public Service() { Conn = new SqlConnection("Data Source=myweb;Initial Catalog=PeopleSoft;Integrated Security=True;"); } public List<ActiveSP> GetActiveSP() { Conn.Open(); Cmd = new SqlCommand(); Cmd.Connection = Conn; Cmd.CommandText = "Select DESCR from myTable"; SqlDataReader Reader = Cmd.ExecuteReader(); List<ActiveSP> listSP = new List<ActiveSP>(); while (Reader.Read()) { listSP.Add(new ActiveSP() { DESCR = Reader[0].ToString() }); } Reader.Close(); Conn.Close(); return listSP; } } }

    The Web.config is:

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <system.serviceModel>
        <services>
          <!-- This section is optional with the default configuration
            model introduced in .NET Framework 4 -->
          <service name="WcfService1.Service">
    
          <endpoint address=""
                      binding="wsHttpBinding"
                      contract="WcfService1.Service.IService" />
    
          <endpoint address="mex"
                      binding="mexHttpBinding"
                      contract="IMetadataExchange" />
          </service>
        </services>
      </system.serviceModel>
    
    </configuration>

    My question is how to publish it in IIS?

    Thanks.




    • Edited by ardmore Tuesday, August 7, 2012 6:37 PM add
    Tuesday, August 7, 2012 5:42 PM

Answers

  • Hello,

    Enter Localhost in Service URL (If you want to publish on local machine)
    In Site/Applicaiton - Give website name / Application Name
    Application will be automatically created once you publish your WCF Service.

    For example, If you give this
    Default Web Site/TestWCFAPP

    TestWCFApp application would be automatically created on IIS and you can find your WCF service inside this Application

    Thanks
    • Marked as answer by ardmore Wednesday, August 8, 2012 1:20 PM
    Wednesday, August 8, 2012 12:42 PM

All replies

  • Have a look at this

    You need a svc file, create the svc file in WCF application directory. Then add a virtual directory to your iis and point to your WCF service application directory


    Tanvir Huda Application Architect/Consultant http://thetechnocrate.wordpress.com/

    Tuesday, August 7, 2012 11:21 PM
  • The link you gave me needs to type the code in IIS instead of creating a WCF project in Visual Studio first, so I followed this instructions.

    But what is the Site/application field?

    See image below.

    Wednesday, August 8, 2012 12:34 PM
  • Hello,

    Enter Localhost in Service URL (If you want to publish on local machine)
    In Site/Applicaiton - Give website name / Application Name
    Application will be automatically created once you publish your WCF Service.

    For example, If you give this
    Default Web Site/TestWCFAPP

    TestWCFApp application would be automatically created on IIS and you can find your WCF service inside this Application

    Thanks
    • Marked as answer by ardmore Wednesday, August 8, 2012 1:20 PM
    Wednesday, August 8, 2012 12:42 PM