none
WCF Implementation class as service reference is not showing up in Windows Service application RRS feed

  • Question

  • My Windows Service is not showing up the WCF Implementation class when I add it as Add Service Reference (When I add the WCF Service reference I have named it as TestBulkEmailService).
    I am new to WCF and .net. So if I am asking something silly please pardon me.

    Hence when I start my service it is giving me error of "ServiceHost only supports class service types."

    Here's my code:

                try
                {

                    Console.WriteLine("Testing 1");
                    WCFEmailEventLog.WriteEntry("My service started"); 
                    System.Diagnostics.Debugger.Break();
                    // Create a ServiceHost 
                    // provide the base address.
                    serviceHost = new ServiceHost(typeof(TestBulkEmailService.BulkEmailService), new Uri("http://localhost/TestBulkEmailService/TestBulkEmailService.svc") );

                    WCFEmailEventLog.WriteEntry("After Service host "); 
                    // Open the ServiceHostBase to create listeners and start 
                    // listening for messages.
                    serviceHost.Open();


    In the above code the typeOf(TestBulkEmailService.BulkEmailService) does not show the Implementation class BulkEmailService and only shows my WCF Contract IBulkEmailService. 

    What am I doing wrong? Should I instead use the BulkEmailDTOList as type here? 
    If so how to use it inside to process it? 



    Here is my app.config file:

                <services>
            <service name="WW.Common.Service.Impl.BulkEmailService" behaviorConfiguration="BulkEmailService">
              <host>
                <baseAddresses>
                  <add baseAddress="http://localhost/TestBulkEmailService/TestBulkEmailService.svc"/>
                </baseAddresses>
              </host>
              <endpoint address="BulkEmailService" binding="basicHttpBinding" contract="TestBulkEmailService.IBulkEmailService" />
              <endpoint address="mex" binding="basicHttpBinding" name="mexEndpoint" contract="IMetadataExchange" />
            </service>
          </services>
        <behaviors>
          <serviceBehaviors>
            <behavior name="BulkEmailService">
              <serviceDebug httpHelpPageEnabled="true" includeExceptionDetailInFaults="true"/>
              <serviceMetadata httpGetEnabled="true" />
              <serviceSecurityAudit auditLogLocation="Application"
                 suppressAuditFailure="true"
                 serviceAuthorizationAuditLevel="Success"
                 messageAuthenticationAuditLevel="Success" />
            </behavior>
          </serviceBehaviors>
        </behaviors>


    And here is my .svc file which has been hosted in IIS and is running fine when using a client app. 

         <%@ ServiceHost Language="C#" Debug="true" Service="WW.Common.Service.Impl.BulkEmailService" %>


    Here's my Implementation and Contract for the WCF Service which I have used as Service reference and have named it as TestBulkEmailService.

          using BulkEmailDac = WW.Common.DataAccess.Impl.BulkEmailDac;

          namespace WW.Common.Service.Impl
          {
              public class BulkEmailService : IBulkEmailService
              {

                  private BulkEmailDac emailDac;
                  ErrorMsg err_msg = new ErrorMsg();

                  public BulkEmailService()
                  {
                      emailDac = new BulkEmailDac();
                  }

                  public string Abc(string s1)
                  {
                      string result = s1;
                      return result;
                  }

                  /// <summary>
                  /// Get Bulk Email Record List
                  /// </summary>
                  /// <returns></returns>
                  public BulkEmailDTOList GetBulkEmailInfo(int recordLimit)
                  {
                      try
                      {
                          return emailDac.GetBulkEmailInfo(recordLimit);
                      }
                      catch (Exception ex)
                      {
                          if (ex is FaultException<OperationFault>)
                          {
                              //throw;
                              Console.WriteLine("faultException1 Message: " + ex.Message);
                              throw;
                          }
                          else
                          {

                              //LOG AND THROW AN UNKNOWN EXCEPTION
                              ApplicationLog.WriteError(DateTime.Now.ToString() + "|"
                                                        + "GetBulkEmailInfo" + "|"
                                                        + ex.Message + "|"
                                                        + ex.StackTrace);
                              Console.WriteLine("faultException2 Message: " + ex.StackTrace);
                              throw new FaultException<OperationFault>(new OperationFault(ex.Message, ErrorMessages.Unknown_Error_Code));
                          }
                      }
                  }



    Contract:


         namespace WW.Common.Service.Contract
         {
             [ServiceContract]
             public interface IBulkEmailService
             {

                 [OperationContract]
                 [FaultContractAttribute(typeof(OperationFault))]
                 BulkEmailDTOList GetBulkEmailInfo(int recordLimit);


                 [OperationContract]
                 [FaultContractAttribute(typeof(OperationFault))]
                 int SendBulkEmail(string emailFm, string emailTo, string ccTo, string subject, string body);

        } 

                                                                  
    Monday, March 4, 2013 10:00 PM

Answers

  • When you added the service reference, Visual Studio created a client proxy behind the scenes. This is not the same as the service implementation. If you want to host your WCF service inside your Windows service, you need to add a reference to the assembly where BulkEmailService is defined. If you are ok with hosting it in IIS (that would be my preference, in the absence of a compelling requirement), then you don't need to stand up a Windows service to expose it.

    Joe

    Tuesday, March 5, 2013 8:31 PM

All replies

  • You appear to be attempting to create a ServiceHost using a client proxy. Adding a service reference creates proxy types that can be used from a client to invoke the service. ServiceHost is used on the service-side to self-host a service.

    Joe

    Tuesday, March 5, 2013 2:19 PM
  • the namespace of BulkEmailService  is WW.Common.Service.Impl

    so it will be somewhat logical that

    serviceHost = new ServiceHost(typeof(WW.Common.Service.Impl.BulkEmailService), ...

    Tuesday, March 5, 2013 8:14 PM
  • When you added the service reference, Visual Studio created a client proxy behind the scenes. This is not the same as the service implementation. If you want to host your WCF service inside your Windows service, you need to add a reference to the assembly where BulkEmailService is defined. If you are ok with hosting it in IIS (that would be my preference, in the absence of a compelling requirement), then you don't need to stand up a Windows service to expose it.

    Joe

    Tuesday, March 5, 2013 8:31 PM