Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / Orcas / NetFXw7 / ndp / fx / src / xsp / System / Web / Extensions / Script / Services / WCFServiceClientProxyGenerator.cs / 1 / WCFServiceClientProxyGenerator.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Web.Script.Services { using System; using System.Globalization; using System.ServiceModel.Description; using System.Text; internal class WCFServiceClientProxyGenerator : ClientProxyGenerator { const int MaxIdentifierLength = 511; const string DataContractXsdBaseNamespace = @"http://schemas.datacontract.org/2004/07/"; string _path; // 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; } internal static string GetClientProxyScript(Type contractType, string path, bool debugMode) { ContractDescription contract = ContractDescription.GetContract(contractType); WebServiceData webServiceData = WebServiceData.GetWebServiceData(contract); WCFServiceClientProxyGenerator proxyGenerator = new WCFServiceClientProxyGenerator(path, debugMode); 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) { this._path = path; this._debugMode = debugMode; } } } // 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.Description; using System.Text; internal class WCFServiceClientProxyGenerator : ClientProxyGenerator { const int MaxIdentifierLength = 511; const string DataContractXsdBaseNamespace = @"http://schemas.datacontract.org/2004/07/"; string _path; // 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; } internal static string GetClientProxyScript(Type contractType, string path, bool debugMode) { ContractDescription contract = ContractDescription.GetContract(contractType); WebServiceData webServiceData = WebServiceData.GetWebServiceData(contract); WCFServiceClientProxyGenerator proxyGenerator = new WCFServiceClientProxyGenerator(path, debugMode); 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) { this._path = path; this._debugMode = debugMode; } } } // 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
- SemaphoreSecurity.cs
- CompilerGeneratedAttribute.cs
- pingexception.cs
- StateManagedCollection.cs
- XmlLinkedNode.cs
- DeclarativeCatalogPartDesigner.cs
- LogExtent.cs
- CuspData.cs
- WorkflowPersistenceService.cs
- DataTable.cs
- ProcessInfo.cs
- TextParagraphProperties.cs
- XmlSchemaInclude.cs
- XmlnsCompatibleWithAttribute.cs
- OutputCacheProfileCollection.cs
- EncryptedPackageFilter.cs
- JavascriptCallbackMessageInspector.cs
- SystemIcmpV6Statistics.cs
- ProxyAssemblyNotLoadedException.cs
- ConfigXmlCDataSection.cs
- UniqueContractNameValidationBehavior.cs
- StackSpiller.Generated.cs
- FrameworkReadOnlyPropertyMetadata.cs
- VerificationAttribute.cs
- HMACMD5.cs
- SoapFault.cs
- SocketElement.cs
- CompleteWizardStep.cs
- XmlAttributeAttribute.cs
- SmiEventSink_DeferedProcessing.cs
- CustomAssemblyResolver.cs
- SemanticResolver.cs
- ObjectStateEntryDbUpdatableDataRecord.cs
- ListSortDescription.cs
- DataListItem.cs
- UpdateCompiler.cs
- XPathConvert.cs
- HtmlFormParameterReader.cs
- PointValueSerializer.cs
- ApplicationContext.cs
- TextEditorParagraphs.cs
- EntryIndex.cs
- DynamicMetaObject.cs
- Point3DConverter.cs
- IFlowDocumentViewer.cs
- ButtonBase.cs
- PrivilegeNotHeldException.cs
- CodeCatchClauseCollection.cs
- ByteStorage.cs
- UserNameSecurityToken.cs
- ListBase.cs
- DocumentPageViewAutomationPeer.cs
- XmlIlVisitor.cs
- AsymmetricSecurityProtocolFactory.cs
- TemplateBamlRecordReader.cs
- WindowsRichEditRange.cs
- ExtentJoinTreeNode.cs
- LinkedResourceCollection.cs
- SoapExtensionStream.cs
- _ShellExpression.cs
- path.cs
- SqlIdentifier.cs
- TabControlAutomationPeer.cs
- DataGridTextBox.cs
- ResourceDefaultValueAttribute.cs
- FragmentQueryProcessor.cs
- TextServicesCompartmentEventSink.cs
- DragEvent.cs
- Int64Animation.cs
- WebPartDisplayMode.cs
- DataStorage.cs
- PointAnimation.cs
- Roles.cs
- TTSEngineTypes.cs
- MouseActionValueSerializer.cs
- TrustManagerPromptUI.cs
- DynamicObjectAccessor.cs
- BindingListCollectionView.cs
- CursorInteropHelper.cs
- ArrayConverter.cs
- ParseHttpDate.cs
- WebServiceTypeData.cs
- HttpResponse.cs
- InvalidOperationException.cs
- SecurityUtils.cs
- ping.cs
- TextPatternIdentifiers.cs
- XmlSchemaComplexContent.cs
- DesignerTransactionCloseEvent.cs
- ParseHttpDate.cs
- ToolboxItemCollection.cs
- ValidationRule.cs
- ProviderUtil.cs
- CompositeActivityValidator.cs
- DebugHandleTracker.cs
- CharacterString.cs
- SafeReadContext.cs
- TextBoxDesigner.cs
- ObjectCache.cs
- InvokeMethod.cs