Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / NetFx35 / System.ServiceModel.Web / System / ServiceModel / Description / WebScriptClientGenerator.cs / 1 / WebScriptClientGenerator.cs
//------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------- namespace System.ServiceModel.Description { using System; using System.Collections.Generic; using System.Globalization; using System.ServiceModel.Channels; using System.Xml; using System.Net; using System.Web; using System.Web.Script.Services; using System.Runtime.Serialization.Json; class WebScriptClientGenerator : ServiceMetadataExtension.IHttpGetMetadata { internal const string DebugMetadataEndpointSuffix = "jsdebug"; internal const string MetadataEndpointSuffix = "js"; bool debugMode; ServiceEndpoint endpoint; string proxyContent; DateTime serviceLastModified; string serviceLastModifiedRfc1123String; public WebScriptClientGenerator(ServiceEndpoint endpoint, bool debugMode) { 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); } string ProxyContent { get { if (proxyContent == null) { proxyContent = ProxyGenerator.GetClientProxyScript(this.endpoint.Contract.ContractType, this.endpoint.Address.Uri.PathAndQuery, this.debugMode); } return proxyContent; } } 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; } Message response = new WebScriptMetadataMessage(string.Empty, ProxyContent); responseMessageProperty.Headers.Add(JsonGlobals.LastModifiedString, ServiceLastModifiedRfc1123String); responseMessageProperty.Headers.Add(JsonGlobals.ExpiresString, ServiceLastModifiedRfc1123String); if (ServiceHostingEnvironment.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. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- OdbcStatementHandle.cs
- LineBreakRecord.cs
- ArraySet.cs
- WeakReference.cs
- RemoveStoryboard.cs
- QuaternionRotation3D.cs
- AssertFilter.cs
- DiscoveryDocumentSearchPattern.cs
- ActiveXHost.cs
- LoginName.cs
- VirtualizedCellInfoCollection.cs
- oledbconnectionstring.cs
- XmlSerializerFactory.cs
- WebPartVerbsEventArgs.cs
- ListenerConfig.cs
- SqlReorderer.cs
- WebEventTraceProvider.cs
- DataKeyCollection.cs
- ComponentChangingEvent.cs
- ZipPackagePart.cs
- SystemIPAddressInformation.cs
- SelectionList.cs
- ValueTable.cs
- DoubleLinkList.cs
- GeometryHitTestResult.cs
- CompiledRegexRunner.cs
- MailBnfHelper.cs
- BatchServiceHost.cs
- Image.cs
- SqlDependency.cs
- SortExpressionBuilder.cs
- Path.cs
- DesignerTextViewAdapter.cs
- LocalizabilityAttribute.cs
- Stroke2.cs
- AdPostCacheSubstitution.cs
- PeerService.cs
- ContainerControlDesigner.cs
- SmtpCommands.cs
- DataGridItemAttachedStorage.cs
- DataPagerFieldItem.cs
- PolicyLevel.cs
- MenuAdapter.cs
- BoundPropertyEntry.cs
- MissingManifestResourceException.cs
- DataSourceCache.cs
- GenericIdentity.cs
- HMACRIPEMD160.cs
- ResXFileRef.cs
- BasicHttpBindingCollectionElement.cs
- WebPartVerbsEventArgs.cs
- WebPartHeaderCloseVerb.cs
- IdentityManager.cs
- NegotiateStream.cs
- Utility.cs
- ReadOnlyTernaryTree.cs
- WebHttpSecurityModeHelper.cs
- OdbcConnectionPoolProviderInfo.cs
- TrackingMemoryStream.cs
- OleDbCommandBuilder.cs
- DefaultSerializationProviderAttribute.cs
- ProvidePropertyAttribute.cs
- FontStyle.cs
- ProxyWebPart.cs
- EntityRecordInfo.cs
- AbstractExpressions.cs
- ProviderUtil.cs
- DoubleCollection.cs
- HttpPostedFile.cs
- TypeLoadException.cs
- DomainConstraint.cs
- NamespaceInfo.cs
- DerivedKeySecurityTokenStub.cs
- DataKeyPropertyAttribute.cs
- DecimalSumAggregationOperator.cs
- CTreeGenerator.cs
- FunctionNode.cs
- TextElementCollection.cs
- ReceiveSecurityHeaderElementManager.cs
- EntryPointNotFoundException.cs
- Metafile.cs
- UIPermission.cs
- XmlAttributeOverrides.cs
- WindowHideOrCloseTracker.cs
- DataDocumentXPathNavigator.cs
- ReferenceEqualityComparer.cs
- ClientSideProviderDescription.cs
- RemoteWebConfigurationHost.cs
- TextFormatterHost.cs
- FixedDSBuilder.cs
- FileLevelControlBuilderAttribute.cs
- StringFunctions.cs
- ZipIOCentralDirectoryFileHeader.cs
- SqlPersonalizationProvider.cs
- ListControlStringCollectionEditor.cs
- TrustLevelCollection.cs
- RegexWriter.cs
- SystemWebSectionGroup.cs
- MessageQueueCriteria.cs
- TypeToStringValueConverter.cs