Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx35 / System.ServiceModel.Web / System / ServiceModel / Description / WebScriptClientGenerator.cs / 1305376 / WebScriptClientGenerator.cs
//------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------- namespace System.ServiceModel.Description { using System; using System.Globalization; using System.Net; using System.Runtime.Serialization.Json; using System.ServiceModel.Activation; using System.ServiceModel.Channels; using System.ServiceModel.Dispatcher; using System.Web; using System.Web.Script.Services; class WebScriptClientGenerator : ServiceMetadataExtension.IHttpGetMetadata { internal const string DebugMetadataEndpointSuffix = "jsdebug"; internal const string MetadataEndpointSuffix = "js"; bool debugMode; ServiceEndpoint endpoint; NameValueCacheproxyCache; DateTime serviceLastModified; string serviceLastModifiedRfc1123String; bool crossDomainScriptAccessEnabled; public WebScriptClientGenerator(ServiceEndpoint endpoint, bool debugMode, bool crossDomainScriptAccessEnabled) { this.endpoint = endpoint; this.debugMode = debugMode; // The service host is automatically restarted every time a service or any of its dependencies change // A restart adds all the behaviors from scratch. // => WebScriptEnablingBehavior plugs in this contract for the "/js" endpoint afresh if the service changes. this.serviceLastModified = DateTime.UtcNow; // Zero out all millisecond and sub-millisecond information because RFC1123 doesn't support milliseconds. // => The parsed If-Modified-Since date, against which serviceLastModified will need to be compared, // won't have milliseconds. this.serviceLastModified = new DateTime(this.serviceLastModified.Year, this.serviceLastModified.Month, this.serviceLastModified.Day, this.serviceLastModified.Hour, this.serviceLastModified.Minute, this.serviceLastModified.Second, DateTimeKind.Utc); this.proxyCache = new NameValueCache (); this.crossDomainScriptAccessEnabled = crossDomainScriptAccessEnabled; } string GetProxyContent(Uri baseUri) { string proxy = this.proxyCache.Lookup(baseUri.Authority); if (String.IsNullOrEmpty(proxy)) { proxy = ProxyGenerator.GetClientProxyScript(this.endpoint.Contract.ContractType, baseUri.AbsoluteUri, this.debugMode, endpoint); this.proxyCache.AddOrUpdate(baseUri.Authority, proxy); } return proxy; } string ServiceLastModifiedRfc1123String { get { if (serviceLastModifiedRfc1123String == null) { // "R" for RFC1123. The HTTP standard requires that dates be serialized according to RFC1123. serviceLastModifiedRfc1123String = serviceLastModified.ToString("R", DateTimeFormatInfo.InvariantInfo); } return serviceLastModifiedRfc1123String; } } public Message Get(Message message) { HttpRequestMessageProperty requestMessageProperty = (HttpRequestMessageProperty) message.Properties[HttpRequestMessageProperty.Name]; HttpResponseMessageProperty responseMessageProperty = new HttpResponseMessageProperty(); if ((requestMessageProperty != null) && IsServiceUnchanged(requestMessageProperty.Headers[JsonGlobals.IfModifiedSinceString])) { Message responseMessage = Message.CreateMessage(MessageVersion.None, string.Empty); responseMessageProperty.StatusCode = HttpStatusCode.NotModified; responseMessage.Properties.Add(HttpResponseMessageProperty.Name, responseMessageProperty); return responseMessage; } string proxyContent = this.GetProxyContent(UriTemplate.RewriteUri(this.endpoint.Address.Uri, requestMessageProperty.Headers[HttpRequestHeader.Host])); Message response = new WebScriptMetadataMessage(string.Empty, proxyContent); responseMessageProperty.Headers.Add(JsonGlobals.LastModifiedString, ServiceLastModifiedRfc1123String); responseMessageProperty.Headers.Add(JsonGlobals.ExpiresString, ServiceLastModifiedRfc1123String); if (AspNetEnvironment.Current.AspNetCompatibilityEnabled) { HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.Public); } else { responseMessageProperty.Headers.Add(JsonGlobals.CacheControlString, JsonGlobals.publicString); } response.Properties.Add(HttpResponseMessageProperty.Name, responseMessageProperty); return response; } internal static string GetMetadataEndpointSuffix(bool debugMode) { if (debugMode) { return DebugMetadataEndpointSuffix; } else { return MetadataEndpointSuffix; } } bool IsServiceUnchanged(string ifModifiedSinceHeaderValue) { if (string.IsNullOrEmpty(ifModifiedSinceHeaderValue)) { return false; } DateTime ifModifiedSinceDateTime; if (DateTime.TryParse(ifModifiedSinceHeaderValue, DateTimeFormatInfo.InvariantInfo, DateTimeStyles.AdjustToUniversal, out ifModifiedSinceDateTime)) { return (ifModifiedSinceDateTime >= serviceLastModified); } return false; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- XmlExtensionFunction.cs
- XAMLParseException.cs
- ConfigurationManagerInternal.cs
- DriveInfo.cs
- CaseKeyBox.ViewModel.cs
- WebPartEditorApplyVerb.cs
- TraceListener.cs
- CompositeDataBoundControl.cs
- Win32.cs
- StagingAreaInputItem.cs
- AutomationPropertyInfo.cs
- SubqueryRules.cs
- DtrList.cs
- ICspAsymmetricAlgorithm.cs
- GroupJoinQueryOperator.cs
- SectionVisual.cs
- OLEDB_Enum.cs
- MethodMessage.cs
- MultipleViewProviderWrapper.cs
- ListControlConvertEventArgs.cs
- ToolStripGripRenderEventArgs.cs
- TemplateBindingExpression.cs
- MenuBindingsEditor.cs
- HostedController.cs
- SqlUserDefinedAggregateAttribute.cs
- EntityDataSourceContextCreatedEventArgs.cs
- PartialToken.cs
- CollectionContainer.cs
- TraceUtils.cs
- TypeTypeConverter.cs
- XmlEventCache.cs
- JournalEntry.cs
- DateTimeUtil.cs
- BitmapSourceSafeMILHandle.cs
- StylusButtonCollection.cs
- ScriptControlDescriptor.cs
- MenuItemStyleCollection.cs
- HttpResponseBase.cs
- ScriptRegistrationManager.cs
- ValidationPropertyAttribute.cs
- CallbackValidatorAttribute.cs
- ScrollPattern.cs
- DataPagerField.cs
- MethodRental.cs
- ProcessRequestArgs.cs
- ProcessModelSection.cs
- DependencyPropertyValueSerializer.cs
- PropertyGeneratedEventArgs.cs
- List.cs
- NameValuePermission.cs
- PhysicalAddress.cs
- ObservableDictionary.cs
- SecurityProtocolCorrelationState.cs
- EntityClientCacheKey.cs
- HttpWrapper.cs
- ReflectionPermission.cs
- ExpressionTable.cs
- ExpandoClass.cs
- WindowsScroll.cs
- SiteMapSection.cs
- Transform.cs
- ConfigXmlElement.cs
- SpStreamWrapper.cs
- DataObjectPastingEventArgs.cs
- ConnectionProviderAttribute.cs
- PolicyManager.cs
- ChtmlPhoneCallAdapter.cs
- DataObjectMethodAttribute.cs
- AlphabeticalEnumConverter.cs
- StringExpressionSet.cs
- FixedSOMLineCollection.cs
- DbConnectionOptions.cs
- GeometryValueSerializer.cs
- InputLanguage.cs
- PriorityRange.cs
- SqlProcedureAttribute.cs
- ModelPropertyDescriptor.cs
- ThreadStaticAttribute.cs
- AppDomainProtocolHandler.cs
- InstanceCollisionException.cs
- DynamicValueConverter.cs
- WsdlBuildProvider.cs
- ControlBuilder.cs
- TripleDESCryptoServiceProvider.cs
- ReadOnlyDataSource.cs
- HttpWriter.cs
- tibetanshape.cs
- DataGridViewCheckBoxColumn.cs
- HostingEnvironmentException.cs
- UInt64Storage.cs
- XmlEnumAttribute.cs
- TableParagraph.cs
- UiaCoreProviderApi.cs
- RoleManagerSection.cs
- OleDbException.cs
- DrawingContext.cs
- SqlException.cs
- CheckBoxField.cs
- DbProviderFactories.cs
- ImageCollectionEditor.cs