Beispiel #1
0
		/*
		private string GetAbsoluteUri (string baseUri, string relativeUri)
		{
			string actualBaseUri = baseUri ?? Path.GetFullPath (".") + Path.DirectorySeparatorChar;
			Uri uri = new Uri (new Uri (actualBaseUri), relativeUri);
			return uri.ToString ();
		}
		*/

		public override void Check (ConformanceCheckContext ctx, Import value) 
		{
			if (value.Location == "" || value.Location == null) {
				ctx.ReportRuleViolation (value, BasicProfileRules.R2007);
				return;
			}
			
			if (!new Uri (value.Namespace, UriKind.RelativeOrAbsolute).IsAbsoluteUri)
				ctx.ReportRuleViolation (value, BasicProfileRules.R2803);

			// LAMESPEC: RetrievalUrl does not seem to help here (in .NET)
			//ServiceDescription importer = value.ServiceDescription;
			//string absUri = GetAbsoluteUri (importer != null ? importer.RetrievalUrl : null, value.Location);
			object doc = ctx.GetDocument (/*absUri*/value.Location, value.Namespace);
			if (doc == null) // and looks like .net ignores non-resolvable documentation... I dunno if it makes sense. I don't care :/
				return; //ctx.ReportError (value, "Document '" + value.Location + "' not found");
			
			if (doc is XmlSchema)
				ctx.ReportRuleViolation (value, BasicProfileRules.R2002);
				
			ServiceDescription imported = doc as ServiceDescription;
			if (imported == null) {
				ctx.ReportRuleViolation (value, BasicProfileRules.R2001);
				return;
			}
				
			if (imported.TargetNamespace != value.Namespace)
				ctx.ReportRuleViolation (value, BasicProfileRules.R2005);
		}
 private void AddImport(string ns, string location)
 {
     foreach (Import import in this.ServiceDescription.Imports)
     {
         if ((import.Namespace == ns) && (import.Location == location))
         {
             return;
         }
     }
     Import import2 = new Import {
         Namespace = ns,
         Location = location
     };
     this.ServiceDescription.Imports.Add(import2);
 }
 internal DiscoveryServerType(Type type, string uri) : base(typeof(DiscoveryServerProtocol))
 {
     this.schemaTable = new Hashtable();
     this.wsdlTable = new Hashtable();
     uri = new Uri(uri, true).GetLeftPart(UriPartial.Path);
     this.methodInfo = new LogicalMethodInfo(typeof(DiscoveryServerProtocol).GetMethod("Discover", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance));
     ServiceDescriptionReflector reflector = new ServiceDescriptionReflector();
     reflector.Reflect(type, uri);
     XmlSchemas schemas = reflector.Schemas;
     this.description = reflector.ServiceDescription;
     XmlSerializer serializer = ServiceDescription.Serializer;
     this.AddSchemaImports(schemas, uri, reflector.ServiceDescriptions);
     for (int i = 1; i < reflector.ServiceDescriptions.Count; i++)
     {
         ServiceDescription description = reflector.ServiceDescriptions[i];
         Import import = new Import {
             Namespace = description.TargetNamespace
         };
         string key = "wsdl" + i.ToString(CultureInfo.InvariantCulture);
         import.Location = uri + "?wsdl=" + key;
         reflector.ServiceDescription.Imports.Add(import);
         this.wsdlTable.Add(key, description);
     }
     this.discoDoc = new DiscoveryDocument();
     this.discoDoc.References.Add(new ContractReference(uri + "?wsdl", uri));
     foreach (Service service in reflector.ServiceDescription.Services)
     {
         foreach (Port port in service.Ports)
         {
             SoapAddressBinding binding = (SoapAddressBinding) port.Extensions.Find(typeof(SoapAddressBinding));
             if (binding != null)
             {
                 System.Web.Services.Discovery.SoapBinding binding2 = new System.Web.Services.Discovery.SoapBinding {
                     Binding = port.Binding,
                     Address = binding.Location
                 };
                 this.discoDoc.References.Add(binding2);
             }
         }
     }
 }
		public override void Check (ConformanceCheckContext ctx, Import value) 
		{
			if (value.Location == "" || value.Location == null) {
				ctx.ReportRuleViolation (value, BasicProfileRules.R2007);
				return;
			}
			
			object doc = ctx.GetDocument (value.Location);
			if (doc == null) ctx.ReportError (value, "Document '" + value.Location + "' not found");
			
			if (doc is XmlSchema)
				ctx.ReportRuleViolation (value, BasicProfileRules.R2002);
				
			ServiceDescription imported = doc as ServiceDescription;
			if (imported == null) {
				ctx.ReportRuleViolation (value, BasicProfileRules.R2001);
				return;
			}
				
			// TODO: rule R2003
			
			if (imported.TargetNamespace != value.Namespace)
				ctx.ReportRuleViolation (value, BasicProfileRules.R2005);
		}
Beispiel #5
0
		EndpointExportMap ExportEndpoint_Internal (ServiceEndpoint endpoint)
		{
			var map = ExportedEndpoints.FirstOrDefault (m => m.Endpoint == endpoint);
			if (map != null)
				return map;

			int index = 0;
			var baseName = String.Concat (endpoint.Binding.Name, "_", endpoint.Contract.Name);
			var name = baseName;
			while (ExportedEndpoints.Exists (m => m.Name == name))
				name = String.Concat (baseName, (++index).ToString ());

			map = new EndpointExportMap (name, endpoint);
			ExportedEndpoints.Add (map);

			var contract = ExportContractInternal (endpoint.Contract);

			//FIXME: Namespace
			WSServiceDescription sd = GetServiceDescription ("http://tempuri.org/");
			if (sd.TargetNamespace != endpoint.Contract.Namespace) {
				sd.Namespaces.Add ("i0", endpoint.Contract.Namespace);

				//Import
				Import import = new Import ();
				import.Namespace = endpoint.Contract.Namespace;

				sd.Imports.Add (import);
			}
			
			if (endpoint.Binding == null)
				throw new ArgumentException (String.Format (
					"Binding for ServiceEndpoint named '{0}' is null",
					endpoint.Name));

			var extensions = new List<IWsdlExportExtension> ();
			var extensionTypes = new Dictionary<Type, IWsdlExportExtension> ();
			if (contract.Results != null) {
				foreach (var extension in contract.Results) {
					var type = extension.GetType ();
					if (extensionTypes.ContainsKey (type))
						continue;
					extensionTypes.Add (type, extension);
					extensions.Add (extension);
				}
			}

			var bindingElements = endpoint.Binding.CreateBindingElements ();
			foreach (var element in bindingElements) {
				var extension = element as IWsdlExportExtension;
				if (extension == null)
					continue;
				var type = extension.GetType ();
				if (extensionTypes.ContainsKey (type))
					continue;
				extensionTypes.Add (type, extension);
				extensions.Add (extension);
			}

			//ExportBinding
			WSBinding ws_binding = new WSBinding ();
			
			//<binding name = .. 
			ws_binding.Name = name;

			//<binding type = ..
			ws_binding.Type = new QName (endpoint.Contract.Name, endpoint.Contract.Namespace);
			sd.Bindings.Add (ws_binding);

			//	<operation
			foreach (OperationDescription sm_op in endpoint.Contract.Operations) {
				var op_binding = CreateOperationBinding (endpoint, sm_op);
				ws_binding.Operations.Add (op_binding);
			}

			//Add <service
			Port ws_port = ExportService (sd, ws_binding, endpoint.Address);

			//Call IWsdlExportExtension.ExportEndpoint
			WsdlContractConversionContext contract_context = new WsdlContractConversionContext (
				endpoint.Contract, sd.PortTypes [endpoint.Contract.Name]);
			WsdlEndpointConversionContext endpoint_context = new WsdlEndpointConversionContext (
				contract_context, endpoint, ws_port, ws_binding);

			foreach (var extension in extensions) {
				try {
					extension.ExportEndpoint (this, endpoint_context);
				} catch (Exception ex) {
					var error = AddError (
						"Failed to export endpoint '{0}': wsdl exporter '{1}' " +
						"threw an exception: {2}", endpoint.Name, extension.GetType (), ex);
					throw new MetadataExportException (error, ex);
				}
			}

			try {
				ExportPolicy (endpoint, ws_binding);
			} catch (MetadataExportException) {
				throw;
			} catch (Exception ex) {
				var error = AddError (
					"Failed to export endpoint '{0}': unhandled exception " +
					"while exporting policy: {1}", endpoint.Name, ex);
				throw new MetadataExportException (error, ex);
			}

			return map;
		}
 static void EnsureWsdlContainsImport(WsdlNS.ServiceDescription srcWsdl, string target)
 {
     if (srcWsdl.TargetNamespace == target)
         return;
     // FindImport
     foreach (WsdlNS.Import import in srcWsdl.Imports)
     {
         if (import.Namespace == target)
             return;
     }
     {
         WsdlNS.Import import = new WsdlNS.Import();
         import.Location = null;
         import.Namespace = target;
         srcWsdl.Imports.Add(import);
         WsdlNamespaceHelper.FindOrCreatePrefix("i", target, srcWsdl);
         return;
     }
 }
Beispiel #7
0
 public bool Contains(Import import)
 {
     return(base.List.Contains(import));
 }
		public override void ExportEndpoint (ServiceEndpoint endpoint)
		{
			List<IWsdlExportExtension> extensions = ExportContractInternal (endpoint.Contract);
			
			//FIXME: Namespace
			WSServiceDescription sd = GetServiceDescription ("http://tempuri.org/");
			if (sd.TargetNamespace != endpoint.Contract.Namespace) {
				sd.Namespaces.Add ("i0", endpoint.Contract.Namespace);

				//Import
				Import import = new Import ();
				import.Namespace = endpoint.Contract.Namespace;

				sd.Imports.Add (import);
			}
			
			if (endpoint.Binding == null)
				throw new ArgumentException (String.Format (
					"Binding for ServiceEndpoint named '{0}' is null",
					endpoint.Name));

			bool msg_version_none =
				endpoint.Binding.MessageVersion != null &&
				endpoint.Binding.MessageVersion.Equals (MessageVersion.None);
			//ExportBinding
			WSBinding ws_binding = new WSBinding ();
			
			//<binding name = .. 
			ws_binding.Name = String.Concat (endpoint.Binding.Name, "_", endpoint.Contract.Name);

			//<binding type = ..
			ws_binding.Type = new QName (endpoint.Contract.Name, endpoint.Contract.Namespace);
			sd.Bindings.Add (ws_binding);

			if (!msg_version_none) {
				SoapBinding soap_binding = new SoapBinding ();
				soap_binding.Transport = SoapBinding.HttpTransport;
				soap_binding.Style = SoapBindingStyle.Document;
				ws_binding.Extensions.Add (soap_binding);
			}

			//	<operation
			foreach (OperationDescription sm_op in endpoint.Contract.Operations){
				OperationBinding op_binding = new OperationBinding ();
				op_binding.Name = sm_op.Name;

				//FIXME: Move to IWsdlExportExtension .. ?
				foreach (MessageDescription sm_md in sm_op.Messages) {
					if (sm_md.Direction == MessageDirection.Input) {
						//<input
						InputBinding in_binding = new InputBinding ();

						if (!msg_version_none) {
							SoapBodyBinding soap_body_binding = new SoapBodyBinding ();
							soap_body_binding.Use = SoapBindingUse.Literal;
							in_binding.Extensions.Add (soap_body_binding);

							//Set Action
							//<operation > <soap:operation soapAction .. >
							SoapOperationBinding soap_operation_binding = new SoapOperationBinding ();
							soap_operation_binding.SoapAction = sm_md.Action;
							soap_operation_binding.Style = SoapBindingStyle.Document;
							op_binding.Extensions.Add (soap_operation_binding);
						}

						op_binding.Input = in_binding;
					} else {
						//<output
						OutputBinding out_binding = new OutputBinding ();

						if (!msg_version_none) {
							SoapBodyBinding soap_body_binding = new SoapBodyBinding ();
							soap_body_binding.Use = SoapBindingUse.Literal;
							out_binding.Extensions.Add (soap_body_binding);
						}
						
						op_binding.Output = out_binding;
					}
				}

				ws_binding.Operations.Add (op_binding);
			}

			//Add <service
			Port ws_port = ExportService (sd, ws_binding, endpoint.Address, msg_version_none);

			//Call IWsdlExportExtension.ExportEndpoint
			WsdlContractConversionContext contract_context = new WsdlContractConversionContext (
				endpoint.Contract, sd.PortTypes [endpoint.Contract.Name]);
			WsdlEndpointConversionContext endpoint_context = new WsdlEndpointConversionContext (
				contract_context, endpoint, ws_port, ws_binding);

			foreach (IWsdlExportExtension extn in extensions)
				extn.ExportEndpoint (this, endpoint_context);

				
		}
Beispiel #9
0
 public int Add(Import import)
 {
     return(base.List.Add(import));
 }
 /// <include file='doc\ServiceDescription.uex' path='docs/doc[@for="ImportCollection.IndexOf"]/*' />
 /// <devdoc>
 ///    <para>[To be supplied.]</para>
 /// </devdoc>
 public int IndexOf(Import import) {
     return List.IndexOf(import);
 }
 /// <include file='doc\ServiceDescription.uex' path='docs/doc[@for="ImportCollection.Remove"]/*' />
 /// <devdoc>
 ///    <para>[To be supplied.]</para>
 /// </devdoc>
 public void Remove(Import import) {
     List.Remove(import);
 }
 private static void EnsureWsdlContainsImport(System.Web.Services.Description.ServiceDescription srcWsdl, string target)
 {
     if (srcWsdl.TargetNamespace != target)
     {
         foreach (Import import in srcWsdl.Imports)
         {
             if (import.Namespace == target)
             {
                 return;
             }
         }
         Import import2 = new Import {
             Location = null,
             Namespace = target
         };
         srcWsdl.Imports.Add(import2);
         WsdlNamespaceHelper.FindOrCreatePrefix("i", target, new DocumentableItem[] { srcWsdl });
     }
 }
 /// <include file='doc\ServiceDescription.uex' path='docs/doc[@for="ImportCollection.Add"]/*' />
 /// <devdoc>
 ///    <para>[To be supplied.]</para>
 /// </devdoc>
 public int Add(Import import) {
     return List.Add(import);
 }
 private void Write4_Import(string n, string ns, Import o, bool isNullable, bool needType)
 {
     if (o == null)
     {
         if (isNullable)
         {
             base.WriteNullTagLiteral(n, ns);
         }
     }
     else
     {
         if (!needType && !(o.GetType() == typeof(Import)))
         {
             throw base.CreateUnknownTypeException(o);
         }
         base.WriteStartElement(n, ns, o, false, o.Namespaces);
         if (needType)
         {
             base.WriteXsiType("Import", "http://schemas.xmlsoap.org/wsdl/");
         }
         XmlAttribute[] extensibleAttributes = o.ExtensibleAttributes;
         if (extensibleAttributes != null)
         {
             for (int i = 0; i < extensibleAttributes.Length; i++)
             {
                 XmlAttribute node = extensibleAttributes[i];
                 base.WriteXmlAttribute(node, o);
             }
         }
         base.WriteAttribute("namespace", "", o.Namespace);
         base.WriteAttribute("location", "", o.Location);
         if ((o.DocumentationElement == null) && (o.DocumentationElement != null))
         {
             throw base.CreateInvalidAnyTypeException(o.DocumentationElement);
         }
         base.WriteElementLiteral(o.DocumentationElement, "documentation", "http://schemas.xmlsoap.org/wsdl/", false, true);
         ServiceDescriptionFormatExtensionCollection extensions = o.Extensions;
         if (extensions != null)
         {
             for (int j = 0; j < extensions.Count; j++)
             {
                 if (!(extensions[j] is XmlNode) && (extensions[j] != null))
                 {
                     throw base.CreateInvalidAnyTypeException(extensions[j]);
                 }
                 base.WriteElementLiteral((XmlNode) extensions[j], "", null, false, true);
             }
         }
         base.WriteEndElement(o);
     }
 }
 public void Remove(Import import)
 {
     base.List.Remove(import);
 }
Beispiel #16
0
 public void Remove(Import import)
 {
     base.List.Remove(import);
 }
Beispiel #17
0
 public void Insert(int index, Import import)
 {
     base.List.Insert(index, import);
 }
Beispiel #18
0
 public int IndexOf(Import import)
 {
     return(base.List.IndexOf(import));
 }
 /// <include file='doc\ServiceDescription.uex' path='docs/doc[@for="ImportCollection.Insert"]/*' />
 /// <devdoc>
 ///    <para>[To be supplied.]</para>
 /// </devdoc>
 public void Insert(int index, Import import) {
     List.Insert(index, import);
 }
 void AddImport(string ns, string location) {
     foreach (Import import in ServiceDescription.Imports) {
         if (import.Namespace == ns && import.Location == location) {
             return;
         }
     }
     Import newImport = new Import();
     newImport.Namespace = ns;
     newImport.Location = location;
     ServiceDescription.Imports.Add(newImport);
 }
 /// <include file='doc\ServiceDescription.uex' path='docs/doc[@for="ImportCollection.Contains"]/*' />
 /// <devdoc>
 ///    <para>[To be supplied.]</para>
 /// </devdoc>
 public bool Contains(Import import) {
     return List.Contains(import);
 }
Beispiel #22
0
		public virtual void Check (ConformanceCheckContext ctx, Import value) { }
 /// <include file='doc\ServiceDescription.uex' path='docs/doc[@for="ImportCollection.CopyTo"]/*' />
 /// <devdoc>
 ///    <para>[To be supplied.]</para>
 /// </devdoc>
 public void CopyTo(Import[] array, int index) {
     List.CopyTo(array, index);
 }
        // See comment on the ServerProtocol.IsCacheUnderPressure method for explanation of the excludeSchemeHostPortFromCachingKey logic.
        internal DiscoveryServerType(Type type, string uri, bool excludeSchemeHostPortFromCachingKey)
            : base(typeof(DiscoveryServerProtocol))
        {
            if (excludeSchemeHostPortFromCachingKey)
            {
                this.UriFixups = new List<Action<Uri>>();
            }            
            //
            // parse the uri from a string into a Uri object
            //
            Uri uriObject = new Uri(uri, true);
            //
            // and get rid of the query string if there's one
            //
            uri = uriObject.GetLeftPart(UriPartial.Path);
            methodInfo = new LogicalMethodInfo(typeof(DiscoveryServerProtocol).GetMethod("Discover", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic));
            ServiceDescriptionReflector reflector = new ServiceDescriptionReflector(this.UriFixups);
            reflector.Reflect(type, uri);

            XmlSchemas schemas = reflector.Schemas;
            this.description = reflector.ServiceDescription;
            
            // We need to force initialization of ServiceDescription's XmlSerializer since we
            // won't necessarily have the permissions to do it when we actually need it
            XmlSerializer serializer = ServiceDescription.Serializer;

            // add imports to the external schemas
            AddSchemaImports(schemas, uri, reflector.ServiceDescriptions);

            // add imports to the other service descriptions
            for (int i = 1; i < reflector.ServiceDescriptions.Count; i++) {
                ServiceDescription description = reflector.ServiceDescriptions[i];
                Import import = new Import();
                import.Namespace = description.TargetNamespace;

                // 


                string id = "wsdl" + i.ToString(CultureInfo.InvariantCulture);

                import.Location = uri + "?wsdl=" + id;
                this.AddUriFixup(delegate(Uri current)
                {
                    import.Location = CombineUris(current, import.Location);
                });
                reflector.ServiceDescription.Imports.Add(import);
                wsdlTable.Add(id, description);
            }

            discoDoc = new DiscoveryDocument();
            ContractReference contractReference = new ContractReference(uri + "?wsdl", uri);
            this.AddUriFixup(delegate(Uri current)
            {
                contractReference.Ref = CombineUris(current, contractReference.Ref);
                contractReference.DocRef = CombineUris(current, contractReference.DocRef);
            });
            discoDoc.References.Add(contractReference);

            foreach (Service service in reflector.ServiceDescription.Services) {
                foreach (Port port in service.Ports) {
                    SoapAddressBinding soapAddress = (SoapAddressBinding)port.Extensions.Find(typeof(SoapAddressBinding));
                    if (soapAddress != null) {
                        System.Web.Services.Discovery.SoapBinding binding = new System.Web.Services.Discovery.SoapBinding();
                        binding.Binding = port.Binding;
                        binding.Address = soapAddress.Location;
                        this.AddUriFixup(delegate(Uri current)
                        {
                            binding.Address = CombineUris(current, binding.Address);
                        });
                        discoDoc.References.Add(binding);
                    }
                }
            }
        }
Beispiel #25
0
		internal static void AddImport (ServiceDescription desc, string ns, string location)
		{
			Import im = new Import();
			im.Namespace = ns;
			im.Location = location;
			desc.Imports.Add (im);
		}
Beispiel #26
0
 public virtual void Check(ConformanceCheckContext ctx, Import value)
 {
 }