Exemplo n.º 1
0
        private void AddMinimum(
            WSD.ServiceDescription wsdl,
            string contractName,
            OperationDescriptionCollection operations,
            ServiceEndpoint endpoint)
        {
            // Absolut minimum in order to provide a WSDL
            var portType =
                new WSD.PortType
            {
                Name = contractName
            };

            wsdl.PortTypes.Add(portType);
            var address =
                new WSD.Soap12AddressBinding
            {
                Location = endpoint.Address.ToString()
            };
            var port =
                new WSD.Port
            {
                Name = contractName
            };

            port.Extensions.Add(address);
            var service =
                new WSD.Service
            {
                Name = wsdl.Name
            };

            service.Ports.Add(port);
            wsdl.Services.Add(service);
        }
Exemplo n.º 2
0
 internal Service(System.Web.Services.Description.Service service, TinyXdto.XdtoFactory factory)
 {
     Name          = service.Name;
     NamespaceURI  = service.ServiceDescription.TargetNamespace;
     Documentation = service.Documentation;
     Endpoints     = EndpointCollection.Create(service.Ports, factory);
 }
Exemplo n.º 3
0
        private void ConvertService(DescriptionType wsdl2, ServiceDescription wsdl1)
        {
            var services = wsdl2.Items.Where(s => s is ServiceType);

            foreach (ServiceType s2 in services)
            {
                var s1 = new Service();
                wsdl1.Services.Add(s1);
                s1.Name = s2.name;

                foreach (EndpointType e2 in s2.Items)
                {
                    var p1 = new Port();
                    s1.Ports.Add(p1);

                    p1.Name    = e2.name;
                    p1.Binding = e2.binding;

                    var sab = new SoapAddressBinding()
                    {
                        Location = e2.address
                    };
                    var sab12 = new Soap12AddressBinding()
                    {
                        Location = e2.address
                    };
                    p1.Extensions.Add(sab);
                    p1.Extensions.Add(sab12);
                }
            }
        }
Exemplo n.º 4
0
		public Port ()
		{
			binding = null;
			extensions = new ServiceDescriptionFormatExtensionCollection (this);
#if !NET_2_0
			name = String.Empty;
#endif
			service = null;
		}
		public void TestAddService ()
		{
			const string serviceName = "testService";
			
			Service s = new Service ();
			s.Name = serviceName;
			
			sc.Add (s);

			Assertion.AssertEquals (1, sc.Count);
			Assertion.AssertEquals (s, sc[serviceName]);
		}
 internal static string GetPortName(ServiceEndpoint endpoint, Service wsdlService)
 {
     return NamingHelper.GetUniqueName(endpoint.Name, ServiceContainsPort(wsdlService), null);
 }
Exemplo n.º 7
0
		void ImportService (ServiceDescription desc, TypeStubInfo typeInfo, string url)
		{
			service = desc.Services [typeInfo.LogicalType.WebServiceName];
			if (service == null)
			{
				service = new Service ();
				service.Name = typeInfo.LogicalType.WebServiceName;
				service.Documentation = typeInfo.LogicalType.Description;
				desc.Services.Add (service);
			}
			
			foreach (BindingInfo binfo in typeInfo.Bindings)
				ImportBinding (desc, service, typeInfo, url, binfo);
		}
 internal void SetParent(Service parent) {
     this.parent = parent;
 }
		void ImportBinding (ServiceDescription desc, Service service, TypeStubInfo typeInfo, string url, BindingInfo binfo)
		{
			port = new Port ();
			port.Name = portNames.AddUnique (binfo.Name, port);
			bool bindingFull = true;

			if (binfo.Namespace != desc.TargetNamespace)
			{
				if (binfo.Location == null || binfo.Location == string.Empty)
				{
					ServiceDescription newDesc = new ServiceDescription();
					newDesc.TargetNamespace = binfo.Namespace;
					newDesc.Name = binfo.Name;
					bindingFull = ImportBindingContent (newDesc, typeInfo, url, binfo);
					if (bindingFull) {
						int id = ServiceDescriptions.Add (newDesc);
						AddImport (desc, binfo.Namespace, GetWsdlUrl (url,id));
					}
				}
				else {
					AddImport (desc, binfo.Namespace, binfo.Location);
					bindingFull = true;
				}
			}
			else
				bindingFull = ImportBindingContent (desc, typeInfo, url, binfo);
				
			if (bindingFull)
			{
				port.Binding = new XmlQualifiedName (binding.Name, binfo.Namespace);
				service.Ports.Add (port);
			}
		}
 /// <include file='doc\ServiceDescription.uex' path='docs/doc[@for="ServiceCollection.Add"]/*' />
 /// <devdoc>
 ///    <para>[To be supplied.]</para>
 /// </devdoc>
 public int Add(Service service) {
     return List.Add(service);
 }
Exemplo n.º 11
0
		internal void SetParent (Service service) 
		{
			this.service = service;
		}
Exemplo n.º 12
0
		public Port ()
		{
			binding = null;
			extensions = new ServiceDescriptionFormatExtensionCollection (this);
			service = null;
		}
        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();
            }
        }
        /// <summary>
        /// Generates the WSDL file for a specified <see cref="InterfaceContract"/>.
        /// </summary>
        /// <param name="serviceInterfaceContract">
        /// <see cref="InterfaceContract"/> to use for the WSDL generation.
        /// </param>
        /// <param name="wsdlSaveLocation">Location to save the generated WSDL file.</param>
        /// <param name="xmlComment">XML comment to add to the top of the WSDL file.</param>
        /// <param name="wsdlLocation">Path of an existing WSDL file to overwrite with the generated 
        /// WSDL file.</param>
        /// <returns>The path of the WSDL file generated.</returns>
        /// <remarks>
        /// This methods loads the information, it receive in a <see cref="InterfaceContract"/> to
        /// a <see cref="System.Web.Services.Description.ServiceDescription"/> class, which is later 
        /// used to generate the WSDL file. The loading process takes place in several steps. <br></br>
        /// 1. Load the basic meta data from <see cref="InterfaceContract"/>.<br></br>
        /// 2. Load the schema imports in the <see cref="SchemaImports"/> collection.<br></br>
        /// 3. Load the messages in <see cref="OperationsCollection"/>.<br></br>
        /// 4. Create the WSDL Port Type.<br></br>
        /// 5. Add each operation and it's corresponding in/out messages to the Port Type.<br></br>
        /// 6. Create a WSDL Binding section and add OperationBinding for each operation.<br></br>
        /// 7. Generate the WSDL 'service' tags if required.<br></br>
        /// 8. Finally write the file to the output stream.<br></br>
        /// 
        /// This method generates <see cref="WsdlGenerationException"/> exception, if it fails to create the WSDL file.
        /// If a file is specified to overwrite with the new file, the original file is restored in case of
        /// a failure.
        /// </remarks>
        public static string GenerateWsdl(InterfaceContract serviceInterfaceContract,
            string wsdlSaveLocation, string xmlComment, string wsdlLocation)
        {
            System.Web.Services.Description.ServiceDescription desc = null;

            string serviceAttributeName = "";
            string bindingName = "";
            string serviceName = "";
            string portTypeName = "";

            // Load the existing WSDL if one specified.
            if (wsdlLocation != null)
            {
                #region Round-tripping

                desc = System.Web.Services.Description.ServiceDescription.Read(wsdlLocation);

                // Read the existing name values.
                serviceAttributeName = desc.Name;
                bindingName = desc.Bindings[0].Name;
                portTypeName = desc.PortTypes[0].Name;

                // Check whether we have a service element and save it's name for the 
                // future use.
                if (desc.Services.Count > 0)
                {
                    serviceName = desc.Services[0].Name;
                }
                else
                {
                    serviceName = serviceInterfaceContract.ServiceName + "Port"; ;
                }

                // Check for the place which has the Service name and assign the new value 
                // appropriatly.			
                if (serviceAttributeName != null && serviceAttributeName != "")
                {
                    serviceAttributeName = serviceInterfaceContract.ServiceName;
                }
                else if (serviceName != null && serviceName != "")
                {
                    // If the user has selected to remove the service element, 
                    // use the service name in the attribute by default.
                    if (serviceInterfaceContract.NeedsServiceElement)
                    {
                        serviceName = serviceInterfaceContract.ServiceName;
                    }
                    else
                    {
                        serviceAttributeName = serviceInterfaceContract.ServiceName;
                    }
                }
                else if (bindingName != null && bindingName != "")
                {
                    bindingName = serviceInterfaceContract.ServiceName;
                }

                // Clear the service description. But do not clear the types definitions.
                desc.Extensions.Clear();
                desc.Bindings.Clear();
                desc.Documentation = "";
                desc.Imports.Clear();
                desc.Messages.Clear();
                desc.PortTypes.Clear();
                desc.RetrievalUrl = "";

                if (desc.ServiceDescriptions != null)
                {
                    desc.ServiceDescriptions.Clear();
                }

                if (!serviceInterfaceContract.NeedsServiceElement)
                {
                    desc.Services.Clear();
                }
                #endregion
            }
            else
            {
                #region New WSDL

                desc = new System.Web.Services.Description.ServiceDescription();

                // Create the default names.
                serviceAttributeName = serviceInterfaceContract.ServiceName;
                bindingName = serviceInterfaceContract.ServiceName;
                portTypeName = serviceInterfaceContract.ServiceName + "Interface";
                serviceName = serviceInterfaceContract.ServiceName + "Port";

                #endregion
            }

            #region Load the basic meta data.
            if (serviceAttributeName != null && serviceAttributeName != "")
            {
                desc.Name = serviceAttributeName;
            }
            desc.TargetNamespace = serviceInterfaceContract.ServiceNamespace;
            desc.Documentation = serviceInterfaceContract.ServiceDocumentation;
            #endregion

            #region Load the schema imports.

            XmlSchema typesSchema = null;

            // Are we round-tripping? Then we have to access the existing types 
            // section.
            // Otherwise we just initialize a new XmlSchema for types.
            if (wsdlLocation != null)
            {
                typesSchema = desc.Types.Schemas[desc.TargetNamespace];
                // if we don't have a types section belonging to the same namespace as service description
                // we take the first types section available.                
                if (typesSchema == null)
                {
                    typesSchema = desc.Types.Schemas[0];
                }
                // Remove the includes. We gonna re-add them later in this operation.
                typesSchema.Includes.Clear();
            }
            else
            {
                typesSchema = new XmlSchema();
            }

            // Add imports to the types section resolved above.
            foreach (SchemaImport import in serviceInterfaceContract.Imports)
            {
                XmlSchemaExternal importedSchema = null;
                if (import.SchemaNamespace == null || import.SchemaNamespace == "")
                {
                    importedSchema = new XmlSchemaInclude();
                }
                else
                {
                    importedSchema = new XmlSchemaImport();
                    ((XmlSchemaImport)importedSchema).Namespace = import.SchemaNamespace;
                }
                if (serviceInterfaceContract.UseAlternateLocationForImports)
                {
                    importedSchema.SchemaLocation = import.AlternateLocation;
                }
                else
                {
                    importedSchema.SchemaLocation = import.SchemaLocation;
                }
                typesSchema.Includes.Add(importedSchema);
            }

            // If we are not round-tripping we have to link the types schema we just created to 
            // the service description.
            if (wsdlLocation == null)
            {
                // Finally add the type schema to the ServiceDescription.Types.Schemas collection.
                desc.Types.Schemas.Add(typesSchema);
            }

            #endregion

            #region Load the messages in all the operations

            MessageCollection msgs = desc.Messages;

            foreach (Operation op in serviceInterfaceContract.OperationsCollection)
            {
                foreach (Message msg in op.MessagesCollection)
                {
                    FxMessage tempMsg = new FxMessage();
                    tempMsg.Name = msg.Name;
                    tempMsg.Documentation = msg.Documentation;

                    MessagePart msgPart = new MessagePart();
                    msgPart.Name = Constants.DefaultMessagePartName;
                    msgPart.Element = new XmlQualifiedName(msg.Element.ElementName,
                            msg.Element.ElementNamespace);
                    tempMsg.Parts.Add(msgPart);

                    msgs.Add(tempMsg);
                }

				foreach (Message msg in op.Faults)
				{
					Message messageName = msg;
					if (msgs.OfType<FxMessage>().Any(m => m.Name == messageName.Name)) continue;

					FxMessage tempMsg = new FxMessage();
					tempMsg.Name = msg.Name;
					tempMsg.Documentation = msg.Documentation;

					MessagePart msgPart = new MessagePart();
					msgPart.Name = Constants.FaultMessagePartName;
					msgPart.Element = new XmlQualifiedName(msg.Element.ElementName, msg.Element.ElementNamespace);
					tempMsg.Parts.Add(msgPart);

					msgs.Add(tempMsg);
				}
            }

            #endregion

            #region Create the Port Type

            PortTypeCollection portTypes = desc.PortTypes;
            PortType portType = new PortType();
            portType.Name = portTypeName;
            portType.Documentation = serviceInterfaceContract.ServiceDocumentation;

            // Add each operation and it's corresponding in/out messages to the WSDL Port Type.
            foreach (Operation op in serviceInterfaceContract.OperationsCollection)
            {
                FxOperation tempOperation = new FxOperation();
                tempOperation.Name = op.Name;
                tempOperation.Documentation = op.Documentation;
                int i = 0;

                OperationInput operationInput = new OperationInput();
                operationInput.Message = new XmlQualifiedName(op.MessagesCollection[i].Name, desc.TargetNamespace);

                tempOperation.Messages.Add(operationInput);

                if (op.Mep == Mep.RequestResponse)
                {
                    OperationOutput operationOutput = new OperationOutput();
                    operationOutput.Message = new XmlQualifiedName(op.MessagesCollection[i + 1].Name, desc.TargetNamespace);

                    tempOperation.Messages.Add(operationOutput);
                }

				foreach (Message fault in op.Faults)
				{
					OperationFault operationFault = new OperationFault();
					operationFault.Name = fault.Name;
					operationFault.Message = new XmlQualifiedName(fault.Name, desc.TargetNamespace);
					tempOperation.Faults.Add(operationFault);
				}
				
                portType.Operations.Add(tempOperation);
                i++;
            }

            portTypes.Add(portType);

            #endregion

            // Here we have a list of WCF endpoints.
            // Currently we populate this list with only two endpoints that has default
            // BasicHttpBinding and default NetTcpBinding.
            List<ServiceEndpoint> endpoints = new List<ServiceEndpoint>();

            BasicHttpBinding basicHttpBinding = new BasicHttpBinding();
            endpoints.Add(ServiceEndpointFactory<IDummyContract>.CreateServiceEndpoint(basicHttpBinding));

            // BDS (10/22/2007): Commented out the TCP binding generation as we are not going to support this feature
            // in this version.
            //NetTcpBinding netTcpBinding = new NetTcpBinding();
            //endpoints.Add(ServiceEndpointFactory<IDummyContract>.CreateServiceEndpoint(netTcpBinding));

            // Now, for each endpoint we have to create a binding in our service description.
            foreach (ServiceEndpoint endpoint in endpoints)
            {
                // Create a WSDL BindingCollection.
                BindingCollection bindings = desc.Bindings;
                System.Web.Services.Description.Binding binding = new System.Web.Services.Description.Binding();
                binding.Name = endpoint.Name.Replace(Constants.InternalContractName, portTypeName);
                binding.Type = new XmlQualifiedName(portType.Name, desc.TargetNamespace);

                // Create Operation binding for each operation and add it the the BindingCollection.
                foreach (Operation op in serviceInterfaceContract.OperationsCollection)
                {
                    // SOAP 1.1 Operation bindings.
                    OperationBinding operationBinding1 = new OperationBinding();
                    operationBinding1.Name = op.Name;

                    InputBinding inputBinding1 = new InputBinding();
                    object bodyBindingExtension = GetSoapBodyBinding(endpoint.Binding);
                    if (bodyBindingExtension != null)
                    {
                        inputBinding1.Extensions.Add(bodyBindingExtension);
                    }
                    operationBinding1.Input = inputBinding1;

					// Faults.
                	foreach (Message fault in op.Faults)
                	{
                		FaultBinding faultBinding = new FaultBinding();
                		faultBinding.Name = fault.Name;

						SoapFaultBinding faultBindingExtension = GetFaultBodyBinding(endpoint.Binding);
						if (faultBindingExtension != null)
						{
							faultBindingExtension.Name = fault.Name;
							faultBinding.Extensions.Add(faultBindingExtension);
						}

                		operationBinding1.Faults.Add(faultBinding);
                	}

                    // Input message.
                    // Look up the message headers for each Message and add them to the current binding.
                    foreach (MessageHeader inHeader in op.MessagesCollection[0].HeadersCollection)
                    {
                        object headerBindingExtension = GetSoapHeaderBinding(endpoint.Binding, inHeader.Message, desc.TargetNamespace);
                        if (headerBindingExtension != null)
                        {
                            inputBinding1.Extensions.Add(headerBindingExtension);
                        }
                    }

                    if (op.Mep == Mep.RequestResponse)
                    {
                        // Output message.
                        OutputBinding outputBinding1 = new OutputBinding();
                        object responseBodyBindingExtension = GetSoapBodyBinding(endpoint.Binding);
                        if (responseBodyBindingExtension != null)
                        {
                            outputBinding1.Extensions.Add(responseBodyBindingExtension);
                        }
                        operationBinding1.Output = outputBinding1;

                        // Look up the message headers for each Message and add them to the current binding. 
                        foreach (MessageHeader outHeader in op.MessagesCollection[1].HeadersCollection)
                        {
                            object headerBindingExtension = GetSoapHeaderBinding(endpoint.Binding, outHeader.Message, desc.TargetNamespace);
                            if (headerBindingExtension != null)
                            {
                                outputBinding1.Extensions.Add(headerBindingExtension);
                            }
                        }
                    }

                    string action = desc.TargetNamespace + ":" + op.Input.Name;
                    object operationBindingExtension = GetSoapOperationBinding(endpoint.Binding, action);
                    if (operationBindingExtension != null)
                    {
                        operationBinding1.Extensions.Add(operationBindingExtension);
                    }

                    binding.Operations.Add(operationBinding1);
                    // End of SOAP 1.1 operation bindings.                    
                }

                object soapBindingExtension = GetSoapBinding(endpoint.Binding);
                if (soapBindingExtension != null)
                {
                    binding.Extensions.Add(soapBindingExtension);
                }
                bindings.Add(binding);
            }

            // Generate <service> element optionally - sometimes necessary for interop reasons
            if (serviceInterfaceContract.NeedsServiceElement)
            {
                Service defaultService = null;
                if (wsdlLocation == null || desc.Services.Count == 0)
                {
                    // Create a new service element.
                    defaultService = new Service();
                    defaultService.Name = serviceName;
                    foreach (ServiceEndpoint endpoint in endpoints)
                    {
                        if (endpoint.Binding.MessageVersion.Envelope == EnvelopeVersion.Soap11)
                        {
                            Port defaultPort = new Port();
                            defaultPort.Name = serviceInterfaceContract.ServiceName + "Port";
                            defaultPort.Binding = new XmlQualifiedName(endpoint.Name.Replace(Constants.InternalContractName, portTypeName), desc.TargetNamespace);
                            SoapAddressBinding defaultSoapAddressBinding = new SoapAddressBinding();
                            defaultSoapAddressBinding.Location = GetDefaultEndpoint(endpoint.Binding, serviceInterfaceContract.ServiceName);
                            defaultPort.Extensions.Add(defaultSoapAddressBinding);
                            defaultService.Ports.Add(defaultPort);
                        }
                        else if (endpoint.Binding.MessageVersion.Envelope == EnvelopeVersion.Soap12)
                        {
                            Port soap12Port = new Port();
                            soap12Port.Name = serviceInterfaceContract.ServiceName + "SOAP12Port";
                            soap12Port.Binding = new XmlQualifiedName(endpoint.Name.Replace(Constants.InternalContractName, portTypeName), desc.TargetNamespace);
                            Soap12AddressBinding soap12AddressBinding = new Soap12AddressBinding();
                            soap12AddressBinding.Location = GetDefaultEndpoint(endpoint.Binding, serviceInterfaceContract.ServiceName);
                            soap12Port.Extensions.Add(soap12AddressBinding);
                            defaultService.Ports.Add(soap12Port);
                        }                        
                    }
                    
                    desc.Services.Add(defaultService);                    
                }
                else
                {
                    defaultService = desc.Services[0];
                    defaultService.Name = serviceName;
                }
            }

            // Generate the WSDL file.
            string fileName = string.Empty;
            string bkFileName = string.Empty;

            // Overwrite the existing file if one specified.
            if (wsdlLocation == null)
            {
                fileName = wsdlSaveLocation + @"\" + serviceInterfaceContract.ServiceName + ".wsdl";
            }
            else
            {
                fileName = wsdlLocation;
            }

            // Backup existing file before proceeding.
            if (File.Exists(fileName))
            {
                int index = 1;
                // Create the backup file name. 
                // See whether the generated backup file name is already taken by an existing file and 
                // generate a new file name. 
                while (File.Exists(fileName + "." + index.ToString()))
                {
                    index++;
                }
                bkFileName = fileName + "." + index.ToString();

                // Backup the file.
                try
                {
                    File.Copy(fileName, bkFileName);
                }
                catch (Exception ex)
                {
                    throw new WsdlGenerationException("An error occured while trying to generate a WSDL. Failed to backup the existing WSDL file.", ex);
                }
            }

            StreamWriter writer1 = new StreamWriter(fileName);
            try
            {
                XmlTextWriter writer11 = new XmlTextWriter(writer1);

                writer11.Formatting = Formatting.Indented;
                writer11.Indentation = 2;
                writer11.WriteComment(xmlComment);
                // BDS: Added a new comment line with the date time of WSDL file.
                CultureInfo ci = new CultureInfo("en-US");
                writer11.WriteComment(DateTime.Now.ToString("dddd", ci) + ", " + DateTime.Now.ToString("dd-MM-yyyy - hh:mm tt", ci));

                XmlSerializer serializer1 = System.Web.Services.Description.ServiceDescription.Serializer;
                XmlSerializerNamespaces nsSer = new XmlSerializerNamespaces();
                nsSer.Add("soap", "http://schemas.xmlsoap.org/wsdl/soap/");
                nsSer.Add("soap12", "http://schemas.xmlsoap.org/wsdl/soap12/");
                nsSer.Add("xsd", "http://www.w3.org/2001/XMLSchema");
                nsSer.Add("tns", desc.TargetNamespace);

                // Add the imported namespaces to the WSDL <description> element.
                for (int importIndex = 0; importIndex < serviceInterfaceContract.Imports.Count;
                    importIndex++)
                {
                    if (serviceInterfaceContract.Imports[importIndex].SchemaNamespace != null &&
                        serviceInterfaceContract.Imports[importIndex].SchemaNamespace != "")
                    {
                        nsSer.Add("import" + importIndex.ToString(),
                                  serviceInterfaceContract.Imports[importIndex].SchemaNamespace);
                    }
                }
                // 

                // Finally write the file to the output stram.
                serializer1.Serialize(writer11, desc, nsSer);

                // Close the stream and delete the backupfile.
                writer1.Close();
                if (bkFileName != string.Empty)
                {
                    File.Delete(bkFileName);
                }

                WsdlWorkshop workshop = new WsdlWorkshop(endpoints, fileName, portTypeName);
                workshop.BuildWsdl();
                return fileName;
            }
            catch (Exception ex)
            {
                writer1.Close();
                string message = ex.Message;
                if (ex.InnerException != null)
                {
                    message += ex.InnerException.Message;
                }

                // Restore the original file.
                if (bkFileName != string.Empty)
                {
                    try
                    {
                        File.Copy(bkFileName, fileName, true);
                        File.Delete(bkFileName);
                    }
                    catch
                    {
                        throw new WsdlGenerationException(
                            message + "\nFailed to restore the original file.");
                    }
                }
                else if (File.Exists(fileName))
                {
                    File.Delete(fileName);
                }

                throw new WsdlGenerationException(
                    message, ex);
            }
        }
Exemplo n.º 15
0
        private void ConvertService(DescriptionType wsdl2, ServiceDescription wsdl1)
        {
            var services = wsdl2.Items.Where(s => s is ServiceType);

            foreach (ServiceType s2 in services)
            {
                var s1 = new Service();
                wsdl1.Services.Add(s1);
                s1.Name = s2.name;

                foreach (EndpointType e2 in s2.Items)
                {
                    var p1 = new Port();
                    s1.Ports.Add(p1);

                    p1.Name = e2.name;
                    p1.Binding = e2.binding;

                    var sab = new SoapAddressBinding() { Location = e2.address };
                    var sab12 = new Soap12AddressBinding() { Location = e2.address };
                    p1.Extensions.Add(sab);
                    p1.Extensions.Add(sab12);
                }
            }
        }
 void MoveToBinding(Service service, Port port, Binding binding, PortType portType) {
     this.service = service;
     this.port = port;
     this.portType = portType;
     this.binding = binding;
     this.encodedBinding = false;
 }
		internal bool Import (ServiceDescriptionImporter descriptionImporter, CodeNamespace codeNamespace, CodeCompileUnit codeCompileUnit, ArrayList importInfo)
		{
			this.descriptionImporter = descriptionImporter;
			this.classNames = new CodeIdentifiers();;
			this.codeNamespace = codeNamespace;
			this.codeCompileUnit = codeCompileUnit;

			warnings = (ServiceDescriptionImportWarnings) 0;
			
			bool found = false;
			
			ClasifySchemas (importInfo);

			BeginNamespace ();
			
			foreach (ImportInfo info in importInfo)
			{
				foreach (Service service in info.ServiceDescription.Services)
				{
					this.service = service;
					int bindingCount = 0;
					foreach (Port port in service.Ports)
					{
						binding = ServiceDescriptions.GetBinding (port.Binding);
						if (IsBindingSupported ()) bindingCount ++;
					}
					
					foreach (Port port in service.Ports)
					{
						this.iinfo = info;
						this.port = port;
						binding = ServiceDescriptions.GetBinding (port.Binding);
						if (!IsBindingSupported ()) continue;
						
						found = true;
						ImportPortBinding (bindingCount > 1);
					}
				}
			}
			
			if (!found)
			{
				// Looks like MS.NET generates classes for all bindings if
				// no services are present
				
				foreach (ImportInfo info in importInfo)
				{
					this.iinfo = info;
					foreach (Binding b in info.ServiceDescription.Bindings)
					{
						this.binding = b;
						this.service = null;
						this.port = null;
						if (!IsBindingSupported ()) continue;
						found = true;
						ImportPortBinding (true);
					}
				}
			}

			EndNamespace ();
			
			if (!found) warnings = ServiceDescriptionImportWarnings.NoCodeGenerated;
			return true;
		}
Exemplo n.º 18
0
        WsdlNS.Service GetOrCreateWsdlService(XmlQualifiedName wsdlServiceQName)
        {
            // NOTE: this method is not thread safe

            WsdlNS.ServiceDescription wsdl = GetOrCreateWsdl(wsdlServiceQName.Namespace);

            WsdlNS.Service wsdlService = wsdl.Services[wsdlServiceQName.Name];
            if (wsdlService == null)
            {
                //Service not found. Create service.
                wsdlService = new WsdlNS.Service();
                wsdlService.Name = wsdlServiceQName.Name;

                if (string.IsNullOrEmpty(wsdl.Name))
                    wsdl.Name = wsdlService.Name;

                wsdl.Services.Add(wsdlService);
            }
            return wsdlService;
        }
Exemplo n.º 19
0
		public ServiceEndpointCollection ImportEndpoints (Service service)
		{
			var coll = new ServiceEndpointCollection ();
			
			foreach (Port port in service.Ports) {
				var sep = ImportEndpoint (port, false);
				if (sep != null)
					coll.Add (sep);
			}

			return coll;
		}
Exemplo n.º 20
0
		public int Add (Service service) 
		{
			Insert (Count, service);
			return (Count - 1);
		}
 /// <include file='doc\ServiceDescription.uex' path='docs/doc[@for="ServiceCollection.IndexOf"]/*' />
 /// <devdoc>
 ///    <para>[To be supplied.]</para>
 /// </devdoc>
 public int IndexOf(Service service) {
     return List.IndexOf(service);
 }
 internal PortCollection(Service service) : base(service) { }
 /// <include file='doc\ServiceDescription.uex' path='docs/doc[@for="ServiceCollection.Remove"]/*' />
 /// <devdoc>
 ///    <para>[To be supplied.]</para>
 /// </devdoc>
 public void Remove(Service service) {
     List.Remove(service);
 }
 /// <include file='doc\ServiceDescription.uex' path='docs/doc[@for="ServiceCollection.Insert"]/*' />
 /// <devdoc>
 ///    <para>[To be supplied.]</para>
 /// </devdoc>
 public void Insert(int index, Service service) {
     List.Insert(index, service);
 }
 private static NamingHelper.DoesNameExist ServiceContainsPort(Service service)
 {
     return delegate (string portName, object nameCollection) {
         foreach (Port port in service.Ports)
         {
             if (port.Name == portName)
             {
                 return true;
             }
         }
         return false;
     };
 }
 /// <include file='doc\ServiceDescription.uex' path='docs/doc[@for="ServiceCollection.Contains"]/*' />
 /// <devdoc>
 ///    <para>[To be supplied.]</para>
 /// </devdoc>
 public bool Contains(Service service) {
     return List.Contains(service);
 }
Exemplo n.º 27
0
		public virtual void Check (ConformanceCheckContext ctx, Service value) { }
 /// <include file='doc\ServiceDescription.uex' path='docs/doc[@for="ServiceCollection.CopyTo"]/*' />
 /// <devdoc>
 ///    <para>[To be supplied.]</para>
 /// </devdoc>
 public void CopyTo(Service[] array, int index) {
     List.CopyTo(array, index);
 }
		public override void Check (ConformanceCheckContext ctx, Service value) { }
Exemplo n.º 30
0
		Service GetService (WSServiceDescription sd, string name)
		{
			Service svc = sd.Services [name];
			if (svc != null)
				return svc;

			svc = new Service ();
			svc.Name = name;
			sd.Services.Add (svc);

			return svc;
		}
Exemplo n.º 31
0
		public ServiceEndpointCollection ImportEndpoints (
			Service service)
		{
			throw new NotImplementedException ();
		}
Exemplo n.º 32
0
		void ImportBinding (ServiceDescription desc, Service service, TypeStubInfo typeInfo, string url, BindingInfo binfo)
		{
			port = new Port ();
			port.Name = portNames.AddUnique (binfo.Name, port);
			bool bindingFull = true;

			if (binfo.Namespace != desc.TargetNamespace)
			{
				if (binfo.Location == null || binfo.Location == string.Empty)
				{
					ServiceDescription newDesc = new ServiceDescription();
					newDesc.TargetNamespace = binfo.Namespace;
					newDesc.Name = binfo.Name;
					bindingFull = ImportBindingContent (newDesc, typeInfo, url, binfo);
					if (bindingFull) {
						int id = ServiceDescriptions.Add (newDesc);
						AddImport (desc, binfo.Namespace, GetWsdlUrl (url,id));
					}
				}
				else {
					AddImport (desc, binfo.Namespace, binfo.Location);
					bindingFull = true;
				}
			}
			else
				bindingFull = ImportBindingContent (desc, typeInfo, url, binfo);
				
			if (bindingFull)
			{
				port.Binding = new XmlQualifiedName (binding.Name, binfo.Namespace);
				
				int n = 0;
				string name = binfo.Name; 
				bool found;
				do {

					found = false;
					foreach (Port p in service.Ports)
						if (p.Name == name) { found = true; n++; name = binfo.Name + n; break; }
				}
				while (found);
				port.Name = name;
				service.Ports.Add (port);
			}

			if (binfo.WebServiceBindingAttribute != null && binfo.WebServiceBindingAttribute.ConformsTo != WsiProfiles.None && String.IsNullOrEmpty (binfo.WebServiceBindingAttribute.Name)) {
				BasicProfileViolationCollection violations = new BasicProfileViolationCollection ();
				desc.Types.Schemas.Add (Schemas);
				ServiceDescriptionCollection col = new ServiceDescriptionCollection ();
				col.Add (desc);
				ConformanceCheckContext ctx = new ConformanceCheckContext (col, violations);
				ctx.ServiceDescription = desc;
				ConformanceChecker[] checkers = WebServicesInteroperability.GetCheckers (binfo.WebServiceBindingAttribute.ConformsTo);
				foreach (ConformanceChecker checker in checkers) {
					ctx.Checker = checker;
					WebServicesInteroperability.Check (ctx, checker, binding);
					if (violations.Count > 0)
						throw new InvalidOperationException (violations [0].ToString ());
				}
			}
		}
Exemplo n.º 33
0
		void CheckServicePort (Service svc, string port_name, XmlQualifiedName binding_name, string address, string label)
		{
			Port port = svc.Ports [port_name];
			Assert.IsNotNull (port, label + " #csp0");
			Assert.AreEqual (port.Binding, binding_name, label + " #csp1");

			Assert.AreEqual (1, port.Extensions.Count, label + " #csp2");
			Assert.AreEqual (typeof (SoapAddressBinding), port.Extensions [0].GetType (), label + " #csp3");
			SoapAddressBinding sab = (SoapAddressBinding) port.Extensions [0];
			Assert.AreEqual (address, sab.Location, label + " #csp3");
		}