Chapter VII hosted in a WCF IIS hosted service on ASMX features

And, like ASMX, WCF also provides a robust expansion model. But in addition to using the HTTP pipeline, it also uses the channel stack. WCF in the channel is very flexible. They understand the transport protocol such as HTTP, but also to understand other elements such as security and transaction protocol. Channel stack in the third chapter, “channel” and Chapter IV “binding” in the description.
Table 7.1 WCF service in a feature set allows ASMX
list ASMX 7.5 session state access and configure settings using System.ServiceModel; using System.Runtime.Serialization; using System.ServiceModel.Activation; using System . Web; using System.Configuration; namespace Services {[DataContract] public class StockPrice {/ / [DataMember] public string source; [DataMember] public double price; [DataMember] public int calls;} [ServiceContract] public interface IStockService {[ OperationContract] StockPrice GetPrice (string ticker);} [ServiceBehavior (InstanceContextMode = InstanceContextMode.PerSession)] [AspNetCompatibilityRequirements (RequirementsMode = AspNetCompatibilityRequirementsMode.Required)] public class StockService: IStockService {public StockPrice GetPrice (string ticker) {StockPrice p = new StockPrice ( ); int nCalls = 0; if (HttpContext.Current.Session ["cnt"]! = null) {nCalls = (int) HttpContext.Current.Session ["cnt"];} HttpContext.Current.Session ["cnt" ] = nCalls; p.calls = nCalls; p.price = 94.85; / / p.source = ConfigurationManager.AppSettings ["StockSource"]; return p;}}}
1. HTTPContext.Current. in ASP.NET HTTP pipeline set to null. In a WCF service, you can use OperationContext.Current object to achieve a similar purpose.
WCF support IIS in a special boarding model: ASP.NET compatibility mode. When running in this mode, time, ASP.NET for WCF services hosted environment. Thus, in and is legal. However, not all of the ASP.NET HTTP features are enabled in this mode:
list of 7.7 on the client configuration file manipulation to Cookies

2010 年 12 月 27 日
4. session state
(2) globalization. You can set the thread culture in the region to access international part.

in ASP.NET compatibility mode is turned on, the service can take advantage of ASP.NET features. 7.5 in the list, we use two ASP.NET features. First, we use the ASMX-SessionState feature to store session layer state. Instance can be set to PerCall, PerSession or Single. The fifth chapter in the “behavior” was further defined. In this example, we use PerSessino, so many times if a client calls the service using the same proxy, session state will be preserved between different calls. WCF has a lot of other ways to store session layer data, but for those who are familiar with ASMX, this is a convenient framework. Second, we use the familiar in web.config AppSettings section to store application-specific configuration data. In the service-side code, ConfigurationManager object AppSettings collection to collect these values.
WCF and ASP.NET impersonation in the open. NET 1.X implementation in the same way. By section of the web.config file contains achieve. When you do this, the client-side validation is automatically sent to the server, the server uses client-side validation to perform the operation.
before the WCF, ASMX is ASP.NET Web Service in a common approach. It needs a public Web service, and excellent support provided by the ASP.NET HTTP pipeline robust expansion capabilities. In WCF, the service is designed to separate transmission and do not understand their boarding model. So WCF service can not rely on the implementation of the HTTP pipeline within such HTTP.SYS.
5.
3. imitate
3. imitation. WCF supports the use of behavior in the service layer and the operation layer. This is the additional implementation of ASP.NET. If the service through the WCF imitation, will override settings in ASP.NET. If the service does not implement imitation, ASP.NET will use the rules.
list 7.8 enables simulation using System.ServiceModel; using System.Runtime.Serialization; using System.ServiceModel.Activation; using System.Web; using System.Configuration; using System.Security.Principal; namespace Services {[DataContract ] public class StockPrice {[DataMember] public double price; [DataMember] public string requestedBy;} [ServiceContract] public interface IStockService {[OperationContract] StockPrice GetPrice (string ticker);} [ServiceBehavior] [AspNetCompatibilityRequirements (RequirementsMode = AspNetCompatibilityRequirementsMode.Required) ] public class StockService: IStockService {[OperationBehavior (Impersonation = ImpersonationOpti on.Required)] public StockPrice GetPrice (string ticker) {StockPrice p = new StockPrice (); p.requestedBy = WindowsIdentity.GetCurrent (). Name; p.price = 94.85; return p;}}}
list of 7.6 in the service configuration to enable ASP.NET compatibility < service behaviorConfiguration = "MEXServiceTypeBehavior" name = "Services.StockService">
4. session state. This is entirely inherited from the ASP.NET configuration implementation. You can use the process, service or continuous structure to hold the SQL state.

List 7.8 shows the operational level simulation setting, assuming it is not allowed in the web.config of the service layer. When a client access server, the user is logged in as a member in RequestedBy return. If the operation behavior is removed, RequestedBy members default to wind back the network services. Simulations in Chapter 8, “Security” details.
7.7 shows how to list the client configuration file to enable cookies. this list by the Add Service Reference in Visual Studio generates. Note that the default allowCookies set to true.
In order to run in ASP.NET compatibility mode on the ASP.NET feature, you need to change two settings. In the application layer, you have to set in web.config / / to true. Because the service layer ASMX is a choice to enter the mode, you must not set in the service layer AspNetCompatibilityRequirements to Allowed. With these two settings, almost all of the ASP.NET features can be used in a WCF service. Table 7.1 describes the relationship between these two settings.
work to make PerSession instance, the client must identity in order to save a session from the client to the server in the order calling the session ID can be returned to the server. For ASP.NET, which is transmitted through the HTTP header in a client cookie to achieve. In order to work through the ASMX-PerSession instance, the client must open the cookies. Because the standard HTTP bindings, basicHttpBinding and wsHttpBinding, by default does not allow cookies, you must define a client app.config AllowCookies = true binding configuration . 7.6 shows the list of server enable aspNetCompatibility.
6. ConfigurationManager.AppSettings. You can only root node in the web.config or the application of the above to obtain a virtual set, because httpContext is empty.
2. File / Url certification
However, there are some need further explanation.
1. HTTPContext.Current. ConfigurationManager.AppSettings and ConfigurationManager.GetSection simultaneously. HttpContext.Current flow between threads in the WCF.
so that you can use to mimic any one of two ways. In order to set it in the service layer, the use of the service behavior impersionateCallerForAllOperations = true, the operation behavior using ImpersionationOption.Allowed. In order to open it in the operating level, the operation behavior using ImpersonationOption.Required, while not in service behavior in reference to anything.

No comments allowed