Tag: #wcf

哪种WCF配置方法更智能?

我正在阅读2本关于WCf的书,其中一本显示配置为App.Config,另一本显示通过Code in C# 我想知道我应该使用哪种方法,以及彼此有什么好处。 Wcf配置向导是否也支持配置后面的c#代码? 谢谢你的回答。

在模拟时调用异步WCF服务

我在服务器上运行WCF服务,该服务器配置为接受Kerberos身份validation。 Kerberos工作正常,因此WCF服务知道哪个用户连接到他。 该服务提供一切作为异步方法。 就像这里一样(只是一个清晰的例子)。 public ExampleService : IExampleService { public Task GetUsernameAsync() { return await Task.Run(() => System.Threading.Thread.CurrentPrincipal.Name); } } 在客户端,我有一个Controller(它是一个MVC页面,但这没关系),它调用方法异步。 public ExampleController { public async Task Index() { using(var serviceClient = ServiceFactory.GetServiceClient()) using(Security.Impersonation.Impersonate()) { var data = await serviceClient.GetUsernameAsync(); return View(data); } } } 只要我不使用等待,模仿就可以正常工作。 由于Task不会模拟模拟身份,因此我想知道是否有可能更改Task的执行用户或执行任何其他操作以使模拟在此用例中起作用。 我尝试了一个自定义的awaiter(因为它可以在那个案例中使用Culture),但这根本不起作用(好吧它也不会冒充)。

在app.config中增加后运行WCF测试客户端并接收MaxReceivedMessageSize错误

我正在尝试在VS 2013中设置我的第一个WCF服务。我正忙着通过一个教程,但是遇到了麻烦…… 运行一个简单的服务(DataViewerService),它调用数据库以返回记录集。 我已将绑定更改为: 在system.serviceModel中,我直接在下面包含了 谷歌搜索,我读到的是客户端和服务器都需要设置…但是,我在localhost上运行,我在wcf测试客户端中消耗。 我似乎无法弄清楚我需要在哪里做出这些改变……我错过了什么?

如何将Noda Time(或任何第三方类型)对象作为参数传递给WCF?

我有一个在OperationContract参数中使用Noda Time类型( LocalDate和ZonedDateTime )的服务,但是当我尝试发送例如LocalDate(1990,7,31) ,服务器接收一个具有默认值(1970/1/1)的对象。 客户端或服务器不会引发任何错误。 以前它适用于相应的BCL类型( DateTimeOffset )。 我理解NCF时间类型可能不会被WCF“知道”,但我看不出我应该如何添加它们。 我在关于已知类型的文档中检查了此页面 ,但它没有帮助。 有没有办法做到这一点,以避免BCL类型的脏(可能不完整)手动转换/序列化? 谢谢。

在WCF中不返回DateTime.Kind

当使用WCF处理DateTime对象时,返回的DateTime对象缺少Kind属性,即使我在返回它之前手动更改它也将始终为DateTimeKind.Unspecified ! 我是在WCF方面做到的: dateFrom = DateTime.SpecifyKind(dateFrom , DateTimeKind.Utc); 仍然,它作为DateTimeKind.Unspecified发送给客户端… 客户端是WinForm应用程序,服务器是在IIS中托管的WCF。 PS我知道DateTime.ToUniversalTime()方法,但这不是我需要的。

如何在C#中使用WCF REST服务?

我的合同细节如下。 我正在使用Json响应和请求格式,也使用POST方法。 如何编写客户端以在c#中使用此服务。 [OperationContract()] [WebInvoke(UriTemplate = “/RESTJson_Sample1_Sample1Add”, Method = “POST”, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest)] int RESTJson_Sample1_Sample1Add(Int32 a, Int32 b, Int32 c);

WCF Windows身份validation安全性错误

我有一些代码尝试模拟调用者的Windows安全设置,然后连接到另一台机器上的另一个WCF服务 WindowsIdentity callerWindowsIdentity = ServiceSecurityContext.Current.WindowsIdentity; using (callerWindowsIdentity.Impersonate()) { NetTcpBinding binding = new NetTcpBinding(); binding.Security.Mode = SecurityMode.Message; binding.Security.Message.ClientCredentialType = MessageCredentialType.Windows; EndpointAddress endpoint = new EndpointAddress(new Uri(“net.tcp://serverName:9990/TestService1”)); ChannelFactory channel = new ChannelFactory(binding, endpoint); WCFTest.ConsoleHost.IService1 service = channel.CreateChannel(); return service.PrintMessage(msg); } 但是我收到错误:“调用者没有通过服务validation”System.ServiceModel ….由于身份validation失败,无法满足安全令牌的请求… 我试图模仿的凭据是服务所在框的valide windows凭证。 有什么想法吗?

序列化代码示例中的无限循环

从这里查看以下代码。 它是关于在wcf中序列化时在数据提取(对象模型,对象图,域模型)中保留循环引用。 class ReferencePreservingDataContractSerializerOperationBehavior :DataContractSerializerOperationBehavior { public ReferencePreservingDataContractSerializerOperationBehavior( OperationDescription operationDescription) : base(operationDescription) { } public override XmlObjectSerializer CreateSerializer( Type type, string name, string ns, IList knownTypes) { return CreateDataContractSerializer(type, name, ns, knownTypes); } private static XmlObjectSerializer CreateDataContractSerializer( Type type, string name, string ns, IList knownTypes) { return CreateDataContractSerializer(type, name, ns, knownTypes); } public override XmlObjectSerializer […]

如何处理WCF故障exception

我试图在开源客户端应用程序中添加有关SOAP错误的更多信息。 客户端设置为在遇到任何SOAP故障时调用“HandleFault”。 Handle Fault方法如下所示: public static void HandleFault(Message message) { MessageFault fault = MessageFault.CreateFault(message, Int32.MaxValue); throw System.ServiceModel.FaultException.CreateFault(fault, typeof(PermissionDeniedFault), typeof(EndpointUnavailable), typeof(InvalidRepresentation), typeof(UnwillingToPerformFault), typeof(CannotProcessFilter), typeof(AnonymousInteractionRequiredFault) ); } 以下是SOAP Fault的一部分,当我尝试执行诸如从客户端将电话号码更改为无效格式之类的操作时,将其作为“消息”传递。 Sender a:InvalidRepresentation The request message contains errors that prevent processing the request. OfficePhone (123)456-7890 ValueViolatesRegularExpression The specified attribute value does not satisfy the regular expression. 11042dda-3ce9-4563-b59e-d1c1355819a4 每当遇到那个Fault时,客户端只返回“请求消息包含阻止处理请求的错误。”,我想在客户端重新抛出exception之前包含“ AttributeRepresentationFailure […]

WCF路由服务 – 动态error handling

我正在学习使用WCF路由服务可以做些什么。 仍然在’拧紧它,看看它能做什么’阶段。 我对路由服务的理解是,当消息通过时,服务将尝试将其传递给备份列表中首先出现的任何端点。 如果失败了,它将继续尝试下一个,然后是下一个,直到任何一个有效或者没有什么可以尝试。 我想做的是访问该失败事件,以便我可以: 记录失败 通过电子邮件发送端点失败的通知 (可选)从备份列表中删除端点,以便它不会减慢将来的消息流过系统的速度 无法找到如何扩展WCF框架以获取此特定事件。 这是WCF路由服务可以做的事情吗? 任何推动正确的方向将不胜感激。 目前,我在IIS下托管了30-beh动态生成的路由服务(或者更确切地说,是Visual Studio 2010的ASP.NET开发服务器)。 我正在设置Global.asax中服务的路由,如下所示。 protected void Application_Start(object sender, EventArgs e) { List serviceTypes = ServiceUtility.GetServiceTypes(); foreach (Type st in serviceTypes) { string route = String.Format(“Services/{0}.svc”, ServiceUtility.GetServiceName(st)); RouteTable.Routes.Add(new ServiceRoute(route, new RoutingServiceHostFactory(st), typeof(System.ServiceModel.Routing.RoutingService))); } } ServiceUtility和RoutingServiceHostFactory是自定义类。 请注意,IPolicyService是我感兴趣的程序集中的WCF服务契约接口。 public static class ServiceUtility { public static List GetServiceTypes() […]