Tag: #wcf

是否需要处置entity framework上下文对象

我们在WCF服务方法中使用entity framework与数据库进行通信,最近我们在服务代码上运行代码审查工具。 像往常一样,我们通过工具获得了许多审核提案,许多评论意见建议处理Entity Framework上下文对象。 所以,我的问题是如果我在方法中使用entity framework上下文对象,一旦我退出该方法,GC不会清理上下文对象? 我们需要明确处理上下文对象吗?

我什么时候应该在WCF服务中使用OperationContextScope?

我目前正在开发一个WCF服务,该服务可以通过其他服务在一些操作中提交信息。 第二个服务的代理是通过强类型的ProxyFactory类生成的。 我没有遇到任何问题,但听到我在拨打电话时应该执行以下操作: using (new OperationContextScope((IContextChannel)_service)) _service.Send(message); 所以我的问题是:什么时候创建这个新的OperationContextScope合适的,为什么? 谢谢!

system.serviceModel / bindings / wsHttpBinding中的绑定没有…错误

我试图在我的WCF基于Web的服务中包含两个端点 – wsHttp和netTcp。 如下面的Web.config所示,我添加了它们,但是当我编译并在Web浏览器中单击Service.svc时收到以下错误: 错误页面: Server Error in ‘/MyService’ Application. Configuration Error Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately. Parser Error Message: The binding at system.serviceModel/bindings/wsHttpBinding does not have a configured binding named […]

WCF配置地狱?

我讨厌使用端点,行为等进行WCF设置。我相信所有这些事情都应该自动执行。 我想要做的就是从我的WCF服务返回JSON结果。 这是我的配置: 我有以下服务实现: public class ZombieService : IZombieService { [WebInvoke(Method = “GET”, ResponseFormat = WebMessageFormat.Json, UriTemplate = “KnownZombies”)] public Zombie GetZombie() { return new Zombie() { Name = “Mohammad Azam”}; } } public class Zombie { public string Name { get; set; } } 当我访问http://localhost:22059/ZombieService/KnownZombies出现以下消息: 使用’UriTemplate’的端点不能与’System.ServiceModel.Description.WebScriptEnablingBehavior’一起使用。 如果我从web.config中删除WebScriptEnablingBehavior,我会收到以下错误: 由于EndpointDispatcher上的AddressFilter不匹配,因此无法在接收方处理To“http:// localhost:22059 / ZombieService.svc / KnownZombies”的消息。 检查发送方和接收方的EndpointAddresses是否一致。 […]

“服务X没有应用程序端点”,除非我在代码中添加端点 – 为什么?

我按照这篇MSDN文章彻底创建了托管在NT服务中的WCF服务。 当我在服务控制台中单击“开始”时,我在事件查看器中看到以下内容: 服务无法启动。 System.InvalidOperationException:服务’MyServiceNamespace.RequestProcessorImpl’没有应用程序(非基础结构)端点。 这可能是因为没有为您的应用程序找到配置文件,或者因为在配置文件中找不到与服务名称匹配的服务元素,或者因为在service元素中没有定义端点。 我试着查看我能找到的所有可能的原因。 这是App.Config文件中的服务描述: 所有实体都以其命名空间命名 ,因此这不是问题。 App.Config文件放在bin \ Debug中 – 正好是NT服务的起始位置。 但是,当我从原始实现更改我的ServiceBase后代OnStart() : public class RequestProcessorWindowsService : ServiceBase { public ServiceHost serviceHost = null; //other methods skipped protected override void OnStart(string[] args) { if( serviceHost != null ) { serviceHost.Close(); } serviceHost = new ServiceHost( typeof(RequestProcesssorImpl) ); serviceHost.Open(); } } 到下一个,以便它调用AddServiceEndpoint()服务启动正常(但我不能添加对它的引用,所以我猜其他错误): public […]

Windows服务OnStop等待完成处理

我实际上是在VS 2012 / .NET 4.5中开发Windows服务。 该服务遵循以下代码段的方案: 使用计时器 每隔几分钟执行一些所需的操作。 该过程大约需要10分钟才能完成 我在服务中使用单个线程 我担心的是,如果有人通过管理控制台停止服务,它可能只是在服务正在进行的过程中。 我已经做了一些关于停止请求停止Windows服务的阅读,但有点迷失。 有时创建WorkerThreads,有时会创建ManualResetEvents,但到目前为止,我无法完全掌握Windows服务的最佳前进方法。 我需要等到处理在onStop方法中正确完成后再停止Windows服务。 那么最好的方法是什么,还要考虑下面的代码片段? 谢谢大家! namespace ImportationCV { public partial class ImportationCV : ServiceBase { private System.Timers.Timer _oTimer; public ImportationCV() { InitializeComponent(); if (!EventLog.SourceExists(DAL.Utilities.Constants.LOG_JOURNAL)) { EventLog.CreateEventSource(DAL.Utilities.Constants.LOG_JOURNAL, DAL.Utilities.Constants.SOURCE_JOURNAL); } EventLog.Source = DAL.Utilities.Constants.SOURCE_JOURNAL; EventLog.Log = DAL.Utilities.Constants.LOG_JOURNAL; } protected override void OnStart(string[] args) { int intDelai = […]

我一直在客户端获得WCF服务处于故障状态。 如何在不破坏我的WCF服务的情况下捕获WCFexception?

我有一个WCF服务多个UI消耗。 当用户无法访问数据库时,我从数据库中获得了未经授权的exception。 我没有在服务器端捕获exception并将其发送到客户端。 在客户端(asp.net网页)上,我看到exception – 用户无法访问数据库,登录失败。 这一切都很好。 但是……如果我再次调用WCF服务,我会得到服务处于故障状态的exception。 只有open才能重新启动整个WCF服务。 WCF服务作为Windows服务托管。 捕获exception的最佳方法是什么,在服务器端记录exception,将exception详细信息发送回客户端而不破坏服务? 谢谢

在浏览器中测试wcf服务

即使在配置文件中使用 ,我也无法在浏览器中调用基本的wcf web方法。 对于源代码,它是非常基本的: 对于界面: [ServiceContract] public interface IService1 { [OperationContract] [WebInvoke(Method = “GET”, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare)] string GetData(); [OperationContract] CompositeType GetDataUsingDataContract(CompositeType composite); // TODO: ajoutez vos opérations de service ici } 并为实施: public string GetData() { return (“{‘code’:’yes’}”); } 此方法在内置的visual studio wcf服务测试程序中工作正常,并返回{‘code’:’yes’} 。 在浏览器中,当我调用http://localhost:54421/Service1.svc/GetData ,它会显示一个空白页面。 我该如何解决这个问题?

将空的js数组传递给控制器​​会给出null

这是我的模型,它是一个WCF代理类 public class MyModel { public Employees[] MyEmpls{get;set;} public int Id{get;set;} public OrgName{get;set;} } 将具有MyEmpls as empty array的下面的json结构对象MyEmpls as empty array传递给MVC控制器。 [“Id”:12, “MyEmpls”:[], “OrgName”:”Kekran Mcran”] 调节器 [HttpPost] public ActionResult SaveOrg(MyModel model) { //model.MyEmpls is null here } 我期待mode.MyEmpls为空c#数组而不是null。 有人可以帮助我吗? 我们需要为此编写自定义模型绑定器吗?

从C#调用WCF时如何增加MaxReceivedMessageSize

可能重复: 已超出传入邮件的最大邮件大小限额(65536) 我正在使用WCF进行文件上传和下载。 上传成功但是当我下载一个大文件时,我发现了这个错误 错误:已超出传入邮件的最大邮件大小限额(65536)。 要增加配额,请在相应的绑定元素上使用MaxReceivedMessageSize属性。 我的Service.config文件具有以下代码。 <!– –> 任何人都可以帮助我如何增加MaxReceivedMessageSize