我有一个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>
当我在浏览器中查看服务时,一切都很好,我可以在客户端项目中成功添加它作为服务引用(当我关闭“重用引用程序集中的类型”时),但是当我去使用时我在客户端项目中的服务,在服务的命名空间中公开的唯一类型是Error
,Progress
和Exception
。我没有与我的服务进行交互的课程或方法。
我已经尝试检查以确保标记中的所有名称引用都是正确的,我已尝试删除并重新创建服务引用并清理和重建解决方案。
答案 0 :(得分:0)
问题是我的Exception
课程中的Error
属性。
Exception
似乎不可序列化,当我删除它时,服务正确地暴露了所有类型。