Search code examples
c#web-serviceswcfsilverlightwcf-ria-services

Service not exposing all types


I have a WCF service, "LoadRefsImport", which is a polling duplex http service.

LoadRefsImport.svc:

namespace Code.Web.ProgressUpdate
{
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class LoadRefsImport : ProgressUpdateServiceBase, ICarrierImportService
    {
        public override TimeSpan UpdateFrequency
        {
            get { return TimeSpan.FromSeconds(1); }
        }

        public void ImportCarriers(string file, Country country)
        {
            StartOperation();
            CarrierLogic.ProgressEventHandler += (o, e) => SendProgress(new Progress()
            {
                Message = e.Message,
                PercentComplete = e.Progress
            });
            CarrierLogic.CarrierLoadedEventHandler += (o, e) => SendProgress(new Progress()
            {
                Message = "Loaded carrier",
                PercentComplete = 0
            });
            CarrierLogic.ImportCarrier(file, country);
        }
    }
}

LoadRefsImport markup:

<%@ ServiceHost Language="C#" Debug="true" Service="iCode.Web.ProgressUpdate.LoadRefsImport" CodeBehind="LoadRefsImport.svc.cs" %>

ICarrierImportService:

namespace Code.Web.ProgressUpdate
{
    [ServiceContract(CallbackContract = typeof(IProgressUpdateClient))]
    public interface ICarrierImportService : IProgressUpdateService
    {
        [OperationContract(IsOneWay = true)]
        void ImportCarriers(string file, Country country);
    }
}

IProgressUpdateService:

namespace Code.Web.ProgressUpdate
{
    [ServiceContract(CallbackContract = typeof(IProgressUpdateClient))]
    public interface IProgressUpdateService
    {
        TimeSpan UpdateFrequency { get; }

        [OperationContract(IsOneWay = true)]
        void StartOperation();
    }
}

IProgressUpdateClient:

namespace Code.Web.ProgressUpdate
{
    [ServiceContract]
    public interface IProgressUpdateClient
    {
        [OperationContract(IsOneWay = true)]
        void ReceiveProgress(Progress progress);
    }

    [DataContract]
    public class Error
    {
        public enum Types
        {
            Error,
            Warning,
            Notice
        }

        [DataMember]
        public Exception Exception { get; set; }

        [DataMember]
        public string Message { get; set; }

        [DataMember]
        public Types Type { get; set; }
    }

    [DataContract]
    public class Progress
    {
        [DataMember]
        public List<Error> Errors { get; set; }

        [DataMember]
        public string Message { get; set; }

        [DataMember]
        public float PercentComplete { get; set; }
    }
}

I've set up the service in Web.config as follows:

<system.serviceModel>
    <extensions>
      <bindingExtensions>
        <add name="pollingDuplexHttpBinding" type="System.ServiceModel.Configuration.PollingDuplexHttpBindingCollectionElement, System.ServiceModel.PollingDuplex, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
      </bindingExtensions>
    </extensions>
    <behaviors>
      <serviceBehaviors>
        <behavior name="LoadRefsImportBehaviour">
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <bindings>
      <pollingDuplexHttpBinding />
    </bindings>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"
      multipleSiteBindingsEnabled="true" />
    <services>
      <service behaviorConfiguration="LoadRefsImportBehaviour" name="Code.Web.ProgressUpdate.LoadRefsImport">
        <endpoint binding="pollingDuplexHttpBinding"
          contract="Code.Web.ProgressUpdate.ICarrierImportService" />
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      </service>
    </services>
  </system.serviceModel>

When I view the service in my browser, everything is fine, and I can successfully add it as a Service Reference in my client project (when I turn off "Reuse types in referenced assemblies"), however when I go to use my service in the client project, the only types that have been exposed in the service's namespace are Error, Progress, and Exception. I get no class or methods for interacting with my service.

I've tried checking to make sure all name references are correct in the markup, I've tried deleting and recreating the service reference and cleaning and rebuilding the solution.


Solution

  • The issue was the Exception property in my Error class.

    Exception appears to not be serializable and when I removed it the service exposed all types correctly.