wcf

学习 WCF (1)--基础篇

痴心易碎 提交于 2020-02-17 14:36:51
Windows Communication Foundation (WCF)是一个面向服务编程的综合分层架构。该架构的顶层称为服务模型层(Service Model Layer),使用户用最少的时间和经历建立自己的软件产品和外界通信的模型。它使得开发者能够建立一个跨平台的安全、可信赖、事务性的解决方案,且能与已有系统兼容协作。我将通过几篇文章和大家一起学习WCF,希望能对新手学习WCF有些帮助。 从功能的角度来看,WCF 完全可以看作是ASMX,.Net Remoting,Enterprise Service,WSE,MSMQ 等技术的并集: WCF Service 软件设计的一个重要原则:软件组件必须针对特定的任务专门的设计和优化。假如我们要做一个管理软件,想象一下,如果一个软件非常依赖于与外界通信,我们不能把管理软件与外界通信的逻辑考虑在管理系统内部。所以必须把通信任务委托给不同的组件。用WCF术语来说,这个组件称为WCF服务。更通俗的将,WFC服务就是负责与外界通信的软件。 一个WCF Service 由下面三部分构成: Service Class :一个标记了[ServiceContract]属性的类,在其中可能包含多个方法。除了标记了一些WCF 特有的Attribute 外,这个类与一般的类没有什么区别。 Host (宿主):可以是应用程序,进程如Windows

How to set ServiceHostingEnvironment.AspNetCompatibilityEnabled = true in Code (not in config) .NET/C#

强颜欢笑 提交于 2020-02-17 13:39:24
问题 I have a requirement to access the HttpContext.Current from with-in a RESTful WCF service. I know I am able to achieve this by adding the following to config: <serviceHostingEnvironment aspNetCompatibilityEnabled=”true” /> and using the following attribute on my service: [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)] Here is my issue, I need to "spin up" an instance of the service in code for unit testing and therefore I cannot use config

How to set ServiceHostingEnvironment.AspNetCompatibilityEnabled = true in Code (not in config) .NET/C#

与世无争的帅哥 提交于 2020-02-17 13:35:11
问题 I have a requirement to access the HttpContext.Current from with-in a RESTful WCF service. I know I am able to achieve this by adding the following to config: <serviceHostingEnvironment aspNetCompatibilityEnabled=”true” /> and using the following attribute on my service: [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)] Here is my issue, I need to "spin up" an instance of the service in code for unit testing and therefore I cannot use config

How to set ServiceHostingEnvironment.AspNetCompatibilityEnabled = true in Code (not in config) .NET/C#

倾然丶 夕夏残阳落幕 提交于 2020-02-17 13:34:32
问题 I have a requirement to access the HttpContext.Current from with-in a RESTful WCF service. I know I am able to achieve this by adding the following to config: <serviceHostingEnvironment aspNetCompatibilityEnabled=”true” /> and using the following attribute on my service: [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)] Here is my issue, I need to "spin up" an instance of the service in code for unit testing and therefore I cannot use config

WCF Service Reference - Getting “XmlException: Name cannot begin with the '<' character, hexadecimal value 0x3C” on Client Side

本秂侑毒 提交于 2020-02-17 11:24:28
问题 I have a smart client application communicating with its server via WCF. Data is created on the client and then sent over the service to be persisted. The server and client use the same domain classes via a shared dll and I'm using the handy "Add Service Reference" functionality in Visual Studio that wraps SvcUtil.exe and generates the client and proxy classes. I get the following error when trying to call the service: System.Xml.XmlException occurred Message=Name cannot begin with the '<'

WCF transport-and-message-security

為{幸葍}努か 提交于 2020-02-15 13:50:16
Things to Consider When Implementing a Load Balancer with WCF https://msdn.microsoft.com/library/hh273122(v=vs.100).aspx Network Load Balancing Technical Overview https://msdn.microsoft.com/en-us/library/bb742455.aspx http://devproconnections.com/net-framework/load-balancing-and-scaling-your-wcf-services http://devproconnections.com/net-framework/wcf-and-ssl-processing-load-balancers http://serverfault.com/questions/68753/does-each-server-behind-a-load-balancer-need-their-own-ssl-certificate Configuring network load balancing for services [AX 2012] http://blogs.msdn.com/b/morgan/archive/2010

WCF catches exception “ The server did not provide a meaningful reply..”

时光怂恿深爱的人放手 提交于 2020-02-15 08:15:48
问题 after a server call my client catches an exception with the following message "The server did not provide a meaningful reply; this might be caused by a contract mismatch, a premature session shutdown or an internal server error." Also, note I tried the configuration in WCF "The server did not provide a meaningful reply" but still didn't work. Please note, that I debug the service to the end, and the data is successfully populated but at the client end when the data is supposed to appear it

AOP suggestion without IOC

孤人 提交于 2020-02-15 06:34:59
问题 I need to introduce AOP in an existing WCF service, basically for exception wrapping and logging. I need an AOP framework in .NET 4 (not 4.5), without need to do IOC injection because it will be too costly to introduce in existing code. In my research I found the following: PostSharp: very nice and straightforward but paid, I need a free one NConcern: latest version is build for .NET 4.5, previous versions is buggy with my code. Also it works with CNetpune which modify the assembly, not

Can you Pass Func<T,bool> Through a WCF Service?

…衆ロ難τιáo~ 提交于 2020-02-10 03:24:08
问题 Func is a serializable class, but yet when I try to pass it as a parameter through a service. I'm told it "isn't a known type". I've tried the solutions here to no avail. Many thanks out there... 回答1: There's work happening to enable it. Check out the Expression Tree Serialization project on the MSDN Code Gallery. 回答2: No, basically. You can't pass an Expression either, since it talks to MemberInfo nodes. Your best bet is a string representation of the predicate. 来源: https://stackoverflow.com

WCF客户端引用服务 代码

≯℡__Kan透↙ 提交于 2020-02-08 19:24:56
方法1: using (ChannelFactory<ICommonService> channelFactory = new ChannelFactory<ICommonService>(new BasicHttpBinding(), "http://127.0.0.1/SystemSecurityService.svc")) { ICommonService proxy = channelFactory.CreateChannel(); return proxy; } 方法2: BasicHttpsBinding BINDING = new BasicHttpsBinding(); return new Service1Client(BINDING, new EndpointAddress("http://127.0.0.1/Service1.svc"));//构建WCF客户端实例 方法3: WSHttpBinding BINDING = new WSHttpBinding(); SoapClientConfig.ReadBindingConfig(BINDING, "WSHttpBinding_ICommonService");//从配置文件(app.config)读取配置。 string endpoint = SoapClientConfig