【问题标题】:Service not exposing all types服务未公开所有类型
【发布时间】:2014-07-17 12:41:40
【问题描述】:

我有一个 WCF 服务“LoadRefsImport”,它是一个轮询双工 http 服务。

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 标记:

<%@ 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; }
    }
}

我在 Web.config 中设置了如下服务:

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

当我在浏览器中查看服务时,一切都很好,我可以成功地将它作为服务引用添加到我的客户端项目中(当我关闭“在引用的程序集中重用类型”时),但是当我去使用我在客户端项目中的服务,在服务的命名空间中公开的唯一类型是ErrorProgressException。我没有获得与我的服务交互的类或方法。

我已尝试检查以确保标记中的所有名称引用都正确,我已尝试删除并重新创建服务引用以及清理和重建解决方案。

【问题讨论】:

    标签: c# web-services wcf silverlight wcf-ria-services


    【解决方案1】:

    问题是我的Error 类中的Exception 属性。

    Exception 似乎不可序列化,当我删除它时,服务正确地公开了所有类型。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-10
      相关资源
      最近更新 更多