Code:
                         / 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / xsp / System / Extensions / Script / Services / WCFServiceClientProxyGenerator.cs / 1305376 / WCFServiceClientProxyGenerator.cs
                        
                        
                            //------------------------------------------------------------------------------ 
// 
//     Copyright (c) Microsoft Corporation.  All rights reserved.
//  
//----------------------------------------------------------------------------- 
namespace System.Web.Script.Services { 
    using System; 
    using System.Globalization;
    using System.ServiceModel.Channels; 
    using System.ServiceModel.Description;
    using System.ServiceModel.Web;
    using System.Text;
 
    internal class WCFServiceClientProxyGenerator : ClientProxyGenerator {
        const int MaxIdentifierLength = 511; 
        const string DataContractXsdBaseNamespace = @"http://schemas.datacontract.org/2004/07/"; 
        const string DefaultCallbackParameterName = "callback";
        private string _path; 
        private ServiceEndpoint _serviceEndpoint;
        // Similar to proxy generation code in WCF System.Runtime.Serialization.CodeExporter
        // to generate CLR namespace from DataContract namespace 
        private static void AddToNamespace(StringBuilder builder, string fragment) {
            if (fragment == null) { 
                return; 
            }
            bool isStart = true; 
            for (int i = 0; i < fragment.Length && builder.Length < MaxIdentifierLength; i++) {
                char c = fragment[i];
 
                if (IsValid(c)) {
                    if (isStart && !IsValidStart(c)) { 
                        builder.Append("_"); 
                    }
                    builder.Append(c); 
                    isStart = false;
                }
                else if ((c == '.' || c == '/' || c == ':') && (builder.Length == 1
                    || (builder.Length > 1 && builder[builder.Length - 1] != '.'))) { 
                    builder.Append('.');
                    isStart = true; 
                } 
            }
        } 
        protected override string GetProxyPath() {
            return _path; 
        }
 
        protected override string GetJsonpCallbackParameterName() { 
            if (_serviceEndpoint == null) {
                return null; 
            }
            WebMessageEncodingBindingElement webEncodingBindingElement = _serviceEndpoint.Binding.CreateBindingElements().Find();
            if (webEncodingBindingElement != null && webEncodingBindingElement.CrossDomainScriptAccessEnabled)
            { 
                if (this._serviceEndpoint.Contract.Behaviors.Contains(typeof(JavascriptCallbackBehaviorAttribute)))
                { 
                    JavascriptCallbackBehaviorAttribute behavior = (JavascriptCallbackBehaviorAttribute)this._serviceEndpoint.Contract.Behaviors[typeof(JavascriptCallbackBehaviorAttribute)]; 
                    return behavior.UrlParameterName;
                } 
                return DefaultCallbackParameterName;
            }
            return null;
        } 
        protected override bool GetSupportsJsonp() { 
            return !String.IsNullOrEmpty(GetJsonpCallbackParameterName()); 
        }
 
        internal static string GetClientProxyScript(Type contractType, string path, bool debugMode, ServiceEndpoint serviceEndpoint) {
            ContractDescription contract = ContractDescription.GetContract(contractType);
            WebServiceData webServiceData = WebServiceData.GetWebServiceData(contract);
            WCFServiceClientProxyGenerator proxyGenerator = new WCFServiceClientProxyGenerator(path, debugMode, serviceEndpoint); 
            return proxyGenerator.GetClientProxyScript(webServiceData);
        } 
 
        // Similar to proxy generation code in WCF System.Runtime.Serialization.CodeExporter
        // to generate CLR namespace from DataContract namespace 
        protected override string GetClientTypeNamespace(string ns) {
            if (string.IsNullOrEmpty(ns)) {
                return String.Empty;
            } 
            Uri uri = null; 
            StringBuilder builder = new StringBuilder(); 
            if (Uri.TryCreate(ns, UriKind.RelativeOrAbsolute, out uri)) {
                if (!uri.IsAbsoluteUri) { 
                    AddToNamespace(builder, uri.OriginalString);
                }
                else {
                    string uriString = uri.AbsoluteUri; 
                    if (uriString.StartsWith(DataContractXsdBaseNamespace, StringComparison.Ordinal)) {
                        AddToNamespace(builder, uriString.Substring(DataContractXsdBaseNamespace.Length)); 
                    } 
                    else {
                        string host = uri.Host; 
                        if (host != null) {
                            AddToNamespace(builder, host);
                        }
                        string path = uri.PathAndQuery; 
                        if (path != null) {
                            AddToNamespace(builder, path); 
                        } 
                    }
                } 
            }
            if (builder.Length == 0) {
                return String.Empty; 
            }
 
            int length = builder.Length; 
            if (builder[builder.Length - 1] == '.') {
                length--; 
            }
            length = Math.Min(MaxIdentifierLength, length);
            return builder.ToString(0, length); 
        }
 
        protected override string GetProxyTypeName(WebServiceData data) { 
            return GetClientTypeNamespace(data.TypeData.TypeName);
        } 
        // Similar to proxy generation code in WCF System.Runtime.Serialization.CodeExporter
        // to generate CLR namespace from DataContract namespace
        private static bool IsValid(char c) { 
            UnicodeCategory uc = Char.GetUnicodeCategory(c);
 
            // each char must be Lu, Ll, Lt, Lm, Lo, Nd, Mn, Mc, Pc 
            switch (uc) { 
                case UnicodeCategory.UppercaseLetter: // Lu
                case UnicodeCategory.LowercaseLetter: // Ll
                case UnicodeCategory.TitlecaseLetter: // Lt
                case UnicodeCategory.ModifierLetter: // Lm 
                case UnicodeCategory.OtherLetter: // Lo
                case UnicodeCategory.DecimalDigitNumber: // Nd 
                case UnicodeCategory.NonSpacingMark: // Mn 
                case UnicodeCategory.SpacingCombiningMark: // Mc
                case UnicodeCategory.ConnectorPunctuation: // Pc 
                    return true;
                default:
                    return false;
            } 
        }
 
        // Similar to proxy generation code in WCF System.Runtime.Serialization.CodeExporter 
        // to generate CLR namespace from DataContract namespace
        private static bool IsValidStart(char c) { 
            return (Char.GetUnicodeCategory(c) != UnicodeCategory.DecimalDigitNumber);
        }
 
        internal WCFServiceClientProxyGenerator(string path, bool debugMode, ServiceEndpoint serviceEndpoint) { 
            _path = path; 
            _debugMode = debugMode;
            _serviceEndpoint = serviceEndpoint; 
        }
    }
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//------------------------------------------------------------------------------ 
// 
//     Copyright (c) Microsoft Corporation.  All rights reserved.
//  
//----------------------------------------------------------------------------- 
namespace System.Web.Script.Services { 
    using System; 
    using System.Globalization;
    using System.ServiceModel.Channels; 
    using System.ServiceModel.Description;
    using System.ServiceModel.Web;
    using System.Text;
 
    internal class WCFServiceClientProxyGenerator : ClientProxyGenerator {
        const int MaxIdentifierLength = 511; 
        const string DataContractXsdBaseNamespace = @"http://schemas.datacontract.org/2004/07/"; 
        const string DefaultCallbackParameterName = "callback";
        private string _path; 
        private ServiceEndpoint _serviceEndpoint;
        // Similar to proxy generation code in WCF System.Runtime.Serialization.CodeExporter
        // to generate CLR namespace from DataContract namespace 
        private static void AddToNamespace(StringBuilder builder, string fragment) {
            if (fragment == null) { 
                return; 
            }
            bool isStart = true; 
            for (int i = 0; i < fragment.Length && builder.Length < MaxIdentifierLength; i++) {
                char c = fragment[i];
 
                if (IsValid(c)) {
                    if (isStart && !IsValidStart(c)) { 
                        builder.Append("_"); 
                    }
                    builder.Append(c); 
                    isStart = false;
                }
                else if ((c == '.' || c == '/' || c == ':') && (builder.Length == 1
                    || (builder.Length > 1 && builder[builder.Length - 1] != '.'))) { 
                    builder.Append('.');
                    isStart = true; 
                } 
            }
        } 
        protected override string GetProxyPath() {
            return _path; 
        }
 
        protected override string GetJsonpCallbackParameterName() { 
            if (_serviceEndpoint == null) {
                return null; 
            }
            WebMessageEncodingBindingElement webEncodingBindingElement = _serviceEndpoint.Binding.CreateBindingElements().Find();
            if (webEncodingBindingElement != null && webEncodingBindingElement.CrossDomainScriptAccessEnabled)
            { 
                if (this._serviceEndpoint.Contract.Behaviors.Contains(typeof(JavascriptCallbackBehaviorAttribute)))
                { 
                    JavascriptCallbackBehaviorAttribute behavior = (JavascriptCallbackBehaviorAttribute)this._serviceEndpoint.Contract.Behaviors[typeof(JavascriptCallbackBehaviorAttribute)]; 
                    return behavior.UrlParameterName;
                } 
                return DefaultCallbackParameterName;
            }
            return null;
        } 
        protected override bool GetSupportsJsonp() { 
            return !String.IsNullOrEmpty(GetJsonpCallbackParameterName()); 
        }
 
        internal static string GetClientProxyScript(Type contractType, string path, bool debugMode, ServiceEndpoint serviceEndpoint) {
            ContractDescription contract = ContractDescription.GetContract(contractType);
            WebServiceData webServiceData = WebServiceData.GetWebServiceData(contract);
            WCFServiceClientProxyGenerator proxyGenerator = new WCFServiceClientProxyGenerator(path, debugMode, serviceEndpoint); 
            return proxyGenerator.GetClientProxyScript(webServiceData);
        } 
 
        // Similar to proxy generation code in WCF System.Runtime.Serialization.CodeExporter
        // to generate CLR namespace from DataContract namespace 
        protected override string GetClientTypeNamespace(string ns) {
            if (string.IsNullOrEmpty(ns)) {
                return String.Empty;
            } 
            Uri uri = null; 
            StringBuilder builder = new StringBuilder(); 
            if (Uri.TryCreate(ns, UriKind.RelativeOrAbsolute, out uri)) {
                if (!uri.IsAbsoluteUri) { 
                    AddToNamespace(builder, uri.OriginalString);
                }
                else {
                    string uriString = uri.AbsoluteUri; 
                    if (uriString.StartsWith(DataContractXsdBaseNamespace, StringComparison.Ordinal)) {
                        AddToNamespace(builder, uriString.Substring(DataContractXsdBaseNamespace.Length)); 
                    } 
                    else {
                        string host = uri.Host; 
                        if (host != null) {
                            AddToNamespace(builder, host);
                        }
                        string path = uri.PathAndQuery; 
                        if (path != null) {
                            AddToNamespace(builder, path); 
                        } 
                    }
                } 
            }
            if (builder.Length == 0) {
                return String.Empty; 
            }
 
            int length = builder.Length; 
            if (builder[builder.Length - 1] == '.') {
                length--; 
            }
            length = Math.Min(MaxIdentifierLength, length);
            return builder.ToString(0, length); 
        }
 
        protected override string GetProxyTypeName(WebServiceData data) { 
            return GetClientTypeNamespace(data.TypeData.TypeName);
        } 
        // Similar to proxy generation code in WCF System.Runtime.Serialization.CodeExporter
        // to generate CLR namespace from DataContract namespace
        private static bool IsValid(char c) { 
            UnicodeCategory uc = Char.GetUnicodeCategory(c);
 
            // each char must be Lu, Ll, Lt, Lm, Lo, Nd, Mn, Mc, Pc 
            switch (uc) { 
                case UnicodeCategory.UppercaseLetter: // Lu
                case UnicodeCategory.LowercaseLetter: // Ll
                case UnicodeCategory.TitlecaseLetter: // Lt
                case UnicodeCategory.ModifierLetter: // Lm 
                case UnicodeCategory.OtherLetter: // Lo
                case UnicodeCategory.DecimalDigitNumber: // Nd 
                case UnicodeCategory.NonSpacingMark: // Mn 
                case UnicodeCategory.SpacingCombiningMark: // Mc
                case UnicodeCategory.ConnectorPunctuation: // Pc 
                    return true;
                default:
                    return false;
            } 
        }
 
        // Similar to proxy generation code in WCF System.Runtime.Serialization.CodeExporter 
        // to generate CLR namespace from DataContract namespace
        private static bool IsValidStart(char c) { 
            return (Char.GetUnicodeCategory(c) != UnicodeCategory.DecimalDigitNumber);
        }
 
        internal WCFServiceClientProxyGenerator(string path, bool debugMode, ServiceEndpoint serviceEndpoint) { 
            _path = path; 
            _debugMode = debugMode;
            _serviceEndpoint = serviceEndpoint; 
        }
    }
}
// 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
- TextTreePropertyUndoUnit.cs
 - connectionpool.cs
 - ListViewCommandEventArgs.cs
 - DataGridAddNewRow.cs
 - TemplateColumn.cs
 - ProcessHostServerConfig.cs
 - PermissionSetTriple.cs
 - WebResourceAttribute.cs
 - TransformValueSerializer.cs
 - Substitution.cs
 - FontUnit.cs
 - Substitution.cs
 - ExtractorMetadata.cs
 - Bitmap.cs
 - TaskExtensions.cs
 - WebHttpEndpointElement.cs
 - PasswordPropertyTextAttribute.cs
 - MenuTracker.cs
 - PageAsyncTaskManager.cs
 - CodePageUtils.cs
 - SchemaElementLookUpTable.cs
 - WebPartConnectionsCloseVerb.cs
 - ResourceAssociationTypeEnd.cs
 - LayoutSettings.cs
 - Context.cs
 - ResourceManager.cs
 - URI.cs
 - UserControlParser.cs
 - QualifiedCellIdBoolean.cs
 - SByteStorage.cs
 - EdmProviderManifest.cs
 - IntSecurity.cs
 - CodeCastExpression.cs
 - ConfigPathUtility.cs
 - PersistChildrenAttribute.cs
 - TreeNode.cs
 - SyndicationDeserializer.cs
 - PenContext.cs
 - XPathEmptyIterator.cs
 - ResourceKey.cs
 - TemplateApplicationHelper.cs
 - DeviceFiltersSection.cs
 - AutoGeneratedFieldProperties.cs
 - Model3D.cs
 - ToolStripArrowRenderEventArgs.cs
 - XPathArrayIterator.cs
 - BrowserCapabilitiesFactoryBase.cs
 - LocalIdKeyIdentifierClause.cs
 - Control.cs
 - MatrixCamera.cs
 - MetadataItemSerializer.cs
 - nulltextcontainer.cs
 - QilName.cs
 - XmlBinaryReaderSession.cs
 - AppSettingsReader.cs
 - ToolboxCategoryItems.cs
 - MasterPageCodeDomTreeGenerator.cs
 - SymbolDocumentGenerator.cs
 - LicenseProviderAttribute.cs
 - HttpHandlersSection.cs
 - Win32.cs
 - TableProviderWrapper.cs
 - XmlEnumAttribute.cs
 - ResourceReferenceKeyNotFoundException.cs
 - ListItemDetailViewAttribute.cs
 - Geometry3D.cs
 - DbConnectionClosed.cs
 - BitArray.cs
 - CapabilitiesState.cs
 - OleDbConnectionInternal.cs
 - IsolatedStorageFileStream.cs
 - RightsDocument.cs
 - ObjectCacheSettings.cs
 - SQLCharsStorage.cs
 - UIElement3D.cs
 - EncryptedPackage.cs
 - SimpleType.cs
 - TreeViewItem.cs
 - Icon.cs
 - AddInToken.cs
 - IdleTimeoutMonitor.cs
 - NullableConverter.cs
 - CacheEntry.cs
 - ObservableDictionary.cs
 - WebPartDescriptionCollection.cs
 - sqlnorm.cs
 - TreeBuilderXamlTranslator.cs
 - FormatterConverter.cs
 - FixUp.cs
 - DataGridBoolColumn.cs
 - RawStylusSystemGestureInputReport.cs
 - ActiveDocumentEvent.cs
 - CharacterBuffer.cs
 - StrokeCollectionConverter.cs
 - MarkupCompiler.cs
 - SecurityTokenParameters.cs
 - wgx_commands.cs
 - CornerRadiusConverter.cs
 - DbConnectionStringCommon.cs
 - UniformGrid.cs