none
WCF hosting with windows Service, Can't browse windows service RRS feed

  • Question

  • I'm trying to build a test application to test wcf and learn more on it:

    I wrote a WCF service and hosted this in a windows service. Here's my app.config from the windows service:

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
    
      <appSettings>
        <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
      </appSettings>
      <system.web>
        <compilation debug="true" />
      </system.web>
      <!-- When deploying the service library project, the content of the config file must be added to the host's 
      app.config file. System.Configuration does not support config files for libraries. -->
      <system.serviceModel>
        <services>
          <service name="WCFLibrary.CalculatorService">
            <host>
              <baseAddresses>
                <add baseAddress = "http://localhost:8788/CalculatorService/" />
              </baseAddresses>
            </host>
            <!-- Service Endpoints -->
            <!-- Unless fully qualified, address is relative to base address supplied above -->
            <endpoint
              name ="ServiceHTTPEndPoint"
              address="" binding="basicHttpBinding" contract="WCFLibrary.ICalculator">
              <!-- 
                  Upon deployment, the following identity element should be removed or replaced to reflect the 
                  identity under which the deployed service runs.  If removed, WCF will infer an appropriate identity 
                  automatically.
              -->
              <identity>
                <dns value="localhost"/>
              </identity>
            </endpoint>
            <!-- Metadata Endpoints -->
            <!-- The Metadata Exchange endpoint is used by the service to describe itself to clients. -->
            <!-- This endpoint does not use a secure binding and should be secured or removed before deployment -->
            <endpoint
              name ="ServiceMexEndPoint"
              address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
          </service>
        </services>
        <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="True" />
            </behavior>
          </serviceBehaviors>
        </behaviors>
      </system.serviceModel>
    
    </configuration>

    Here's the implementation to start the wcf:

    namespace WindowsService
    {
        public partial class Service1 : ServiceBase
        {
            public ServiceHost serviceHost = null;
    
          
            public Service1()
            {
                InitializeComponent();
            }
    
         
            public void onDebug()
            {
                OnStart(null);
            }
    
                protected override void OnStart(string[] args)
            {
                
    
                if (serviceHost != null)
                {
                    serviceHost.Close();
                }
    
                // Create a ServiceHost for the CalculatorService type and 
                // provide the base address.
                serviceHost = new ServiceHost(typeof(CalculatorService));
    
                // Open the ServiceHostBase to create listeners and start 
                // listening for messages.
                serviceHost.Open();
                 
                
    
            }
                
    
            protected override void OnStop()
            {
    
                if (serviceHost != null)
                {
                    serviceHost.Close();
                    serviceHost = null;
                }
    
            }
        }
    }

    I can run the wcf test client just fine. After build and installing windows service, then running from the service manager. I can't seem to browse to the base address.

    Why is that the test client work but the browser doesn't.

    Please advise.

    Sunday, July 27, 2014 11:07 AM

Answers

All replies

  • I'm trying to build a test application to test wcf and learn more on it:

    I wrote a WCF service and hosted this in a windows service. Here's my app.config from the windows service:

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
    
      <appSettings>
        <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
      </appSettings>
      <system.web>
        <compilation debug="true" />
      </system.web>
      <!-- When deploying the service library project, the content of the config file must be added to the host's 
      app.config file. System.Configuration does not support config files for libraries. -->
      <system.serviceModel>
        <services>
          <service name="WCFLibrary.CalculatorService">
            <host>
              <baseAddresses>
                <add baseAddress = "http://localhost:8788/CalculatorService/" />
              </baseAddresses>
            </host>
            <!-- Service Endpoints -->
            <!-- Unless fully qualified, address is relative to base address supplied above -->
            <endpoint
              name ="ServiceHTTPEndPoint"
              address="" binding="basicHttpBinding" contract="WCFLibrary.ICalculator">
              <!-- 
                  Upon deployment, the following identity element should be removed or replaced to reflect the 
                  identity under which the deployed service runs.  If removed, WCF will infer an appropriate identity 
                  automatically.
              -->
              <identity>
                <dns value="localhost"/>
              </identity>
            </endpoint>
            <!-- Metadata Endpoints -->
            <!-- The Metadata Exchange endpoint is used by the service to describe itself to clients. -->
            <!-- This endpoint does not use a secure binding and should be secured or removed before deployment -->
            <endpoint
              name ="ServiceMexEndPoint"
              address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
          </service>
        </services>
        <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="True" />
            </behavior>
          </serviceBehaviors>
        </behaviors>
      </system.serviceModel>
    
    </configuration>
    

    Here's the implementation to start the wcf:

    namespace WindowsService
    {
        public partial class Service1 : ServiceBase
        {
            public ServiceHost serviceHost = null;
    
          
            public Service1()
            {
                InitializeComponent();
            }
    
         
            public void onDebug()
            {
                OnStart(null);
            }
    
                protected override void OnStart(string[] args)
            {
                
    
                if (serviceHost != null)
                {
                    serviceHost.Close();
                }
    
                // Create a ServiceHost for the CalculatorService type and 
                // provide the base address.
                serviceHost = new ServiceHost(typeof(CalculatorService));
    
                // Open the ServiceHostBase to create listeners and start 
                // listening for messages.
                serviceHost.Open();
                 
                
    
            }
                
    
            protected override void OnStop()
            {
    
                if (serviceHost != null)
                {
                    serviceHost.Close();
                    serviceHost = null;
                }
    
            }
        }
    }
    

    I can run the wcf test client just fine. After build and installing windows service, then running from the service manager. I can't seem to browse to the base address.

    Why is that the test client work but the browser doesn't.

    Please advise.

    Saturday, July 26, 2014 7:21 PM
  • http://social.msdn.microsoft.com/Forums/vstudio/en-US/home?forum=wcf

    The above forum is where you should post for help.

    Sunday, July 27, 2014 2:53 AM
  • Thank you. Reposted there.
    Sunday, July 27, 2014 11:08 AM
  • Why is that the test client work but the browser doesn't.

    A browser if that is what you are talking about (a browser) only works with HTTP. So the only WCF service you are going to be able to access is a ASP.NET WCF Web service hosted on IIS with a browser by giving the URL of the browser in the browser address line.  It's the first thing you should do, use a browser, to test if the ASP.NET Web service is hosted and is listening on IIS.

    http://msdn.microsoft.com/en-us/library/bb552364(v=vs.110).aspx

    Monday, July 28, 2014 5:06 AM
  • Hi,

    >>Why is that the test client work but the browser doesn't.

    When we are using the WCF test client, the WcfSvcHost.exe will host the service. And when the service works well in the WCF test client, then it will mean that the service code is correct.

    For your question, it seems that the windows service does not host the WCF Service very well.  First please try to make sure that you have installed the windows service very well.

    The following articles may help you do the check.
    #Example for hosting WCF service in windows service:
    http://dotnetmentors.com/example-for-hosting-wcf-service-in-windows-service.aspx .

    #Windows Service Hosting:
    http://www.wcftutorial.net/WCF-Windows-Service-Hosting.aspx .

    #WCF Hosting with Windows Service:
    http://www.codeproject.com/Articles/653493/WCF-Hosting-with-Windows-Service .

    Then please try to make sure that the windows service is running.

    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.

    Monday, July 28, 2014 8:09 AM
    Moderator