Example #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);
        }
		internal WsdlEndpointConversionContext (WsdlContractConversionContext context, ServiceEndpoint endpoint, Port port, WSBinding wsdlBinding)
		{
			this.context = context;
			this.endpoint = endpoint;
			this.port = port;
			this.wsdl_binding = wsdlBinding;
		}
 private System.Web.Services.Description.Binding CreateWsdlBindingAndPort(ServiceEndpoint endpoint, XmlQualifiedName wsdlServiceQName, out Port wsdlPort, out bool newBinding, out bool bindingNameWasUniquified)
 {
     System.Web.Services.Description.ServiceDescription orCreateWsdl;
     System.Web.Services.Description.Binding binding;
     WsdlEndpointConversionContext context;
     XmlQualifiedName name;
     XmlQualifiedName type;
     bool flag = IsWsdlExportable(endpoint.Binding);
     if (!this.exportedBindings.TryGetValue(new BindingDictionaryKey(endpoint.Contract, endpoint.Binding), out context))
     {
         name = WsdlNamingHelper.GetBindingQName(endpoint, this, out bindingNameWasUniquified);
         orCreateWsdl = this.GetOrCreateWsdl(name.Namespace);
         binding = new System.Web.Services.Description.Binding {
             Name = name.Name
         };
         newBinding = true;
         PortType wsdlPortType = this.exportedContracts[endpoint.Contract].WsdlPortType;
         type = new XmlQualifiedName(wsdlPortType.Name, wsdlPortType.ServiceDescription.TargetNamespace);
         binding.Type = type;
         if (flag)
         {
             orCreateWsdl.Bindings.Add(binding);
         }
         EnsureWsdlContainsImport(orCreateWsdl, type.Namespace);
     }
     else
     {
         name = new XmlQualifiedName(context.WsdlBinding.Name, context.WsdlBinding.ServiceDescription.TargetNamespace);
         bindingNameWasUniquified = false;
         orCreateWsdl = this.wsdlDocuments[name.Namespace];
         binding = orCreateWsdl.Bindings[name.Name];
         type = binding.Type;
         newBinding = false;
     }
     if (endpoint.Address != null)
     {
         Service orCreateWsdlService = this.GetOrCreateWsdlService(wsdlServiceQName);
         wsdlPort = new Port();
         string portName = WsdlNamingHelper.GetPortName(endpoint, orCreateWsdlService);
         wsdlPort.Name = portName;
         wsdlPort.Binding = name;
         SoapAddressBinding binding2 = SoapHelper.GetOrCreateSoapAddressBinding(binding, wsdlPort, this);
         if (binding2 != null)
         {
             binding2.Location = endpoint.Address.Uri.AbsoluteUri;
         }
         EnsureWsdlContainsImport(orCreateWsdlService.ServiceDescription, name.Namespace);
         if (flag)
         {
             orCreateWsdlService.Ports.Add(wsdlPort);
         }
         return binding;
     }
     wsdlPort = null;
     return binding;
 }
 internal static WsdlNS.SoapAddressBinding GetSoapAddressBinding(WsdlNS.Port wsdlPort)
 {
     foreach (object o in wsdlPort.Extensions)
     {
         if (o is WsdlNS.SoapAddressBinding)
         {
             return((WsdlNS.SoapAddressBinding)o);
         }
     }
     return(null);
 }
 internal WsdlEndpointConversionContext(WsdlContractConversionContext contractContext, ServiceEndpoint endpoint, Binding wsdlBinding, Port wsdlport)
 {
     this.endpoint = endpoint;
     this.wsdlBinding = wsdlBinding;
     this.wsdlPort = wsdlport;
     this.contractContext = contractContext;
     this.wsdlOperationBindings = new Dictionary<OperationDescription, OperationBinding>();
     this.operationDescriptionBindings = new Dictionary<OperationBinding, OperationDescription>();
     this.wsdlMessageBindings = new Dictionary<MessageDescription, MessageBinding>();
     this.messageDescriptionBindings = new Dictionary<MessageBinding, MessageDescription>();
     this.wsdlFaultBindings = new Dictionary<FaultDescription, FaultBinding>();
     this.faultDescriptionBindings = new Dictionary<FaultBinding, FaultDescription>();
 }
 internal WsdlEndpointConversionContext(WsdlEndpointConversionContext bindingContext, ServiceEndpoint endpoint, Port wsdlport)
 {
     this.endpoint = endpoint;
     this.wsdlBinding = bindingContext.WsdlBinding;
     this.wsdlPort = wsdlport;
     this.contractContext = bindingContext.contractContext;
     this.wsdlOperationBindings = bindingContext.wsdlOperationBindings;
     this.operationDescriptionBindings = bindingContext.operationDescriptionBindings;
     this.wsdlMessageBindings = bindingContext.wsdlMessageBindings;
     this.messageDescriptionBindings = bindingContext.messageDescriptionBindings;
     this.wsdlFaultBindings = bindingContext.wsdlFaultBindings;
     this.faultDescriptionBindings = bindingContext.faultDescriptionBindings;
 }
Example #7
0
        internal WsdlEndpointConversionContext(WsdlEndpointConversionContext bindingContext, ServiceEndpoint endpoint, WsdlNS.Port wsdlport)
        {
            _endpoint        = endpoint;
            _wsdlBinding     = bindingContext.WsdlBinding;
            _wsdlPort        = wsdlport;
            _contractContext = bindingContext._contractContext;

            _wsdlOperationBindings        = bindingContext._wsdlOperationBindings;
            _operationDescriptionBindings = bindingContext._operationDescriptionBindings;
            _wsdlMessageBindings          = bindingContext._wsdlMessageBindings;
            _messageDescriptionBindings   = bindingContext._messageDescriptionBindings;
            _wsdlFaultBindings            = bindingContext._wsdlFaultBindings;
            _faultDescriptionBindings     = bindingContext._faultDescriptionBindings;
        }
        internal WsdlEndpointConversionContext(WsdlEndpointConversionContext bindingContext, ServiceEndpoint endpoint, WsdlNS.Port wsdlport)
        {
            this.endpoint        = endpoint;
            this.wsdlBinding     = bindingContext.WsdlBinding;
            this.wsdlPort        = wsdlport;
            this.contractContext = bindingContext.contractContext;

            this.wsdlOperationBindings        = bindingContext.wsdlOperationBindings;
            this.operationDescriptionBindings = bindingContext.operationDescriptionBindings;
            this.wsdlMessageBindings          = bindingContext.wsdlMessageBindings;
            this.messageDescriptionBindings   = bindingContext.messageDescriptionBindings;
            this.wsdlFaultBindings            = bindingContext.wsdlFaultBindings;
            this.faultDescriptionBindings     = bindingContext.faultDescriptionBindings;
        }
Example #9
0
        internal WsdlEndpointConversionContext(WsdlContractConversionContext contractContext, ServiceEndpoint endpoint, WsdlNS.Binding wsdlBinding, WsdlNS.Port wsdlport)
        {
            _endpoint        = endpoint;
            _wsdlBinding     = wsdlBinding;
            _wsdlPort        = wsdlport;
            _contractContext = contractContext;

            _wsdlOperationBindings        = new Dictionary <OperationDescription, WsdlNS.OperationBinding>();
            _operationDescriptionBindings = new Dictionary <WsdlNS.OperationBinding, OperationDescription>();
            _wsdlMessageBindings          = new Dictionary <MessageDescription, WsdlNS.MessageBinding>();
            _messageDescriptionBindings   = new Dictionary <WsdlNS.MessageBinding, MessageDescription>();
            _wsdlFaultBindings            = new Dictionary <FaultDescription, WsdlNS.FaultBinding>();
            _faultDescriptionBindings     = new Dictionary <WsdlNS.FaultBinding, FaultDescription>();
        }
Example #10
0
        private static void AddAddressToWsdlPort(WsdlNS.Port wsdlPort, EndpointAddress endpointAddress, AddressingVersion addressing)
        {
            if (addressing == AddressingVersion.None)
            {
                return;
            }

            MemoryStream memoryStream = new MemoryStream();
            XmlWriter    xmlWriter    = XmlWriter.Create(memoryStream);

            xmlWriter.WriteStartElement("temp");

            if (addressing == AddressingVersion.WSAddressing10)
            {
                xmlWriter.WriteAttributeString("xmlns", "wsa10", null, AddressingVersionConstants.WSAddressing10NameSpace);
            }
            else if (addressing == AddressingVersion.WSAddressingAugust2004)
            {
                xmlWriter.WriteAttributeString("xmlns", "wsa", null, AddressingVersionConstants.WSAddressingAugust2004NameSpace);
            }
            else
            {
                throw new InvalidOperationException("This addressing version is not supported:\n" + addressing.ToString());
            }

            endpointAddress.WriteTo(addressing, xmlWriter);
            xmlWriter.WriteEndElement();

            xmlWriter.Flush();
            memoryStream.Seek(0, SeekOrigin.Begin);

            XmlReader xmlReader = XmlReader.Create(memoryStream);

            xmlReader.MoveToContent();



            XmlElement endpointReference = (XmlElement)XmlDoc.ReadNode(xmlReader).ChildNodes[0];

            wsdlPort.Extensions.Add(endpointReference);
        }
Example #11
0
        public string GenerateHttpGetMessage(Port port, OperationBinding obin, Operation oper, OperationMessage msg)
        {
            string req = "";

            if (msg is OperationInput) {
                HttpAddressBinding sab = port.Extensions.Find(typeof(HttpAddressBinding)) as HttpAddressBinding;
                HttpOperationBinding sob = obin.Extensions.Find(typeof(HttpOperationBinding)) as HttpOperationBinding;
                string location = new Uri(sab.Location).AbsolutePath + sob.Location + "?" + BuildQueryString(msg);
                req += "GET " + location + "\n";
                req += "Host: " + GetLiteral("string");
            }
            else {
                req += "HTTP/1.0 200 OK\n";
                req += "Content-Type: text/xml; charset=utf-8\n";
                req += "Content-Length: " + GetLiteral("string") + "\n\n";

                MimeXmlBinding mxb = (MimeXmlBinding)obin.Output.Extensions.Find(typeof(MimeXmlBinding)) as MimeXmlBinding;
                if (mxb == null) return req;

                Message message = descriptions.GetMessage(msg.Message);
                XmlQualifiedName ename = null;
                foreach (MessagePart part in message.Parts)
                    if (part.Name == mxb.Part) ename = part.Element;

                if (ename == null) return req + GetLiteral("string");

                StringWriter sw = new StringWriter();
                XmlTextWriter xtw = new XmlTextWriter(sw);
                xtw.Formatting = Formatting.Indented;
                currentUse = SoapBindingUse.Literal;
                WriteRootElementSample(xtw, ename);
                xtw.Close();
                req += sw.ToString();
            }

            return req;
        }
        /// <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);
            }
        }
Example #13
0
        public string GenerateHttpPostMessage(Port port, OperationBinding obin, Operation oper, OperationMessage msg)
        {
            string req = "";

            if (msg is OperationInput) {
                HttpAddressBinding sab = port.Extensions.Find(typeof(HttpAddressBinding)) as HttpAddressBinding;
                HttpOperationBinding sob = obin.Extensions.Find(typeof(HttpOperationBinding)) as HttpOperationBinding;
                string location = new Uri(sab.Location).AbsolutePath + sob.Location;
                req += "POST " + location + "\n";
                req += "Content-Type: application/x-www-form-urlencoded\n";
                req += "Content-Length: " + GetLiteral("string") + "\n";
                req += "Host: " + GetLiteral("string") + "\n\n";
                req += BuildQueryString(msg);
            }
            else return GenerateHttpGetMessage(port, obin, oper, msg);

            return req;
        }
 /// <include file='doc\ServiceDescription.uex' path='docs/doc[@for="PortCollection.Remove"]/*' />
 /// <devdoc>
 ///    <para>[To be supplied.]</para>
 /// </devdoc>
 public void Remove(Port port) {
     List.Remove(port);
 }
		Port ExportService (WSServiceDescription sd, WSBinding ws_binding, EndpointAddress address, bool msg_version_none)
		{
			if (address == null)
				return null;

			Service ws_svc = GetService (sd, "service");
			sd.Name = "service";

				Port ws_port = new Port ();
				ws_port.Name = ws_binding.Name;
				ws_port.Binding = new QName (ws_binding.Name, sd.TargetNamespace);

				if (!msg_version_none) {
					SoapAddressBinding soap_addr = new SoapAddressBinding ();
					soap_addr.Location = address.Uri.AbsoluteUri;

					ws_port.Extensions.Add (soap_addr);
				}

			ws_svc.Ports.Add (ws_port);

			return ws_port;
		}
Example #16
0
		public ServiceEndpoint ImportEndpoint (Port wsdlPort)
		{
			return ImportEndpoint (wsdlPort, true);
		}
 /// <include file='doc\ServiceDescription.uex' path='docs/doc[@for="PortCollection.IndexOf"]/*' />
 /// <devdoc>
 ///    <para>[To be supplied.]</para>
 /// </devdoc>
 public int IndexOf(Port port) {
     return List.IndexOf(port);
 }
        // -----------------------------------------------------------------------------------------------------------------------
        // Developers Note: We go through a little song an dance here to Get or Create an exsisting SoapBinding from the WSDL
        // Extensions for a number of reasons:
        //      1. Multiple Extensions may contribute to the settings in the soap binding and so to make this work without
        //          relying on ordering, we need the GetOrCreate method.
        //      2. There are diffrent classes for diffrent SOAP versions and the extensions that determines the version is
        //          also un-ordered so when we finally figure out the version we may need to recreate the BindingExtension and
        //          clone it.

        internal static WsdlNS.SoapAddressBinding GetOrCreateSoapAddressBinding(WsdlNS.Binding wsdlBinding, WsdlNS.Port wsdlPort, WsdlExporter exporter)
        {
            if (GetSoapVersionState(wsdlBinding, exporter) == EnvelopeVersion.None)
            {
                return(null);
            }

            WsdlNS.SoapAddressBinding existingSoapAddressBinding = GetSoapAddressBinding(wsdlPort);
            EnvelopeVersion           version = GetSoapVersion(wsdlBinding);

            if (existingSoapAddressBinding != null)
            {
                return(existingSoapAddressBinding);
            }

            WsdlNS.SoapAddressBinding soapAddressBinding = CreateSoapAddressBinding(version, wsdlPort);
            return(soapAddressBinding);
        }
Example #19
0
		ServiceEndpoint ImportEndpoint (Port port, bool throwOnError)
		{
			ServiceEndpoint endpoint;
			if (endpointHash.ContainsKey (port)) {
				endpoint = endpointHash [port];
				if (endpoint != null)
					return endpoint;
				
				if (!throwOnError)
					return null;
				
				throw new InvalidOperationException (String.Format (
					"Failed to import port `{0}', an error has " +
					"already been reported before.", port.Name));
			}

			var binding = port.Service.ServiceDescription.Bindings [port.Binding.Name];
			if (binding == null) {
				endpointHash.Add (port, null);
				var error = AddError (
					"Failed to import port `{0}': cannot find binding `{1}' that " +
					"this port depends on.", port.Name, port.Binding.Name);
				if (throwOnError)
					throw new MetadataImportException (error);
				return null;
			}

			try {
				endpoint = ImportBinding (binding, throwOnError);
			} catch (Exception ex) {
				endpointHash.Add (port, null);
				var error = AddError (
					"Failed to import port `{0}': error while trying to import " +
					"binding `{1}' that this port depends on: {2}",
					port.Name, port.Binding.Name, ex.Message);
				if (throwOnError)
					throw new MetadataImportException (error, ex);
				return null;
			}

			if (endpoint == null) {
				endpointHash.Add (port, null);
				AddError (
					"Failed to import port `{0}': error while trying to import " +
					"binding `{1}' that this port depends on.",
					port.Name, port.Binding.Name);
				return null;
			}

			try {
				ImportEndpoint (port, binding, endpoint, throwOnError);
				endpointHash.Add (port, endpoint);
				return endpoint;
			} catch (MetadataImportException) {
				endpointHash.Add (port, null);
				if (throwOnError)
					throw;
				return null;
			} catch (Exception ex) {
				endpointHash.Add (port, null);
				var error = AddError (
					"Failed to import port `{0}': {1}", port.Name, ex.Message);
				if (throwOnError)
					throw new MetadataImportException (error, ex);
				return null;
			}
		}
		public override void Check (ConformanceCheckContext ctx, Port value) { }
Example #21
0
		public virtual void Check (ConformanceCheckContext ctx, Port value) { }
        void ReflectBinding(ReflectedBinding reflectedBinding) {
            string bindingName = XmlConvert.EncodeLocalName(reflectedBinding.bindingAttr.Name);
            string bindingNamespace = reflectedBinding.bindingAttr.Namespace;
            if (bindingName.Length == 0) bindingName = Service.Name + ProtocolName;
            if (bindingNamespace.Length == 0) bindingNamespace = ServiceDescription.TargetNamespace;
            WsiProfiles claims = WsiProfiles.None;
            
            if (reflectedBinding.bindingAttr.Location.Length > 0) {
                // If a URL is specified for the WSDL, file, then we just import the
                // binding from there instead of generating it in this WSDL file.
                portType = null;
                binding = null;
            }
            else {
                bindingServiceDescription = GetServiceDescription(bindingNamespace);
                CodeIdentifiers bindingNames = new CodeIdentifiers();
                foreach (Binding b in bindingServiceDescription.Bindings)
                    bindingNames.AddReserved(b.Name);

                bindingName = bindingNames.AddUnique(bindingName, binding);

                portType = new PortType();
                binding = new Binding();
                portType.Name = bindingName;
                binding.Name = bindingName;
                binding.Type = new XmlQualifiedName(portType.Name, bindingNamespace);
                claims = reflectedBinding.bindingAttr.ConformsTo & this.ConformsTo;
                if (reflectedBinding.bindingAttr.EmitConformanceClaims && claims != WsiProfiles.None) {
                    ServiceDescription.AddConformanceClaims(binding.GetDocumentationElement(), claims);
                }
                bindingServiceDescription.Bindings.Add(binding);
                bindingServiceDescription.PortTypes.Add(portType);
            }
            
            if (portNames == null) {
                portNames = new CodeIdentifiers();
                foreach (Port p in Service.Ports)
                    portNames.AddReserved(p.Name);
            }

            port = new Port();
            port.Binding = new XmlQualifiedName(bindingName, bindingNamespace);
            port.Name = portNames.AddUnique(bindingName, port);
            Service.Ports.Add(port);
            
            BeginClass();

            if (reflectedBinding.methodList != null && reflectedBinding.methodList.Count > 0) {
                foreach (LogicalMethodInfo method in reflectedBinding.methodList) {

                    MoveToMethod(method);

                    operation = new Operation();
                    operation.Name = XmlConvert.EncodeLocalName(method.Name);
                    if (methodAttr.Description != null && methodAttr.Description.Length > 0)
                        operation.Documentation = methodAttr.Description;

                    operationBinding = new OperationBinding();
                    operationBinding.Name = operation.Name;

                    inputMessage = null;
                    outputMessage = null;
                    headerMessages = null;

                    if (ReflectMethod()) {
                        if (inputMessage != null) bindingServiceDescription.Messages.Add(inputMessage);
                        if (outputMessage != null) bindingServiceDescription.Messages.Add(outputMessage);
                        if (headerMessages != null) {
                            foreach (Message headerMessage in headerMessages) {
                                bindingServiceDescription.Messages.Add(headerMessage);
                            }
                        }
                        binding.Operations.Add(operationBinding);
                        portType.Operations.Add(operation);
                    }
                }
            }
            if (binding != null && claims == WsiProfiles.BasicProfile1_1 && ProtocolName == "Soap") {
                BasicProfileViolationCollection warnings = new BasicProfileViolationCollection();
                WebServicesInteroperability.AnalyzeBinding(binding, bindingServiceDescription, ServiceDescriptions, warnings);
                if (warnings.Count > 0) {
                    throw new InvalidOperationException(Res.GetString(Res.WebWsiViolation, ServiceType.FullName, warnings.ToString()));
                }
            }
            EndClass();
        }
		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;
		}
Example #24
0
		void ImportEndpoint (Port port, WSBinding wsb, ServiceEndpoint sep, bool throwOnError)
		{
			BeforeImport ();

			var port_type = GetPortTypeFromBinding (wsb);

			var contract_context = new WsdlContractConversionContext (sep.Contract, port_type);
			WsdlEndpointConversionContext endpoint_context = new WsdlEndpointConversionContext (
					contract_context, sep, port, wsb);

			foreach (IWsdlImportExtension extension in wsdl_extensions)
				extension.ImportEndpoint (this, endpoint_context);
		}
 /// <include file='doc\ServiceDescription.uex' path='docs/doc[@for="PortCollection.Add"]/*' />
 /// <devdoc>
 ///    <para>[To be supplied.]</para>
 /// </devdoc>
 public int Add(Port port) {
     return List.Add(port);
 }
		void ClasifySchemas (ArrayList importInfo)
		{
			// I don't like this, but I could not find any other way of clasifying
			// schemas between encoded and literal.
			
			xmlSchemas = new XmlSchemas ();
			soapSchemas = new XmlSchemas ();
			
			foreach (ImportInfo info in importInfo)
			{
				foreach (Service service in info.ServiceDescription.Services)
				{
					foreach (Port port in service.Ports)
					{
						this.iinfo = info;
						this.port = port;
						binding = ServiceDescriptions.GetBinding (port.Binding);
						if (binding == null) continue;
						portType = ServiceDescriptions.GetPortType (binding.Type);
						if (portType == null) continue;
						
						foreach (OperationBinding oper in binding.Operations) 
						{
							operationBinding = oper;
							operation = FindPortOperation ();
							if (operation == null) continue;
		
							foreach (OperationMessage omsg in operation.Messages)
							{
								Message msg = ServiceDescriptions.GetMessage (omsg.Message);
								if (msg == null) continue;
								
								if (omsg is OperationInput)
									inputMessage = msg;
								else
									outputMessage = msg;
							}
							
							if (GetMessageEncoding (oper.Input) == SoapBindingUse.Encoded)
								AddMessageSchema (soapSchemas, oper.Input, inputMessage);
							else
								AddMessageSchema (xmlSchemas, oper.Input, inputMessage);
							
							if (oper.Output != null) {
								if (GetMessageEncoding (oper.Output) == SoapBindingUse.Encoded)
									AddMessageSchema (soapSchemas, oper.Output, outputMessage);
								else
									AddMessageSchema (xmlSchemas, oper.Output, outputMessage);
							}
						}
					}
				}
			}
			
			XmlSchemas defaultList = xmlSchemas;
				
			if (xmlSchemas.Count == 0 && soapSchemas.Count > 0)
				defaultList = soapSchemas;
				
			// Schemas not referenced by any message
			foreach (XmlSchema sc in Schemas)
			{
				if (!soapSchemas.Contains (sc) && !xmlSchemas.Contains (sc)) {
					if (ImportsEncodedNamespace (sc))
						soapSchemas.Add (sc);
					else
						defaultList.Add (sc);
				}
			}
		}
        static WsdlNS.SoapAddressBinding CreateSoapAddressBinding(EnvelopeVersion version, WsdlNS.Port wsdlPort)
        {
            WsdlNS.SoapAddressBinding soapAddressBinding = null;

            if (version == EnvelopeVersion.Soap12)
            {
                soapAddressBinding = new WsdlNS.Soap12AddressBinding();
            }
            else if (version == EnvelopeVersion.Soap11)
            {
                soapAddressBinding = new WsdlNS.SoapAddressBinding();
            }
            Fx.Assert(soapAddressBinding != null, "EnvelopeVersion is not recognized. Please update the SoapHelper class");

            wsdlPort.Extensions.Add(soapAddressBinding);
            return(soapAddressBinding);
        }
		public ServiceEndpoint ImportEndpoint (Port wsdlPort)
		{
			foreach (IWsdlImportExtension extension in wsdl_extensions) {
				extension.BeforeImport (wsdl_documents, xmlschemas, policies);
			}

			//Get the corresponding contract
			//via the PortType
			WSBinding wsb = wsdlPort.Service.ServiceDescription.Bindings [wsdlPort.Binding.Name];
			if (wsb == null)
				//FIXME
				throw new Exception (String.Format ("Binding named {0} not found.", wsdlPort.Binding.Name));

			SMBinding binding = ImportBinding (wsb);

			PortType port_type = null;
			foreach (WSServiceDescription sd in wsdl_documents) {
				port_type = sd.PortTypes [wsb.Type.Name];
				if (port_type != null)
					break;
			}

			if (port_type == null)
				//FIXME
				throw new Exception (String.Format ("PortType named {0} not found.", wsb.Type.Name));

			ContractDescription contract = ImportContract (port_type);
			ServiceEndpoint sep = new ServiceEndpoint (contract);

			sep.Binding = binding;

			WsdlContractConversionContext contract_context = new WsdlContractConversionContext (contract, port_type);
			WsdlEndpointConversionContext endpoint_context = new WsdlEndpointConversionContext (
					contract_context, sep, wsdlPort, wsb);

			foreach (IWsdlImportExtension extension in wsdl_extensions)
				extension.ImportEndpoint (this, endpoint_context);

			return sep;
		}
Example #29
0
		Port ExportService (WSServiceDescription sd, WSBinding ws_binding, EndpointAddress address)
		{
			if (address == null)
				return null;

			Service ws_svc = GetService (sd, "service");
			sd.Name = "service";

			Port ws_port = new Port ();
			ws_port.Name = ws_binding.Name;
			ws_port.Binding = new QName (ws_binding.Name, sd.TargetNamespace);

			ws_svc.Ports.Add (ws_port);

			return ws_port;
		}
 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;
 }
 /// <include file='doc\ServiceDescription.uex' path='docs/doc[@for="PortCollection.Insert"]/*' />
 /// <devdoc>
 ///    <para>[To be supplied.]</para>
 /// </devdoc>
 public void Insert(int index, Port port) {
     List.Insert(index, port);
 }
        WsdlNS.Binding CreateWsdlBindingAndPort(ServiceEndpoint endpoint, XmlQualifiedName wsdlServiceQName, out WsdlNS.Port wsdlPort, out bool newBinding, out bool bindingNameWasUniquified)
        {
            WsdlNS.ServiceDescription bindingWsdl;
            WsdlNS.Binding wsdlBinding;
            WsdlEndpointConversionContext bindingConversionContext;
            XmlQualifiedName wsdlBindingQName;
            XmlQualifiedName wsdlPortTypeQName;
            bool printWsdlDeclaration = IsWsdlExportable(endpoint.Binding);

            if (!exportedBindings.TryGetValue(new BindingDictionaryKey(endpoint.Contract, endpoint.Binding), out bindingConversionContext))
            {
                wsdlBindingQName = WsdlNamingHelper.GetBindingQName(endpoint, this, out bindingNameWasUniquified);
                bindingWsdl = GetOrCreateWsdl(wsdlBindingQName.Namespace);
                wsdlBinding = new WsdlNS.Binding();
                wsdlBinding.Name = wsdlBindingQName.Name;
                newBinding = true;

                WsdlNS.PortType wsdlPortType = exportedContracts[endpoint.Contract].WsdlPortType;
                wsdlPortTypeQName = new XmlQualifiedName(wsdlPortType.Name, wsdlPortType.ServiceDescription.TargetNamespace);
                wsdlBinding.Type = wsdlPortTypeQName;
                if (printWsdlDeclaration)
                {
                    bindingWsdl.Bindings.Add(wsdlBinding);
                }
                WsdlExporter.EnsureWsdlContainsImport(bindingWsdl, wsdlPortTypeQName.Namespace);
            }
            else
            {
                wsdlBindingQName = new XmlQualifiedName(bindingConversionContext.WsdlBinding.Name, bindingConversionContext.WsdlBinding.ServiceDescription.TargetNamespace);
                bindingNameWasUniquified = false;
                bindingWsdl = wsdlDocuments[wsdlBindingQName.Namespace];
                wsdlBinding = bindingWsdl.Bindings[wsdlBindingQName.Name];
                wsdlPortTypeQName = wsdlBinding.Type;
                newBinding = false;
            }


            //We can only create a Port if there is an address
            if (endpoint.Address != null)
            {
                WsdlNS.Service wsdlService = GetOrCreateWsdlService(wsdlServiceQName);

                wsdlPort = new WsdlNS.Port();
                string wsdlPortName = WsdlNamingHelper.GetPortName(endpoint, wsdlService);
                wsdlPort.Name = wsdlPortName;
                wsdlPort.Binding = wsdlBindingQName;

                WsdlNS.SoapAddressBinding addressBinding = SoapHelper.GetOrCreateSoapAddressBinding(wsdlBinding, wsdlPort, this);

                if (addressBinding != null)
                {
                    addressBinding.Location = endpoint.Address.Uri.AbsoluteUri;
                }

                WsdlExporter.EnsureWsdlContainsImport(wsdlService.ServiceDescription, wsdlBindingQName.Namespace);
                if (printWsdlDeclaration)
                {
                    wsdlService.Ports.Add(wsdlPort);
                }
            }
            else
            {
                wsdlPort = null;
            }

            return wsdlBinding;
        }
 /// <include file='doc\ServiceDescription.uex' path='docs/doc[@for="PortCollection.Contains"]/*' />
 /// <devdoc>
 ///    <para>[To be supplied.]</para>
 /// </devdoc>
 public bool Contains(Port port) {
     return List.Contains(port);
 }
 private static bool SoapPort(Port p)
 {
   return p.Extensions.OfType<SoapAddressBinding>().Any()
     || p.Extensions.OfType<Soap12AddressBinding>().Any();
 }
 /// <include file='doc\ServiceDescription.uex' path='docs/doc[@for="PortCollection.CopyTo"]/*' />
 /// <devdoc>
 ///    <para>[To be supplied.]</para>
 /// </devdoc>
 public void CopyTo(Port[] array, int index) {
     List.CopyTo(array, index);
 }
Example #36
0
        public string GenerateHttpSoapMessage(Port port, OperationBinding obin, Operation oper, OperationMessage msg)
        {
            string req = "";

            if (msg is OperationInput) {
                SoapAddressBinding sab = port.Extensions.Find(typeof(SoapAddressBinding)) as SoapAddressBinding;
                SoapOperationBinding sob = obin.Extensions.Find(typeof(SoapOperationBinding)) as SoapOperationBinding;

                req += "POST " + GetAbsolutePath(sab.Location) + "\n";
                req += "SOAPAction: " + sob.SoapAction + "\n";
                req += "Content-Type: text/xml; charset=utf-8\n";
                req += "Content-Length: " + GetLiteral("string") + "\n";
                req += "Host: " + GetLiteral("string") + "\n\n";
            }
            else {
                req += "HTTP/1.0 200 OK\n";
                req += "Content-Type: text/xml; charset=utf-8\n";
                req += "Content-Length: " + GetLiteral("string") + "\n\n";
            }

            req += GenerateSoapMessage(obin, oper, msg);
            return req;
        }
Example #37
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 ());
				}
			}
		}
Example #38
0
        public string GenerateMessage(Port port, OperationBinding obin, Operation oper, string protocol, bool generateInput)
        {
            OperationMessage msg = null;
            foreach (OperationMessage opm in oper.Messages) {
                if (opm is OperationInput && generateInput) msg = opm;
                else if (opm is OperationOutput && !generateInput) msg = opm;
            }
            if (msg == null) return null;

            switch (protocol) {
                case "Soap": return GenerateHttpSoapMessage(port, obin, oper, msg);
                case "HttpGet": return GenerateHttpGetMessage(port, obin, oper, msg);
                case "HttpPost": return GenerateHttpPostMessage(port, obin, oper, msg);
            }
            return "Unknown protocol";
        }