Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / Services / Web / System / Web / Services / Description / ServiceDescriptionReflector.cs / 1305376 / ServiceDescriptionReflector.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
namespace System.Web.Services.Description {
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Serialization;
using System.Xml.Schema;
using System.Collections;
using System;
using System.Xml;
using System.Reflection;
using System.Security.Permissions;
using System.Web.Services.Configuration;
using System.IO;
///
///
/// [To be supplied.]
///
[PermissionSet(SecurityAction.InheritanceDemand, Name="FullTrust")]
[PermissionSet(SecurityAction.LinkDemand, Name="FullTrust")]
public class ServiceDescriptionReflector {
ProtocolReflector[] reflectors, reflectorsWithPost;
ServiceDescriptionCollection descriptions = new ServiceDescriptionCollection();
XmlSchemas schemas = new XmlSchemas();
ServiceDescriptionCollection descriptionsWithPost;
XmlSchemas schemasWithPost;
WebServiceAttribute serviceAttr;
ServiceDescription description;
Service service;
LogicalMethodInfo[] methods;
XmlSchemaExporter exporter;
XmlReflectionImporter importer;
Type serviceType;
string serviceUrl;
Hashtable reflectionContext;
///
///
/// [To be supplied.]
///
public ServiceDescriptionCollection ServiceDescriptions {
get { return descriptions; }
}
///
///
/// [To be supplied.]
///
public XmlSchemas Schemas {
get { return schemas; }
}
internal ServiceDescriptionCollection ServiceDescriptionsWithPost {
get { return descriptionsWithPost; }
}
internal XmlSchemas SchemasWithPost {
get { return schemasWithPost; }
}
internal ServiceDescription ServiceDescription {
get { return description; }
}
internal Service Service {
get { return service; }
}
internal Type ServiceType {
get { return serviceType; }
}
internal LogicalMethodInfo[] Methods {
get { return methods; }
}
internal string ServiceUrl {
get { return serviceUrl; }
}
internal XmlSchemaExporter SchemaExporter {
get { return exporter; }
}
internal XmlReflectionImporter ReflectionImporter {
get { return importer; }
}
internal WebServiceAttribute ServiceAttribute {
get { return serviceAttr; }
}
internal Hashtable ReflectionContext {
get {
if (reflectionContext == null)
reflectionContext = new Hashtable();
return reflectionContext;
}
}
///
///
/// [To be supplied.]
///
public ServiceDescriptionReflector() {
Type[] reflectorTypes = WebServicesSection.Current.ProtocolReflectorTypes;
reflectors = new ProtocolReflector[reflectorTypes.Length];
for (int i = 0; i < reflectors.Length; i++) {
ProtocolReflector reflector = (ProtocolReflector)Activator.CreateInstance(reflectorTypes[i]);
reflector.Initialize(this);
reflectors[i] = reflector;
}
WebServiceProtocols enabledProtocols = WebServicesSection.Current.EnabledProtocols;
if ((enabledProtocols & WebServiceProtocols.HttpPost) == 0 && (enabledProtocols & WebServiceProtocols.HttpPostLocalhost) != 0) {
reflectorsWithPost = new ProtocolReflector[reflectors.Length + 1];
for (int i = 0; i < reflectorsWithPost.Length - 1; i++) {
ProtocolReflector reflector = (ProtocolReflector) Activator.CreateInstance(reflectorTypes[i]);
reflector.Initialize(this);
reflectorsWithPost[i] = reflector;
}
ProtocolReflector reflectorWithPost = new HttpPostProtocolReflector();
reflectorWithPost.Initialize(this);
reflectorsWithPost[reflectorsWithPost.Length - 1] = reflectorWithPost;
}
}
private void ReflectInternal(ProtocolReflector[] reflectors) {
description = new ServiceDescription();
description.TargetNamespace = serviceAttr.Namespace;
ServiceDescriptions.Add(description);
service = new Service();
string name = serviceAttr.Name;
if (name == null || name.Length == 0)
name = serviceType.Name;
service.Name = XmlConvert.EncodeLocalName(name);
if (serviceAttr.Description != null && serviceAttr.Description.Length > 0)
service.Documentation = serviceAttr.Description;
description.Services.Add(service);
reflectionContext = new Hashtable();
exporter = new XmlSchemaExporter(description.Types.Schemas);
importer = SoapReflector.CreateXmlImporter(serviceAttr.Namespace, SoapReflector.ServiceDefaultIsEncoded(serviceType));
WebMethodReflector.IncludeTypes(methods, importer);
for (int i = 0; i < reflectors.Length; i++) {
reflectors[i].Reflect();
}
}
///
///
/// [To be supplied.]
///
public void Reflect(Type type, string url) {
serviceType = type;
serviceUrl = url;
serviceAttr = WebServiceReflector.GetAttribute(type);
methods = WebMethodReflector.GetMethods(type);
CheckForDuplicateMethods(methods);
descriptionsWithPost = descriptions;
schemasWithPost = schemas;
if (reflectorsWithPost != null) {
ReflectInternal(reflectorsWithPost);
descriptions = new ServiceDescriptionCollection();
schemas = new XmlSchemas();
}
ReflectInternal(reflectors);
if (serviceAttr.Description != null && serviceAttr.Description.Length > 0)
ServiceDescription.Documentation = serviceAttr.Description;
// need to preprocess all exported schemas to make sure that IXmlSerializable schemas are Merged and the resulting set is valid
ServiceDescription.Types.Schemas.Compile(null, false);
if (ServiceDescriptions.Count > 1) {
// if defining interfaces, we move all schemas to the external collection
// since the types therein may be referenced from any of the sdls
Schemas.Add(ServiceDescription.Types.Schemas);
ServiceDescription.Types.Schemas.Clear();
}
else if (ServiceDescription.Types.Schemas.Count > 0) {
XmlSchema[] descriptionSchemas = new XmlSchema[ServiceDescription.Types.Schemas.Count];
ServiceDescription.Types.Schemas.CopyTo(descriptionSchemas, 0);
foreach (XmlSchema schema in descriptionSchemas) {
// we always move dataset schemas to the external schema's collection.
if (XmlSchemas.IsDataSet(schema)) {
ServiceDescription.Types.Schemas.Remove(schema);
Schemas.Add(schema);
}
}
}
}
void CheckForDuplicateMethods(LogicalMethodInfo[] methods) {
Hashtable messageNames = new Hashtable();
foreach (LogicalMethodInfo method in methods) {
WebMethodAttribute attribute = method.MethodAttribute;
string messageName = attribute.MessageName;
if (messageName.Length == 0) messageName = method.Name;
string key = method.Binding == null ? messageName : method.Binding.Name + "." + messageName;
LogicalMethodInfo existingMethod = (LogicalMethodInfo)messageNames[key];
if (existingMethod != null) {
throw new InvalidOperationException(Res.GetString(Res.BothAndUseTheMessageNameUseTheMessageName3, method, existingMethod, XmlConvert.EncodeLocalName(messageName)));
}
messageNames.Add(key, method);
}
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
namespace System.Web.Services.Description {
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Serialization;
using System.Xml.Schema;
using System.Collections;
using System;
using System.Xml;
using System.Reflection;
using System.Security.Permissions;
using System.Web.Services.Configuration;
using System.IO;
///
///
/// [To be supplied.]
///
[PermissionSet(SecurityAction.InheritanceDemand, Name="FullTrust")]
[PermissionSet(SecurityAction.LinkDemand, Name="FullTrust")]
public class ServiceDescriptionReflector {
ProtocolReflector[] reflectors, reflectorsWithPost;
ServiceDescriptionCollection descriptions = new ServiceDescriptionCollection();
XmlSchemas schemas = new XmlSchemas();
ServiceDescriptionCollection descriptionsWithPost;
XmlSchemas schemasWithPost;
WebServiceAttribute serviceAttr;
ServiceDescription description;
Service service;
LogicalMethodInfo[] methods;
XmlSchemaExporter exporter;
XmlReflectionImporter importer;
Type serviceType;
string serviceUrl;
Hashtable reflectionContext;
///
///
/// [To be supplied.]
///
public ServiceDescriptionCollection ServiceDescriptions {
get { return descriptions; }
}
///
///
/// [To be supplied.]
///
public XmlSchemas Schemas {
get { return schemas; }
}
internal ServiceDescriptionCollection ServiceDescriptionsWithPost {
get { return descriptionsWithPost; }
}
internal XmlSchemas SchemasWithPost {
get { return schemasWithPost; }
}
internal ServiceDescription ServiceDescription {
get { return description; }
}
internal Service Service {
get { return service; }
}
internal Type ServiceType {
get { return serviceType; }
}
internal LogicalMethodInfo[] Methods {
get { return methods; }
}
internal string ServiceUrl {
get { return serviceUrl; }
}
internal XmlSchemaExporter SchemaExporter {
get { return exporter; }
}
internal XmlReflectionImporter ReflectionImporter {
get { return importer; }
}
internal WebServiceAttribute ServiceAttribute {
get { return serviceAttr; }
}
internal Hashtable ReflectionContext {
get {
if (reflectionContext == null)
reflectionContext = new Hashtable();
return reflectionContext;
}
}
///
///
/// [To be supplied.]
///
public ServiceDescriptionReflector() {
Type[] reflectorTypes = WebServicesSection.Current.ProtocolReflectorTypes;
reflectors = new ProtocolReflector[reflectorTypes.Length];
for (int i = 0; i < reflectors.Length; i++) {
ProtocolReflector reflector = (ProtocolReflector)Activator.CreateInstance(reflectorTypes[i]);
reflector.Initialize(this);
reflectors[i] = reflector;
}
WebServiceProtocols enabledProtocols = WebServicesSection.Current.EnabledProtocols;
if ((enabledProtocols & WebServiceProtocols.HttpPost) == 0 && (enabledProtocols & WebServiceProtocols.HttpPostLocalhost) != 0) {
reflectorsWithPost = new ProtocolReflector[reflectors.Length + 1];
for (int i = 0; i < reflectorsWithPost.Length - 1; i++) {
ProtocolReflector reflector = (ProtocolReflector) Activator.CreateInstance(reflectorTypes[i]);
reflector.Initialize(this);
reflectorsWithPost[i] = reflector;
}
ProtocolReflector reflectorWithPost = new HttpPostProtocolReflector();
reflectorWithPost.Initialize(this);
reflectorsWithPost[reflectorsWithPost.Length - 1] = reflectorWithPost;
}
}
private void ReflectInternal(ProtocolReflector[] reflectors) {
description = new ServiceDescription();
description.TargetNamespace = serviceAttr.Namespace;
ServiceDescriptions.Add(description);
service = new Service();
string name = serviceAttr.Name;
if (name == null || name.Length == 0)
name = serviceType.Name;
service.Name = XmlConvert.EncodeLocalName(name);
if (serviceAttr.Description != null && serviceAttr.Description.Length > 0)
service.Documentation = serviceAttr.Description;
description.Services.Add(service);
reflectionContext = new Hashtable();
exporter = new XmlSchemaExporter(description.Types.Schemas);
importer = SoapReflector.CreateXmlImporter(serviceAttr.Namespace, SoapReflector.ServiceDefaultIsEncoded(serviceType));
WebMethodReflector.IncludeTypes(methods, importer);
for (int i = 0; i < reflectors.Length; i++) {
reflectors[i].Reflect();
}
}
///
///
/// [To be supplied.]
///
public void Reflect(Type type, string url) {
serviceType = type;
serviceUrl = url;
serviceAttr = WebServiceReflector.GetAttribute(type);
methods = WebMethodReflector.GetMethods(type);
CheckForDuplicateMethods(methods);
descriptionsWithPost = descriptions;
schemasWithPost = schemas;
if (reflectorsWithPost != null) {
ReflectInternal(reflectorsWithPost);
descriptions = new ServiceDescriptionCollection();
schemas = new XmlSchemas();
}
ReflectInternal(reflectors);
if (serviceAttr.Description != null && serviceAttr.Description.Length > 0)
ServiceDescription.Documentation = serviceAttr.Description;
// need to preprocess all exported schemas to make sure that IXmlSerializable schemas are Merged and the resulting set is valid
ServiceDescription.Types.Schemas.Compile(null, false);
if (ServiceDescriptions.Count > 1) {
// if defining interfaces, we move all schemas to the external collection
// since the types therein may be referenced from any of the sdls
Schemas.Add(ServiceDescription.Types.Schemas);
ServiceDescription.Types.Schemas.Clear();
}
else if (ServiceDescription.Types.Schemas.Count > 0) {
XmlSchema[] descriptionSchemas = new XmlSchema[ServiceDescription.Types.Schemas.Count];
ServiceDescription.Types.Schemas.CopyTo(descriptionSchemas, 0);
foreach (XmlSchema schema in descriptionSchemas) {
// we always move dataset schemas to the external schema's collection.
if (XmlSchemas.IsDataSet(schema)) {
ServiceDescription.Types.Schemas.Remove(schema);
Schemas.Add(schema);
}
}
}
}
void CheckForDuplicateMethods(LogicalMethodInfo[] methods) {
Hashtable messageNames = new Hashtable();
foreach (LogicalMethodInfo method in methods) {
WebMethodAttribute attribute = method.MethodAttribute;
string messageName = attribute.MessageName;
if (messageName.Length == 0) messageName = method.Name;
string key = method.Binding == null ? messageName : method.Binding.Name + "." + messageName;
LogicalMethodInfo existingMethod = (LogicalMethodInfo)messageNames[key];
if (existingMethod != null) {
throw new InvalidOperationException(Res.GetString(Res.BothAndUseTheMessageNameUseTheMessageName3, method, existingMethod, XmlConvert.EncodeLocalName(messageName)));
}
messageNames.Add(key, method);
}
}
}
}
// 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
- AttributeCollection.cs
- HttpInputStream.cs
- UInt32.cs
- DurableInstanceContextProvider.cs
- EntityKey.cs
- SweepDirectionValidation.cs
- ExecutionPropertyManager.cs
- DataObject.cs
- ValueQuery.cs
- login.cs
- TrackingMemoryStreamFactory.cs
- Rect.cs
- Decoder.cs
- MobileUserControl.cs
- SchemaImporterExtensionsSection.cs
- PipelineModuleStepContainer.cs
- ElementHostAutomationPeer.cs
- MergeFilterQuery.cs
- WmpBitmapEncoder.cs
- DataServiceStreamResponse.cs
- DragCompletedEventArgs.cs
- TypeConverterHelper.cs
- EventProviderWriter.cs
- WindowsContainer.cs
- MailDefinition.cs
- CachedTypeface.cs
- MissingManifestResourceException.cs
- FileDialog.cs
- CellLabel.cs
- DoubleLinkList.cs
- RequiredFieldValidator.cs
- DependsOnAttribute.cs
- NavigationProperty.cs
- HttpInputStream.cs
- QueryStringHandler.cs
- DataSourceConverter.cs
- PersonalizationStateInfoCollection.cs
- ConnectionsZone.cs
- AttributeUsageAttribute.cs
- QilNode.cs
- SocketAddress.cs
- ConfigurationLocation.cs
- ReferenceConverter.cs
- RijndaelManagedTransform.cs
- SByte.cs
- DefaultObjectMappingItemCollection.cs
- GeometryCollection.cs
- SizeAnimation.cs
- BaseTreeIterator.cs
- EntityDataSourceViewSchema.cs
- DocumentPageHost.cs
- WizardForm.cs
- ItemList.cs
- WebEventTraceProvider.cs
- StylusEventArgs.cs
- SrgsDocument.cs
- ButtonChrome.cs
- IndexedSelectQueryOperator.cs
- DataColumnChangeEvent.cs
- TextTreeDeleteContentUndoUnit.cs
- RequestTimeoutManager.cs
- DBBindings.cs
- DataGridViewHitTestInfo.cs
- ImplicitInputBrush.cs
- WebPartCollection.cs
- DefinitionBase.cs
- TextTreeRootNode.cs
- RelationshipEnd.cs
- DataGridViewCellStyleContentChangedEventArgs.cs
- OSEnvironmentHelper.cs
- TypeBuilder.cs
- Queue.cs
- TabControl.cs
- WebPartUserCapability.cs
- TransformerInfo.cs
- DataGridPagingPage.cs
- ToolStripManager.cs
- TextSegment.cs
- FixedTextPointer.cs
- PassportAuthenticationModule.cs
- Journaling.cs
- LoadRetryStrategyFactory.cs
- XmlLanguage.cs
- SigningCredentials.cs
- DataStorage.cs
- LinqDataSourceSelectEventArgs.cs
- Dynamic.cs
- Point3DKeyFrameCollection.cs
- MachineKeySection.cs
- Rules.cs
- UnSafeCharBuffer.cs
- xmlglyphRunInfo.cs
- NameValueCollection.cs
- HttpCapabilitiesSectionHandler.cs
- MetaChildrenColumn.cs
- PlainXmlSerializer.cs
- versioninfo.cs
- MenuBindingsEditor.cs
- Zone.cs
- ExternalException.cs