none
Hosting WCF Service VS-2013 RRS feed

  • Question

  • Hi,

    I created a WCF service, then I created a client to consume it. Until now everything works fine.

    Now that I wanted to host this in IIS 8.0, I'm not able to get it rolling.

    Steps I followed to publish my website in IIS.

    Right click on solution then publish... below are the details I entered.

    

    then I previewed things and it worked fine.

    Now do I need to create a hosting site for this ? (With my understanding yes, so I went a head and created one)

    Below are the details I entered.

    Couple of question here for my understanding... What is the default port we need to choose for hosting a wcf service (is there one ?)

    Because for port 80 it gives me an alert at next stage to changes since its being used by another website (My guess is the default site in IIS uses it)

    If I change the port then what should it be, and why ?

    So to make it work I updated the port details to 4576 and things worked fine.. But with this port details I run into another problem  and that is... I need to keep my VS running else the path is in accessible. this makes the service not a self running service. 

    I will post the image in following message as there a restriction to upload max 2 images per message! (WCF)

    Web.config details

    <?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"/>
      </system.web>
      <system.serviceModel>
        <behaviors>
          <serviceBehaviors>
            <behavior>
              <!-- 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>
        </behaviors>
        <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>
    


    Interface code block

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Runtime.Serialization;
    using System.ServiceModel;
    using System.ServiceModel.Web;
    using System.Text;
    
    
    namespace EventGeine
    {
        // 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 IEventService
        {
    
            [OperationContract]
            string GetData(int value);
    
            [OperationContract]
            AllEventEntity GeteventsDetails(int eventId);       
        }
    
    }
    


    EventService.svc

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Runtime.Serialization;
    using System.ServiceModel;
    using System.ServiceModel.Web;
    using System.Text;
    
    namespace EventGeine
    {
        // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together.
        // NOTE: In order to launch WCF Test Client for testing this service,
        // please select Service1.svc or Service1.svc.cs at the Solution Explorer and start debugging.
        public class EventService : IEventService
        {
            public string GetData(int value)
            {
                return string.Format("You entered: {0}", value);
            }
    
            
            public AllEventEntity GeteventsDetails(int eventId)
            {
               List<AllEventEntity> ObjLazyEvent = new List<AllEventEntity>
                {
                    new AllEventEntity(){ EventId=1, EventName="LAS Events-1", EventDescription="Testing Descrption for event id 1", EventSummary="Testing EventSummary 1" },                
                    new AllEventEntity(){ EventId=2, EventName="LAS Events-2", EventDescription="Testing Descrption for event id 2", EventSummary="Testing EventSummary 2" },
                    new AllEventEntity(){ EventId=3, EventName="LAS Events-3", EventDescription="Testing Descrption for event id 3", EventSummary="Testing EventSummary 3" },
                    new AllEventEntity(){ EventId=4, EventName="LAS Events-4", EventDescription="Testing Descrption for event id 4", EventSummary="Testing EventSummary 4" }
                };
    
               return ObjLazyEvent.Find(x => x.EventId.Equals(eventId));
            }
        }
    }
    

    DataContract: AllEventEntity.cs

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    
    using System.Runtime.Serialization;
    
    namespace EventGeine
    {
        [DataContract]
        public class AllEventEntity
        {
            [DataMember]
            public int EventId { get; set; }
            [DataMember]
            public string EventName { get; set; }
            [DataMember]
            public string EventSummary { get; set; }
            [DataMember]
            public String EventDescription { get; set; }
    
        }
    }


    I also create a test client asp.net application and it worked fine!

    Monday, February 24, 2014 10:52 AM

Answers

  • Hi,

    >>Because for port 80 it gives me an alert at next stage to changes since its being used by another website (My guess is the default site in IIS uses it)If I change the port then what should it be, and why ?

    By default the port number for the http is 80, the port number for the https is 443. You can change to use the other port number. But of course there is some limit about the port number, for more information, please try to check this:

    #The limit of the port number:
    http://stackoverflow.com/questions/113224/what-is-the-largest-tcp-ip-network-port-number-allowable-for-ipv4 .

    >>But with this port details I run into another problem  and that is... I need to keep my VS running else the path is in accessible. this makes the service not a self running service

    I am not clear about what do you mean. Could you please describe it more clearly?
    And also please try to check this article:
    #How to deploy WCF Web Service on IIS:
    http://bojan-komazec.blogspot.com/2012/03/how-to-deploy-wcf-web-service-on-iis.html .

    Best Regards,
    Amy Peng


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, February 25, 2014 2:41 AM
    Moderator

All replies

  • Monday, February 24, 2014 10:53 AM
  • Hi,

    >>Because for port 80 it gives me an alert at next stage to changes since its being used by another website (My guess is the default site in IIS uses it)If I change the port then what should it be, and why ?

    By default the port number for the http is 80, the port number for the https is 443. You can change to use the other port number. But of course there is some limit about the port number, for more information, please try to check this:

    #The limit of the port number:
    http://stackoverflow.com/questions/113224/what-is-the-largest-tcp-ip-network-port-number-allowable-for-ipv4 .

    >>But with this port details I run into another problem  and that is... I need to keep my VS running else the path is in accessible. this makes the service not a self running service

    I am not clear about what do you mean. Could you please describe it more clearly?
    And also please try to check this article:
    #How to deploy WCF Web Service on IIS:
    http://bojan-komazec.blogspot.com/2012/03/how-to-deploy-wcf-web-service-on-iis.html .

    Best Regards,
    Amy Peng


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, February 25, 2014 2:41 AM
    Moderator