我的WCF实现类引用未显示在Windows服务中

时间:2013-03-02 00:19:11

标签: wcf wcf-binding

我的Windows服务现在正在显示我的WCF实现类。 因此,当我启动我的服务时,它给出了“ServiceHost仅支持类服务类型”的错误。 这是我的代码:

        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();

在上面的代码中,typeOf(TestBulkEmailService.BulkEmailService)不显示Implementation类BulkEmailService,只显示我的WCF Contract IBulkEmailService。

我做错了什么?

这是我的app.config文件:

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

这是我的.svc文件,它已经在IIS中托管,并且在使用客户端应用程序时运行正常。

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

这是我作为服务参考使用的WCF服务的实现和合同,并将其命名为TestBulkEmailService。

  using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Runtime.Serialization;
  using System.ServiceModel;
  using System.Text;
  using WW.EnterpriseLibrary.Error;
  using WW.Common.Service.Contract;
  using WW.Common.Data.DTO;
  using WW.Common.Data;
  using WW.ServiceCore.Error;
  using WW.ServiceCore.Log;
  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));
                  }
              }
          }

合同:

      using System;
 using System.Web;
 using System.Collections.Generic;
 using System.Linq;
 using System.Runtime.Serialization;
 using System.ServiceModel;
 using System.Text;
 using WW.EnterpriseLibrary.Error;
 using WW.Common.Data.DTO;

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

} 

0 个答案:

没有答案