private void CreateEncodedMessage(Message message, MessageBinding messageBinding, XmlMembersMapping members, bool wrapped)
 {
     this.SoapExporter.ExportMembersMapping(members, wrapped);
     if (wrapped)
     {
         MessagePart messagePart = new MessagePart {
             Name = "parameters",
             Type = new XmlQualifiedName(members.TypeName, members.TypeNamespace)
         };
         message.Parts.Add(messagePart);
     }
     else
     {
         for (int i = 0; i < members.Count; i++)
         {
             XmlMemberMapping mapping = members[i];
             MessagePart part2 = new MessagePart {
                 Name = mapping.XsdElementName,
                 Type = new XmlQualifiedName(mapping.TypeName, mapping.TypeNamespace)
             };
             message.Parts.Add(part2);
         }
     }
     messageBinding.Extensions.Add(this.CreateSoapBodyBinding(SoapBindingUse.Encoded, members.Namespace));
 }
        void CheckMessage(WSServiceDescription sd, string msg_name, string part_name, string part_type, bool is_type, string label)
        {
            WSMessage m = sd.Messages [msg_name];

            Assert.IsNotNull(m, label + " : Message named " + msg_name + " not found.");

            Assert.AreEqual(msg_name, m.Name, label + " #cm1");
            Assert.AreEqual(0, m.Extensions.Count, label + " #cm2");

            Assert.IsNull(m.ExtensibleAttributes, label + " #cm3a");
            Assert.AreEqual(1, m.Parts.Count, label + " #cm3");

            Assert.AreEqual(part_name, m.Parts [0].Name, label + " #cm9");

            if (is_type)
            {
                Assert.AreEqual("", m.Parts [0].Element.ToString(), label + " #cm4");
                Assert.AreEqual(part_type, m.Parts [0].Type.ToString(), label + " #cm4a");
            }
            else
            {
                Assert.AreEqual("", m.Parts [0].Type.ToString(), label + " #cm5");
                Assert.AreEqual(part_type, m.Parts [0].Element.ToString(), label + " #cm5a");
            }

            Assert.IsNull(m.Parts [0].ExtensibleAttributes, label + " #cm6");
            Assert.AreEqual(0, m.Parts [0].Extensions.Count, label + " #cm7");
        }
Example #3
0
		public MessagePart ()
		{
			element = XmlQualifiedName.Empty;
			message = null;
			type = XmlQualifiedName.Empty;
			extensions = new ServiceDescriptionFormatExtensionCollection (this);
		}
Example #4
0
private TreeNode MessageToTreeNode(OperationMessage omsg, SoapBindingUse use)
{			
	Message msg=_services.GetMessage (omsg.Message);
	
	TreeNode node=new TreeNode() ;
	SchemaParser ngen=new SchemaParser(_schemas);
	ngen.BindingUse=use;

	foreach (MessagePart part in msg.Parts)
	{
		if (part.Element == XmlQualifiedName.Empty)
		    {
			TreeNode partNode=ngen.Translate(part.Type);
			partNode.ImageIndex=5;
			partNode.SelectedImageIndex=5;
			partNode.Text=part.Name;
			node.Nodes.Add(partNode);
		     }
		else
		{
		TreeNode partNode=ngen.Translate(part.Element);
		partNode.ImageIndex=5;
		  partNode.SelectedImageIndex=5;

		  partNode.Text=part.Name;
		  node.Nodes.Add(partNode);
		  }

		  }

		return node;			
		}
		public MessagePart ()
		{
			element = XmlQualifiedName.Empty;
			message = null;
#if !NET_2_0
			name = String.Empty;
#endif
			type = XmlQualifiedName.Empty;
		}
 internal static bool Check(MessagePart part, Message message, WsdlWarningHandler warningHandler)
 {
     if (string.IsNullOrEmpty(part.Name))
     {
         string str = System.ServiceModel.SR.GetString("XsdMissingRequiredAttribute1", new object[] { "name" });
         string warning = System.ServiceModel.SR.GetString("IgnoreMessagePart3", new object[] { message.Name, message.ServiceDescription.TargetNamespace, str });
         warningHandler(warning);
         return false;
     }
     return true;
 }
Example #7
0
		public MessagePart ()
		{
			element = XmlQualifiedName.Empty;
			message = null;
#if !NET_2_0
			name = String.Empty;
#endif
			type = XmlQualifiedName.Empty;
#if NET_2_0
			extensions = new ServiceDescriptionFormatExtensionCollection (this);
#endif
		}
Example #8
0
        MessagePartDescription CreateMessagePart(XmlSchemaElement elem, Message msg, MessagePart msgPart)
        {
            var part = new MessagePartDescription(elem.QualifiedName.Name, elem.QualifiedName.Namespace);

            part.DataContractImporter = dc_importer;
            if (dc_importer.CanImport(schema_set_in_use, elem))
            {
                var typeQName = dc_importer.Import(schema_set_in_use, elem);
                part.CodeTypeReference = dc_importer.GetCodeTypeReference(elem.ElementSchemaType.QualifiedName, elem);
            }
            return(part);
        }
Example #9
0
        private static void addHeaderToOperations(System.Web.Services.Description.Message headerMessage, WsdlEndpointConversionContext context)
        {
            // Create a XmlQualifiedName based on the header message, this will be used for binding the header message and the SoapHeaderBinding
            XmlQualifiedName header = new XmlQualifiedName(headerMessage.Name, headerMessage.ServiceDescription.TargetNamespace);

            foreach (OperationBinding operation in context.WsdlBinding.Operations)
            {
                // Add the SoapHeaderBinding to the MessageBinding
                ExportMessageHeaderBinding(operation.Input, context, header, false);
                ExportMessageHeaderBinding(operation.Output, context, header, false);
            }
        }
Example #10
0
        private static System.Web.Services.Description.Message CreateHeaderMessage()
        {
            // Create Message
            System.Web.Services.Description.Message headerMessage = new System.Web.Services.Description.Message();

            // Set the name of the header message
            headerMessage.Name = VeriBranchMessageHeaderNames.SoapHeaderName;

            // Create the messagepart and add to the header message
            MessagePart part = new MessagePart();

            part.Name    = "Header";
            part.Element = new XmlQualifiedName(VeriBranchMessageHeaderNames.SoapHeaderName, VeriBranchMessageHeaderNames.SoapHeaderNamespace);
            headerMessage.Parts.Add(part);

            return(headerMessage);
        }
 public static void ExportHeaderToAllOpreations(Type headerType, WsdlExporter exporter, string headerMessageName, string headerPartName, WsdlHeaderOptionElement option)
 {
     if ((option != null) && ((option.ExportInputEnabled) || (option.ExportOutputEnabled)))
     {
         XmlQualifiedName xqn = ExportTypeToXsd(headerType, exporter);
         Wsdl.Message     msg = WsdlHelper.CreateSinglePartMessage(headerMessageName, headerPartName, xqn);
         foreach (Wsdl.ServiceDescription svc in exporter.GeneratedWsdlDocuments)
         {
             if (svc.Messages.Count > 0)
             {
                 svc.Messages.Add(msg);
             }
             WsdlHelper.AddHeaderToAllOperationsInService(svc, msg, null,
                                                          option.ExportInputEnabled,
                                                          option.ExportInputRequired,
                                                          option.ExportOutputEnabled,
                                                          option.ExportOutputRequired);
         }
     }
 }
Example #12
0
 void resolveMessage(Message msg, MessageBodyDescription body, List <MessagePartDescription> parts)
 {
     foreach (MessagePart part in msg.Parts)
     {
         if (part.Name == "parameters")
         {
             if (!part.Element.IsEmpty)
             {
                 body.WrapperName = part.Element.Name;
                 ImportPartsBySchemaElement(part.Element, parts, msg, part);
             }
             else
             {
                 body.WrapperName = part.Type.Name;
                 ResolveType(part.Type, parts, body.WrapperNamespace);
             }
         }
         //FIXME: non-parameters?
     }
 }
        private static void ConstructMessages(InterfaceContract serviceInterfaceContract, System.Web.Services.Description.ServiceDescription desc)
        {
            MessageCollection msgs = desc.Messages;

            foreach (Operation op in serviceInterfaceContract.Operations)
            {
                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);
                }
            }
        }
Example #14
0
        public static void ExportEndpoint(WsdlExporter exporter, WsdlEndpointConversionContext context)
        {
            // Read the schema of the custom header message
            var assembly = Assembly.GetAssembly(typeof(VeriBranch.Common.MessageDefinitions.AccessRestriction));

            XmlSchema customSoapHeaderSchema = XmlSchema.Read(assembly.GetManifestResourceStream(MessageHeaderXSD),
                                                              new ValidationEventHandler(SoapHeaderWsdlExport.ValidationCallBack));

            // Create the HeaderMessage to add to wsdl:message AND to refer to from wsdl:operation
            System.Web.Services.Description.Message headerMessage = CreateHeaderMessage();

            foreach (System.Web.Services.Description.ServiceDescription wsdl in exporter.GeneratedWsdlDocuments)
            {
                // Add the schema of the CustomSoapHeader to the types AND add the namespace to the list of namespaces
                wsdl.Types.Schemas.Add(customSoapHeaderSchema);
                wsdl.Namespaces.Add("sh", VeriBranchMessageHeaderNames.SoapHeaderNamespace);

                // The actual adding of the message to the list of messages
                wsdl.Messages.Add(headerMessage);
            }

            addHeaderToOperations(headerMessage, context);
        }
Example #15
0
        private XmlQualifiedName CreateMessage(ServiceDescription wsdl1, string name, XmlQualifiedName element, string partName)
        {
            var res = new XmlQualifiedName(name, wsdl1.TargetNamespace);

            if (HasMessage(wsdl1.Messages, name))
            {
                return(res);
            }

            var msg = new Message();

            wsdl1.Messages.Add(msg);

            msg.Name = name;

            var p = new MessagePart();

            p.Name    = partName;
            p.Element = element;
            msg.Parts.Add(p);

            return(res);
        }
Example #16
0
 void resolveMessage(Message msg, MessageBodyDescription body, List <MessagePartDescription> parts)
 {
     foreach (MessagePart part in msg.Parts)
     {
         if (part.Name == "parameters")
         {
             if (!part.Element.IsEmpty)
             {
                 body.WrapperName = part.Element.Name;
                 ImportPartsBySchemaElement(part.Element, parts, msg, part);
             }
             else
             {
                 body.WrapperName = part.Type.Name;
                 ResolveType(part.Type, parts, body.WrapperNamespace);
             }
         }
         else
         {
             throw new InvalidOperationException("Only 'parameters' element in message part is supported");                      // this should have been rejected by CanImportOperation().
         }
     }
 }
        void CreateMessage(bool rpc, SoapBindingUse use, SoapParameterStyle paramStyle, Message message, MessageBinding messageBinding, XmlMembersMapping members) {
            bool wrapped = paramStyle != SoapParameterStyle.Bare;

            if (use == SoapBindingUse.Encoded)
                CreateEncodedMessage(message, messageBinding, members, wrapped && !rpc);
            else
                CreateLiteralMessage(message, messageBinding, members, wrapped && !rpc, rpc);
        }
		XmlMembersMapping ImportInMembersMapping (Message msg)
		{
			SoapSchemaMember[] mems = new SoapSchemaMember [msg.Parts.Count];
			for (int n=0; n<mems.Length; n++)
			{
				SoapSchemaMember mem = new SoapSchemaMember();
				mem.MemberName = msg.Parts[n].Name;
				mem.MemberType = msg.Parts[n].Type;
				mems[n] = mem;
			}
			return soapImporter.ImportMembersMapping (Operation.Name, "", mems);
		}
Example #19
0
        protected override void ImportPartsBySchemaElement(QName qname, List <MessagePartDescription> parts, Message msg, MessagePart msgPart)
        {
            if (schema_set_cache != schema_set_in_use)
            {
                schema_set_cache = schema_set_in_use;
                var xss = new XmlSchemas();
                foreach (XmlSchema xs in schema_set_cache.Schemas())
                {
                    xss.Add(xs);
                }
                schema_importer = new XmlSchemaImporter(xss);
                if (ccu.Namespaces.Count == 0)
                {
                    ccu.Namespaces.Add(new CodeNamespace());
                }
                var cns = ccu.Namespaces [0];
                code_exporter = new XmlCodeExporter(cns, ccu);
            }

            var part = new MessagePartDescription(qname.Name, qname.Namespace);

            part.XmlSerializationImporter = this;
            var mbrNS = msg.ServiceDescription.TargetNamespace;
            var xmm   = schema_importer.ImportMembersMapping(qname);

            code_exporter.ExportMembersMapping(xmm);
            // FIXME: use of ElementName is a hack!
            part.CodeTypeReference = new CodeTypeReference(xmm.ElementName);
            parts.Add(part);
        }
Example #20
0
        protected override void ImportPartsBySchemaElement(QName qname, List <MessagePartDescription> parts, Message msg, MessagePart part)
        {
            XmlSchemaElement element = (XmlSchemaElement)schema_set_in_use.GlobalElements [qname];

            if (element == null)
            {
                throw new InvalidOperationException("Could not resolve : " + qname.ToString());                   // this should have been rejected by CanImportOperation().
            }
            var ct = element.ElementSchemaType as XmlSchemaComplexType;

            if (ct == null)             // simple type
            {
                parts.Add(CreateMessagePart(element, msg, part));
            }
            else             // complex type
            {
                foreach (var elem in GetElementsInParticle(ct.ContentTypeParticle))
                {
                    parts.Add(CreateMessagePart(elem, msg, part));
                }
            }
        }
		public override void Check (ConformanceCheckContext ctx, Message value)
		{
			// TODO: R2113
		}
Example #22
0
		void ImportMessage (XmlMembersMapping members, Message msg)
		{
			SoapMethodStubInfo method = (SoapMethodStubInfo) MethodStubInfo;
			bool needsEnclosingElement = (method.ParameterStyle == SoapParameterStyle.Wrapped && 
											method.SoapBindingStyle == SoapBindingStyle.Document);

			if (needsEnclosingElement)
			{
				MessagePart part = new MessagePart ();
				part.Name = "parameters";
				XmlQualifiedName qname = new XmlQualifiedName (members.ElementName, members.Namespace);
				if (method.Use == SoapBindingUse.Literal) part.Element = qname;
				else part.Type = qname;
				msg.Parts.Add (part);
			}
			else
			{
				for (int n=0; n<members.Count; n++)
				{
					MessagePart part = new MessagePart ();
					part.Name = members[n].MemberName;
					
					if (method.Use == SoapBindingUse.Literal) {
						if (members[n].Any)
							part.Type = new XmlQualifiedName ("any", members[n].Namespace);
						else
							part.Element = new XmlQualifiedName (members[n].ElementName, members[n].Namespace);
					}
					else {
						string namesp = members[n].TypeNamespace;
						if (namesp == "") namesp = members[n].Namespace;
						part.Name = members[n].ElementName;
						part.Type = new XmlQualifiedName (members[n].TypeName, namesp);
					}
					msg.Parts.Add (part);
				}
			}
			
			
			if (method.Use == SoapBindingUse.Literal)
				SchemaExporter.ExportMembersMapping (members);
			else
				SoapSchemaExporter.ExportMembersMapping (members, needsEnclosingElement);
		}
		void resolveMessage (Message msg, MessageBodyDescription body, List<MessagePartDescription> parts)
		{
			foreach (MessagePart part in msg.Parts) {
				if (part.Name == "parameters") {
					if (!part.Element.IsEmpty) {
						body.WrapperName = part.Element.Name;
						ImportPartsBySchemaElement (part.Element, parts, body.WrapperNamespace);
					} else {
						body.WrapperName = part.Type.Name;
						resolveType (part.Type, parts, body.WrapperNamespace);
					}
				}
				//FIXME: non-parameters?
			}
		}
        void MoveToOperation(Operation operation) {
            this.operation = operation;

            operationBinding = null;
            foreach (OperationBinding b in binding.Operations) {
                if (operation.IsBoundBy(b)) {
                    if (operationBinding != null) throw OperationSyntaxException(Res.GetString(Res.DuplicateInputOutputNames0));
                    operationBinding = b;
                }
            }
            if (operationBinding == null) {
                throw OperationSyntaxException(Res.GetString(Res.MissingBinding0));
            }
            //NOTE: The following two excepions would never happen since IsBoundBy checks these conditions already.
            if (operation.Messages.Input != null && operationBinding.Input == null) {
                throw OperationSyntaxException(Res.GetString(Res.MissingInputBinding0));
            }
            if (operation.Messages.Output != null && operationBinding.Output == null) {
                throw OperationSyntaxException(Res.GetString(Res.MissingOutputBinding0));
            }

            this.inputMessage = operation.Messages.Input == null ? null : ServiceDescriptions.GetMessage(operation.Messages.Input.Message);
            this.outputMessage = operation.Messages.Output == null ? null : ServiceDescriptions.GetMessage(operation.Messages.Output.Message);
        }
		protected override void ImportPartsBySchemaElement (QName qname, List<MessagePartDescription> parts, Message msg, MessagePart msgPart)
		{
			if (schema_set_cache != schema_set_in_use) {
				schema_set_cache = schema_set_in_use;
				var xss = new XmlSchemas ();
				foreach (XmlSchema xs in schema_set_cache.Schemas ())
					xss.Add (xs);
				schema_importer = new XmlSchemaImporter (xss);
				if (ccu.Namespaces.Count == 0)
					ccu.Namespaces.Add (new CodeNamespace ());
				var cns = ccu.Namespaces [0];
				code_exporter = new XmlCodeExporter (cns, ccu);
			}

			var part = new MessagePartDescription (qname.Name, qname.Namespace);
			part.XmlSerializationImporter = this;
			var mbrNS = msg.ServiceDescription.TargetNamespace;
			var xmm = schema_importer.ImportMembersMapping (qname);
			code_exporter.ExportMembersMapping (xmm);
			// FIXME: use of ElementName is a hack!
			part.CodeTypeReference = new CodeTypeReference (xmm.ElementName);
			parts.Add (part);
		}
		MessagePartDescription CreateMessagePart (XmlSchemaElement elem, Message msg, MessagePart msgPart)
		{
			var part = new MessagePartDescription (elem.QualifiedName.Name, elem.QualifiedName.Namespace);
			part.DataContractImporter = dc_importer;
			if (dc_importer.CanImport (schema_set_in_use, elem)) {
				var typeQName = dc_importer.Import (schema_set_in_use, elem);
				part.CodeTypeReference = dc_importer.GetCodeTypeReference (elem.ElementSchemaType.QualifiedName, elem);
			}
			return part;
		}
		protected override void ImportPartsBySchemaElement (QName qname, List<MessagePartDescription> parts, Message msg, MessagePart part)
		{
			XmlSchemaElement element = (XmlSchemaElement) schema_set_in_use.GlobalElements [qname];
			if (element == null)
				throw new InvalidOperationException ("Could not resolve : " + qname.ToString ()); // this should have been rejected by CanImportOperation().

			var ct = element.ElementSchemaType as XmlSchemaComplexType;
			if (ct == null) // simple type
				parts.Add (CreateMessagePart (element, msg, part));
			else // complex type
				foreach (var elem in GetElementsInParticle (ct.ContentTypeParticle))
					parts.Add (CreateMessagePart (elem, msg, part));
		}
        void CreateHeaderMessages(string methodName, SoapBindingUse use, XmlMembersMapping inHeaderMappings, XmlMembersMapping outHeaderMappings, SoapReflectedHeader[] headers, bool rpc) {
            // 
            if (use == SoapBindingUse.Encoded) {
                SoapExporter.ExportMembersMapping(inHeaderMappings, false);
                if (outHeaderMappings != null)
                    SoapExporter.ExportMembersMapping(outHeaderMappings, false);
            }
            else {
                SchemaExporter.ExportMembersMapping(inHeaderMappings);
                if (outHeaderMappings != null)
                    SchemaExporter.ExportMembersMapping(outHeaderMappings);
            }

            CodeIdentifiers identifiers = new CodeIdentifiers();
            int inCount = 0, outCount = 0;
            for (int i = 0; i < headers.Length; i++) {
                SoapReflectedHeader soapHeader = headers[i];
                if (!soapHeader.custom) continue;
                
                XmlMemberMapping member;
                if ((soapHeader.direction & SoapHeaderDirection.In) != 0) {
                    member = inHeaderMappings[inCount++];
                    if (soapHeader.direction != SoapHeaderDirection.In)
                        outCount++;
                }
                else {
                    member = outHeaderMappings[outCount++];
                }

                MessagePart part = new MessagePart();
                part.Name = member.XsdElementName;
                if (use == SoapBindingUse.Encoded)
                    part.Type = new XmlQualifiedName(member.TypeName, member.TypeNamespace);
                else
                    part.Element = new XmlQualifiedName(member.XsdElementName, member.Namespace);
                Message message = new Message();
                message.Name = identifiers.AddUnique(methodName + part.Name, message);
                message.Parts.Add(part);
                HeaderMessages.Add(message);

                ServiceDescriptionFormatExtension soapHeaderBinding = CreateSoapHeaderBinding(new XmlQualifiedName(message.Name, Binding.ServiceDescription.TargetNamespace), part.Name, rpc ? member.Namespace : null, use);
                
                if ((soapHeader.direction & SoapHeaderDirection.In) != 0)
                    OperationBinding.Input.Extensions.Add(soapHeaderBinding);
                if ((soapHeader.direction & SoapHeaderDirection.Out) != 0)
                    OperationBinding.Output.Extensions.Add(soapHeaderBinding);

                if ((soapHeader.direction & SoapHeaderDirection.Fault) != 0) {
                    if (soapMethod.IsClaimsConformance) {
                        throw new InvalidOperationException(Res.GetString(Res.BPConformanceHeaderFault, soapMethod.methodInfo.ToString(), soapMethod.methodInfo.DeclaringType.FullName, "Direction", typeof(SoapHeaderDirection).Name, SoapHeaderDirection.Fault.ToString())); 
                    }
                    OperationBinding.Output.Extensions.Add(soapHeaderBinding);
                }
            }
        }
Example #29
0
        public List<WSParameter> GetParameters(Message msg)
        {
            List<WSParameter> parameters = new List<WSParameter>();
            foreach (MessagePart msgpart in msg.Parts)
            {

                XmlQualifiedName typName = msgpart.Element;

                XmlSchemaElement lookup = (XmlSchemaElement)schemas.Find(typName, typeof(XmlSchemaElement));

                if (lookup != null)
                {
                    XmlSchemaComplexType tt = (XmlSchemaComplexType)lookup.SchemaType;

                    XmlSchemaSequence sequence = (XmlSchemaSequence)tt.Particle;
                    //int i = 0;
                    if (sequence != null)
                    {
                        foreach (XmlSchemaElement childElement in sequence.Items)
                        {
                            WSParameter param = new WSParameter();
                            param.Name = childElement.Name;
                            param.TypeName = childElement.SchemaTypeName.Name;
                            param.MinOccurs = childElement.MinOccurs;
                            param.MaxOccurs = childElement.MaxOccurs.ToString();

                            parameters.Add(param);
                            //ParameterAndType.Add(childElement.Name, childElement.SchemaTypeName.Name);
                            //Console.WriteLine("Element: {0} ,{1}", childElement.Name,childElement.SchemaTypeName.Name);
                        }
                    }
                }
            }

            return parameters;
        }
		protected abstract void ImportPartsBySchemaElement (QName qname, List<MessagePartDescription> parts, Message msg, MessagePart part);
		List<IWsdlExportExtension> ExportContractInternal (ContractDescription contract)
		{
			QName qname = new QName (contract.Name, contract.Namespace);
			if (ExportedContracts.ContainsKey (qname))
				throw new ArgumentException (String.Format (
					"A ContractDescription with Namespace : {0} and Name : {1} has already been exported.", 
					contract.Namespace, contract.Name));

			WSServiceDescription sd = GetServiceDescription (contract.Namespace);

			List<IWsdlExportExtension> extensions = new List<IWsdlExportExtension> ();
			foreach (IWsdlExportExtension extn in contract.Behaviors.FindAll<IWsdlExportExtension> ())
				extensions.Add (extn);

			XmlDocument xdoc = new XmlDocument ();

			PortType ws_port = new PortType ();
			ws_port.Name = contract.Name;

			foreach (OperationDescription sm_op in contract.Operations) {
				Operation ws_op = new Operation ();
				ws_op.Name = sm_op.Name;

				foreach (MessageDescription sm_md in sm_op.Messages) {
					//OperationMessage
					OperationMessage ws_opmsg;
					WSMessage ws_msg = new WSMessage ();
					MessagePart ws_msgpart;
					if (sm_md.Direction == MessageDirection.Input) {
						ws_opmsg = new OperationInput ();
						ws_msg.Name = String.Concat (ws_port.Name, "_", ws_op.Name, "_", "InputMessage");
						ws_msgpart = ExportMessageBodyDescription (sm_md.Body, ws_op.Name, sd.TargetNamespace);
					} else {
						ws_opmsg = new OperationOutput ();
						ws_msg.Name = String.Concat (ws_port.Name, "_", ws_op.Name, "_", "OutputMessage");
						ws_msgpart = ExportMessageBodyDescription (sm_md.Body, ws_op.Name + "Response", sd.TargetNamespace);
					}
					ws_msg.Parts.Add (ws_msgpart);	

					/* FIXME: Faults */

					//Action
					XmlAttribute attr = xdoc.CreateAttribute ("wsaw", "Action", "http://www.w3.org/2006/05/addressing/wsdl");
					attr.Value = sm_md.Action;
					ws_opmsg.ExtensibleAttributes = new XmlAttribute [] { attr };
					
					//FIXME: Set .Input & .Output

					ws_opmsg.Message = new QName (ws_msg.Name, sd.TargetNamespace);
					ws_op.Messages.Add (ws_opmsg);
					sd.Messages.Add (ws_msg);
				}

				ws_port.Operations.Add (ws_op);

				foreach (IWsdlExportExtension extn in sm_op.Behaviors.FindAll<IWsdlExportExtension> ())
					extensions.Add (extn);
			}

			//Add Imports for <types
			XmlSchema xs_import = new XmlSchema ();
			xs_import.TargetNamespace = String.Concat (
					contract.Namespace, 
					contract.Namespace.EndsWith ("/") ? "" : "/",
					"Imports");
			foreach (XmlSchema schema in GeneratedXmlSchemas.Schemas ()) {
				XmlSchemaImport imp = new XmlSchemaImport ();
				imp.Namespace = schema.TargetNamespace;
				xs_import.Includes.Add (imp);
			}
			sd.Types.Schemas.Add (xs_import);

			sd.PortTypes.Add (ws_port);
			ExportedContracts [qname] = contract;

			WsdlContractConversionContext context = new WsdlContractConversionContext (contract, ws_port);
			foreach (IWsdlExportExtension extn in extensions)
				extn.ExportContract (this, context);

			return extensions;
		}
Example #32
0
		void ImportMessageParts ()
		{
			SoapMethodStubInfo method = (SoapMethodStubInfo) MethodStubInfo;
			ImportMessage (method.InputMembersMapping, InputMessage);
			ImportMessage (method.OutputMembersMapping, OutputMessage);
				

			foreach (SoapHeaderMapping hf in method.Headers)
			{
				if (hf.Custom) continue;
				
				Message msg = new Message ();
				msg.Name = Operation.Name + hf.HeaderType.Name;
				MessagePart part = new MessagePart ();
				part.Name = hf.HeaderType.Name;
				msg.Parts.Add (part);
				ServiceDescription.Messages.Add (msg);

				if (method.Use == SoapBindingUse.Literal)
				{
					// MS.NET reflects header classes in a weird way. The root element
					// name is the CLR class name unless it is specified in an XmlRootAttribute.
					// The usual is to use the xml type name by default, but not in this case.
				
					XmlRootAttribute root;
					XmlAttributes ats = new XmlAttributes (hf.HeaderType);
					if (ats.XmlRoot != null) root = ats.XmlRoot;
					else root = new XmlRootAttribute (hf.HeaderType.Name);
					
					if (root.Namespace == null) root.Namespace = TypeInfo.LogicalType.GetWebServiceLiteralNamespace (ServiceDescription.TargetNamespace);
					if (root.ElementName == null) root.ElementName = hf.HeaderType.Name;
					
					XmlTypeMapping mapping = ReflectionImporter.ImportTypeMapping (hf.HeaderType, root);
					part.Element = new XmlQualifiedName (mapping.ElementName, mapping.Namespace);
					SchemaExporter.ExportTypeMapping (mapping);
				}
				else
				{
					XmlTypeMapping mapping = SoapReflectionImporter.ImportTypeMapping (hf.HeaderType, TypeInfo.LogicalType.GetWebServiceEncodedNamespace (ServiceDescription.TargetNamespace));
					part.Type = new XmlQualifiedName (mapping.ElementName, mapping.Namespace);
					SoapSchemaExporter.ExportTypeMapping (mapping);
				}
			}
		}
Example #33
0
        /// <summary>
        /// Creates an <see cref="InterfaceContract"/> object by loading the contents in a specified
        /// WSDL file.
        /// </summary>
        /// <param name="wsdlFileName">Path of the WSDL file to load the information from.</param>
        /// <returns>An instance of <see cref="InterfaceContract"/> with the information loaded from the WSDL file.</returns>
        /// <remarks>
        /// This method first loads the content of the WSDL file to an instance of
        /// <see cref="System.Web.Services.Description.ServiceDescription"/> class. Then it creates an
        /// instance of <see cref="InterfaceContract"/> class by loading the data from that.
        /// This method throws <see cref="WsdlLoadException"/> in case of a failure to load the WSDL file.
        /// </remarks>
        public static InterfaceContract GetInterfaceContract(string wsdlFileName)
        {
            // Try to load the service description from the specified file.
            LoadWsdl(wsdlFileName);

            // Validate the WSDL before proceeding.
            CheckIfWsdlIsUsableForRoundtripping();

            // Start building the simplified InterfaceContract object from the
            // .Net Fx ServiceDescription we created.
            InterfaceContract simpleContract = new InterfaceContract();

            // Initialize the basic meta data.
            simpleContract.ServiceName          = srvDesc.Name;
            simpleContract.ServiceNamespace     = srvDesc.TargetNamespace;
            simpleContract.ServiceDocumentation = srvDesc.Documentation;
            // Try to get the service namespace from the service description.

            // If it was not found in the service description. Then try to get it from the
            // service. If it is not found their either, then try to get it from binding.
            if (simpleContract.ServiceName == null || simpleContract.ServiceName == "")
            {
                if (srvDesc.Services.Count > 0 && srvDesc.Services[0].Name != null &&
                    srvDesc.Services[0].Name != "")
                {
                    simpleContract.ServiceName = srvDesc.Services[0].Name;
                }
                else
                {
                    simpleContract.ServiceName = srvDesc.Bindings[0].Name;
                }
            }

            // Set the http binding property.
            simpleContract.IsHttpBinding = isHttpBinding;

            // Initialize the imports.
            foreach (XmlSchema typeSchema in srvDesc.Types.Schemas)
            {
                foreach (XmlSchemaObject schemaObject in typeSchema.Includes)
                {
                    XmlSchemaImport import = schemaObject as XmlSchemaImport;

                    if (import != null)
                    {
                        SchemaImport simpleImport = new SchemaImport();
                        simpleImport.SchemaNamespace = import.Namespace;
                        simpleImport.SchemaLocation  = import.SchemaLocation;
                        simpleContract.Imports.Add(simpleImport);
                    }
                }
            }

            // Initialize the types embedded to the WSDL.
            simpleContract.SetTypes(GetSchemaElements(srvDesc.Types.Schemas, srvDesc.TargetNamespace));

            // Initialize the operations and in/out messages.
            PortType ptype = srvDesc.PortTypes[0];

            if (ptype != null)
            {
                foreach (FxOperation op in ptype.Operations)
                {
                    // Create the Operation.
                    Operation simpleOp = new Operation();
                    simpleOp.Name          = op.Name;
                    simpleOp.Documentation = op.Documentation;

                    if (op.Messages.Input != null)
                    {
                        FxMessage inMessage = srvDesc.Messages[op.Messages.Input.Message.Name];

                        if (inMessage == null)
                        {
                            // WSDL modified.
                            throw new WsdlModifiedException("Could not find the message");
                        }

                        MessagePart part = inMessage.Parts[0];
                        if (part != null)
                        {
                            // Create the input message.
                            Message simpleInMessage = new Message();
                            simpleInMessage.Name = inMessage.Name;
                            simpleInMessage.Element.ElementName      = part.Element.Name;
                            simpleInMessage.Element.ElementNamespace = part.Element.Namespace;
                            simpleInMessage.Documentation            = inMessage.Documentation;

                            simpleOp.MessagesCollection.Add(simpleInMessage);

                            simpleOp.Input = simpleInMessage;
                        }
                        else
                        {
                            // WSDL is modified.
                            throw new WsdlModifiedException("Could not find the message part");
                        }
                    }

                    if (op.Messages.Output != null)
                    {
                        FxMessage outMessage = srvDesc.Messages[op.Messages.Output.Message.Name];

                        if (outMessage == null)
                        {
                            // WSDL is modified.
                            throw new WsdlModifiedException("Could not find the message");
                        }

                        MessagePart part = outMessage.Parts[0];
                        if (part != null)
                        {
                            // Create the output message.
                            Message simpleOutMessage = new Message();
                            simpleOutMessage.Name = outMessage.Name;
                            simpleOutMessage.Element.ElementName      = part.Element.Name;
                            simpleOutMessage.Element.ElementNamespace = part.Element.Namespace;
                            simpleOutMessage.Documentation            = outMessage.Documentation;

                            simpleOp.MessagesCollection.Add(simpleOutMessage);

                            simpleOp.Output = simpleOutMessage;
                        }
                        else
                        {
                            // WSDL is modified.
                            throw new WsdlModifiedException("Could not find the message part");
                        }

                        // Set the message direction.
                        simpleOp.Mep = Mep.RequestResponse;
                    }
                    else
                    {
                        simpleOp.Mep = Mep.OneWay;
                    }

                    // Finally add the Operation to Operations collection.
                    simpleContract.Operations.Add(simpleOp);
                }
            }
            else
            {
                // WSDL is modified.
                throw new WsdlModifiedException("Could not find the portType");
            }

            // Initialize the message headers and header messages.
            System.Web.Services.Description.Binding binding1 = srvDesc.Bindings[0];
            if (binding1 != null)
            {
                // Find the corresponding Operation in the InterfaceContract, for each OperationBinding
                // in the binding1.Operations collection.
                foreach (OperationBinding opBinding in binding1.Operations)
                {
                    foreach (Operation simpleOp in simpleContract.Operations)
                    {
                        if (simpleOp.Name == opBinding.Name)
                        {
                            if (opBinding.Input != null)
                            {
                                // Enumerate the message headers for the input message.
                                foreach (ServiceDescriptionFormatExtension extension in opBinding.Input.Extensions)
                                {
                                    SoapHeaderBinding inHeader = extension as SoapHeaderBinding;
                                    if (inHeader != null)
                                    {
                                        // Create the in header and add it to the headers collection.
                                        MessageHeader simpleInHeader  = new MessageHeader();
                                        FxMessage     inHeaderMessage = srvDesc.Messages[inHeader.Message.Name];

                                        if (inHeaderMessage == null)
                                        {
                                            // WSDL modified.
                                            throw new WsdlModifiedException("Could not find the message");
                                        }

                                        simpleInHeader.Name    = inHeaderMessage.Name;
                                        simpleInHeader.Message = inHeaderMessage.Name;
                                        simpleOp.MessagesCollection[0].HeadersCollection.Add(simpleInHeader);

                                        // Create the in header message and put it to the Operation's messeages collection.
                                        MessagePart part = inHeaderMessage.Parts[0];
                                        if (part != null)
                                        {
                                            Message simpleInHeaderMessage = new Message();
                                            simpleInHeaderMessage.Name = inHeaderMessage.Name;
                                            simpleInHeaderMessage.Element.ElementName      = part.Element.Name;
                                            simpleInHeaderMessage.Element.ElementNamespace = part.Element.Namespace;

                                            simpleOp.MessagesCollection.Add(simpleInHeaderMessage);
                                        }
                                        else
                                        {
                                            // WSDL is modified.
                                            throw new WsdlModifiedException("Could not find the message part");
                                        }
                                    }
                                }
                            }
                            else
                            {
                                // WSDL modified.
                                throw new WsdlModifiedException("Could not find the operation binding");
                            }

                            if (simpleOp.Mep == Mep.RequestResponse && opBinding.Output != null)
                            {
                                // Enumerate the message headers for the output message.
                                foreach (ServiceDescriptionFormatExtension extension in opBinding.Output.Extensions)
                                {
                                    SoapHeaderBinding outHeader = extension as SoapHeaderBinding;
                                    if (outHeader != null)
                                    {
                                        // Create the in header and add it to the headers collection.
                                        MessageHeader simpleOutHeader  = new MessageHeader();
                                        FxMessage     outHeaderMessage = srvDesc.Messages[outHeader.Message.Name];

                                        if (outHeaderMessage == null)
                                        {
                                            // WSDL is modified.
                                            throw new WsdlModifiedException("Could not find the message");
                                        }

                                        simpleOutHeader.Name    = outHeaderMessage.Name;
                                        simpleOutHeader.Message = outHeaderMessage.Name;
                                        simpleOp.MessagesCollection[1].HeadersCollection.Add(simpleOutHeader);

                                        // Create the out header message and put it to the Operation's messeages collection.
                                        MessagePart part = outHeaderMessage.Parts[0];
                                        if (part != null)
                                        {
                                            Message simpleOutHeaderMessage = new Message();
                                            simpleOutHeaderMessage.Name = outHeaderMessage.Name;
                                            simpleOutHeaderMessage.Element.ElementName      = part.Element.Name;
                                            simpleOutHeaderMessage.Element.ElementNamespace = part.Element.Namespace;

                                            simpleOp.MessagesCollection.Add(simpleOutHeaderMessage);
                                        }
                                        else
                                        {
                                            // WSDL is modified.
                                            throw new WsdlModifiedException("Could not find the message part");
                                        }
                                    }
                                }
                            }
                            else if (simpleOp.Mep == Mep.RequestResponse)
                            {
                                // WSDL modified.
                                throw new WsdlModifiedException("Could not find the operation binding");
                            }
                        }
                    }
                }
            }

            // Check for the "Generate service tags" option.
            if (srvDesc.Services.Count == 1)
            {
                simpleContract.NeedsServiceElement = true;
            }

            // Turn on the SOAP 1.2 binding if available.
            foreach (System.Web.Services.Description.Binding binding in srvDesc.Bindings)
            {
                if (binding.Extensions.Find(typeof(Soap12Binding)) != null)
                {
                    simpleContract.Bindings |= InterfaceContract.SoapBindings.Soap12;
                }
            }

            return(simpleContract);
        }
Example #34
0
        void DoImportContract()
        {
            PortType            port_type = context.WsdlPortType;
            ContractDescription contract = context.Contract;
            int i, j;
            List <MessagePartDescription> parts = new List <MessagePartDescription> ();

            i = 0;
            foreach (Operation op in port_type.Operations)
            {
                OperationDescription opdescr = contract.Operations [i];
                if (IsOperationImported(port_type, op))
                {
                    continue;
                }
                if (!CanImportOperation(port_type, op))
                {
                    continue;
                }

                j = 0;
                foreach (OperationMessage opmsg in op.Messages)
                {
                    //SM.MessageDescription
                    MessageDescription msgdescr = opdescr.Messages [j];

                    //OpMsg's corresponding WSMessage
                    Message msg = port_type.ServiceDescription.Messages [opmsg.Message.Name];

                    msgdescr.Body.WrapperNamespace = port_type.ServiceDescription.TargetNamespace;

                    if (opmsg is OperationOutput)
                    {
                        //ReturnValue
                        msg = port_type.ServiceDescription.Messages [opmsg.Message.Name];

                        resolveMessage(msg, msgdescr.Body, parts);
                        if (parts.Count > 0)
                        {
                            msgdescr.Body.ReturnValue = parts [0];
                            parts.Clear();
                        }
                        continue;
                    }

                    /* OperationInput */

                    /* Parts, MessagePartDescription */
                    resolveMessage(msg, msgdescr.Body, parts);
                    foreach (MessagePartDescription p in parts)
                    {
                        msgdescr.Body.Parts.Add(p);
                    }
                    parts.Clear();

                    j++;
                }

                OnOperationImported(opdescr);


                i++;
            }
        }
        protected bool CreateHeaderMessage(MessageDescription message, out WsdlNS.Message wsdlMessage)
        {
            wsdlMessage = null;

            if (ExportedMessages.WsdlHeaderMessages.ContainsKey(new MessageDescriptionDictionaryKey(contractContext.Contract, message)))
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.GetString(SR.MultipleCallsToExportContractWithSameContract)));

            TypedMessageKey typedMessageKey = null;
            if (message.IsTypedMessage)
            {
                typedMessageKey = new TypedMessageKey(message.MessageType, operation.DeclaringContract.Namespace, GetExtensionData());
                if (ExportedMessages.TypedHeaderMessages.TryGetValue(typedMessageKey, out wsdlMessage))
                {
                    this.ExportedMessages.WsdlHeaderMessages.Add(new MessageDescriptionDictionaryKey(contractContext.Contract, message), wsdlMessage);
                    return false;
                }
            }

            string messageName = GetHeaderMessageName(message);
            wsdlMessage = new WsdlNS.Message();
            wsdlMessage.Name = messageName;
            contractContext.WsdlPortType.ServiceDescription.Messages.Add(wsdlMessage);
            if (message.IsTypedMessage)
                ExportedMessages.TypedHeaderMessages.Add(typedMessageKey, wsdlMessage);

            this.ExportedMessages.WsdlHeaderMessages.Add(new MessageDescriptionDictionaryKey(contractContext.Contract, message), wsdlMessage);

            return true;
        }
Example #36
0
 protected abstract void ImportPartsBySchemaElement(QName qname, List <MessagePartDescription> parts, Message msg, MessagePart part);
Example #37
0
		internal void SetParent (Message message)
		{
			this.message = message; 
		}
Example #38
0
public TreeNode TranslateOperation(Port port, OperationBinding obin, Operation oper, string protocol)
{
	TreeNode tnOperation=new TreeNode (oper.Name, 13 , 13);
	SoapBindingStyle style=new SoapBindingStyle() ;
	SoapBindingUse inputUse=new SoapBindingUse() ;
	SoapBindingUse outputUse=new SoapBindingUse() ;

	string requestmsg=string.Empty;
	string responsemsg=string.Empty;
	TreeNode tnInput=new TreeNode ();
	TreeNode tnOutput=new TreeNode ();			
	TreeNode tnFault=new TreeNode ("Faults");								
	GetOperationFormat (obin, oper, out style,out inputUse,out outputUse, out requestmsg, out responsemsg,out tnInput, out tnOutput);
 
	string operDesc=string.Empty;
	operDesc +=oper.Documentation + "\n";
	operDesc +="Style: " + style.ToString() + "\n" ;
	tnOperation.Tag=operDesc;
	MessageCollection messages=_services[0].Messages;			
	if (oper.Messages.Input != null)
	{
	Message messageIn=messages[oper.Messages.Input.Message.Name] ;			if (messageIn != null )
	{					
	if (tnInput == null) tnInput=new TreeNode() ;			
	tnInput.Tag=requestmsg;	
	tnInput.ImageIndex=13;
	tnInput.SelectedImageIndex=13;
	if (oper.Messages.Input.Name != null && oper.Messages.Input.Name != string.Empty)
	{
		tnInput.Text="Input: " + oper.Messages.Input.Name ;
	}
	Else{
	tnInput.Text="Input: " + oper.Messages.Input.Message.Name ;
	if (tnInput != null) tnOperation.Nodes.Add  (tnInput );
	};
	};

	if (oper.Messages.Output != null)
	{
	Message messageOut=messages[oper.Messages.Output.Message.Name] ;
	if (messageOut != null )
	{				

	if (tnOutput == null) tnOutput=new TreeNode() ;	
	tnOutput.Tag=responsemsg;
	tnOutput.ImageIndex=13;
	tnOutput.SelectedImageIndex=13;

	if (oper.Messages.Output.Name != null &&     oper.Messages.Output.Name != string.Empty)
	{
	tnOutput.Text="Output: " + oper.Messages.Output.Name ;
	}
	else
	tnOutput.Text="Output: " + oper.Messages.Output.Message.Name ;
	if (tnOutput != null) tnOperation.Nodes.Add  (tnOutput );
	};

	};
		
	foreach (OperationFault faultOp in  oper.Faults)
	{				
	Message messageFault=messages[faultOp.Message.Name] ;
	if (messageFault != null )				
	{					

	TreeNode treeNode=new TreeNode() ;			

	tnFault.ImageIndex=14;
	tnFault.SelectedImageIndex=14;
	if (treeNode != null)
	tnFault.Nodes.Add (treeNode);
	};
 
	};

	if (tnFault.Nodes.Count > 0 ) tnOperation.Nodes.Add  (tnFault );

	return tnOperation;			
			
	}
Example #39
0
        protected override void ImportPartsBySchemaElement(QName qname, List <MessagePartDescription> parts, Message msg, MessagePart part)
        {
            XmlSchemaElement element = (XmlSchemaElement)schema_set_in_use.GlobalElements [qname];

            if (element == null)
            {
                //FIXME: What to do here?
                throw new Exception("Could not resolve : " + qname.ToString());
            }

            var ct = element.ElementSchemaType as XmlSchemaComplexType;

            if (ct == null)             // simple type
            {
                parts.Add(CreateMessagePart(element, msg, part));
            }
            else             // complex type
            {
                foreach (var elem in GetElementsInParticle(ct.ContentTypeParticle))
                {
                    parts.Add(CreateMessagePart(elem, msg, part));
                }
            }
        }
		XmlMembersMapping ImportMembersMapping (Message msg, SoapBodyBinding sbb, SoapBindingStyle style, bool output)
		{
			string elemName = Operation.Name;
			if (output) elemName += "Response";

			if (msg.Parts.Count == 1 && msg.Parts[0].Name == "parameters")
			{
				// Wrapped parameter style
				
				MessagePart part = msg.Parts[0];
				if (sbb.Use == SoapBindingUse.Encoded)
				{
					SoapSchemaMember ssm = new SoapSchemaMember ();
					ssm.MemberName = part.Name;
					ssm.MemberType = part.Type;
					return soapImporter.ImportMembersMapping (elemName, part.Type.Namespace, ssm);
				}
				else
					return xmlImporter.ImportMembersMapping (part.Element);
			}
			else
			{
				if (sbb.Use == SoapBindingUse.Encoded)
				{
					SoapSchemaMember[] mems = new SoapSchemaMember [msg.Parts.Count];
					for (int n=0; n<mems.Length; n++)
					{
						SoapSchemaMember mem = new SoapSchemaMember();
						mem.MemberName = msg.Parts[n].Name;
						mem.MemberType = msg.Parts[n].Type;
						mems[n] = mem;
					}
					
					// Rpc messages always have a wrapping element
					if (style == SoapBindingStyle.Rpc)
						return soapImporter.ImportMembersMapping (elemName, sbb.Namespace, mems, true);
					else
						return soapImporter.ImportMembersMapping ("", "", mems, false);
				}
				else
				{
					if (style == SoapBindingStyle.Rpc)
						throw new InvalidOperationException ("The combination of style=rpc with use=literal is not supported");
					
					if (msg.Parts.Count == 1 && msg.Parts[0].Type != XmlQualifiedName.Empty)
						return xmlImporter.ImportAnyType (msg.Parts[0].Type, null);
					else
					{
						XmlQualifiedName[] pnames = new XmlQualifiedName [msg.Parts.Count];
						for (int n=0; n<pnames.Length; n++)
							pnames[n] = msg.Parts[n].Element;
						return xmlImporter.ImportMembersMapping (pnames);
					}
				}
			}
		}
Example #41
0
        ContractExportMap ExportContractInternal(ContractDescription contract)
        {
            if (ExportedContracts.ContainsKey(contract))
            {
                return(ExportedContracts [contract]);
            }

            QName qname = new QName(contract.Name, contract.Namespace);

            if (ExportedContracts.Any(m => m.Value.QName == qname))
            {
                throw new ArgumentException(String.Format(
                                                "A ContractDescription with Namespace : {0} and Name : {1} has already been exported.",
                                                contract.Namespace, contract.Name));
            }

            WSServiceDescription sd = GetServiceDescription(contract.Namespace);

            List <IWsdlExportExtension> extensions = new List <IWsdlExportExtension> ();

            foreach (IWsdlExportExtension extn in contract.Behaviors.FindAll <IWsdlExportExtension> ())
            {
                extensions.Add(extn);
            }

            XmlDocument xdoc = new XmlDocument();

            PortType ws_port = new PortType();

            ws_port.Name = contract.Name;

            foreach (OperationDescription sm_op in contract.Operations)
            {
                Operation ws_op = new Operation();
                ws_op.Name = sm_op.Name;

                foreach (MessageDescription sm_md in sm_op.Messages)
                {
                    //OperationMessage
                    OperationMessage ws_opmsg;
                    WSMessage        ws_msg = new WSMessage();
                    MessagePart      ws_msgpart;
                    if (sm_md.Direction == MessageDirection.Input)
                    {
                        ws_opmsg    = new OperationInput();
                        ws_msg.Name = String.Concat(ws_port.Name, "_", ws_op.Name, "_", "InputMessage");
                        ws_msgpart  = ExportMessageBodyDescription(sm_md.Body, ws_op.Name, sd.TargetNamespace);
                    }
                    else
                    {
                        ws_opmsg    = new OperationOutput();
                        ws_msg.Name = String.Concat(ws_port.Name, "_", ws_op.Name, "_", "OutputMessage");
                        ws_msgpart  = ExportMessageBodyDescription(sm_md.Body, ws_op.Name + "Response", sd.TargetNamespace);
                    }
                    ws_msg.Parts.Add(ws_msgpart);

                    /* FIXME: Faults */

                    //Action
                    XmlAttribute attr = xdoc.CreateAttribute("wsaw", "Action", "http://www.w3.org/2006/05/addressing/wsdl");
                    attr.Value = sm_md.Action;
                    ws_opmsg.ExtensibleAttributes = new XmlAttribute [] { attr };

                    //FIXME: Set .Input & .Output

                    ws_opmsg.Message = new QName(ws_msg.Name, sd.TargetNamespace);
                    ws_op.Messages.Add(ws_opmsg);
                    sd.Messages.Add(ws_msg);
                }

                ws_port.Operations.Add(ws_op);

                foreach (IWsdlExportExtension extn in sm_op.Behaviors.FindAll <IWsdlExportExtension> ())
                {
                    extensions.Add(extn);
                }
            }

            //Add Imports for <types
            XmlSchema xs_import = new XmlSchema();

            xs_import.TargetNamespace = String.Concat(
                contract.Namespace,
                contract.Namespace.EndsWith("/") ? "" : "/",
                "Imports");
            foreach (XmlSchema schema in GeneratedXmlSchemas.Schemas())
            {
                XmlSchemaImport imp = new XmlSchemaImport();
                imp.Namespace = schema.TargetNamespace;
                xs_import.Includes.Add(imp);
            }
            sd.Types.Schemas.Add(xs_import);

            sd.PortTypes.Add(ws_port);
            var map = new ContractExportMap(qname, contract, extensions);

            ExportedContracts.Add(contract, map);

            WsdlContractConversionContext context = new WsdlContractConversionContext(contract, ws_port);

            foreach (IWsdlExportExtension extn in extensions)
            {
                extn.ExportContract(this, context);
            }

            return(map);
        }
		XmlTypeMapping ImportOutMembersMapping (Message msg)
		{
			if (msg.Parts.Count == 0) return null;
			
			if (msg.Parts[0].Name == "Body" && msg.Parts[0].Element == XmlQualifiedName.Empty)
				return xmlReflectionImporter.ImportTypeMapping (typeof(XmlNode));
			else {
				// This is a bit hacky. The issue is that types such as string[] are to be imported
				// as such, not as ArrayOfString class. ImportTypeMapping will return a
				// class if the type has not been imported as an array before, hence the
				// call to ImportMembersMapping.
				xmlImporter.ImportMembersMapping (new XmlQualifiedName[] {msg.Parts[0].Element});
				return xmlImporter.ImportTypeMapping (msg.Parts[0].Element);
			}
		}
Example #43
0
        /// <summary>
        /// Given a Wsdl Message part element returns the name of the request or response element
        /// wrapper. If a message part is not found return the name of the action with "Request" or "Response"
        /// appended.
        /// </summary>
        /// <param name="message">A Wsdl Message element.</param>
        /// <returns>The name of the Clr type used by the message element.</returns>
        internal static string GetMessageElementName(ServiceDescription svcDesc, Message message)
        {

            // If there is no message part(s) the message is void so return null
            if (message.Parts.Count == 0)
                return null;

            // If the message part contains a type reference
            XmlSchemaType type = null;
            string typeName = null;
            if (message.Parts[0].Element == null || message.Parts[0].Element.IsEmpty)
            {
                type = FindSchemaType(svcDesc, message.Parts[0].Type.Name, message.Parts[0].Type.Namespace);
                if (type.TypeCode == XmlTypeCode.None)
                    return message.Parts[0].Type.Name;
                typeName = message.Parts[0].Type.Name;
            }
            // If the message part contains an element reference
            else
            {
                XmlSchemaElement element = FindSchemaElement(svcDesc, message.Parts[0].Element.Name, message.Parts[0].Element.Namespace);
                if (element == null || element.SchemaTypeName == null || element.SchemaTypeName.Name == "")
                    return message.Parts[0].Element.Name;

                type = element.ElementSchemaType;
                typeName = message.Parts[0].Element.Name;
            }

            string clrTypeName = CodeGenUtils.GetClrType(typeName);
            clrTypeName = clrTypeName != null && clrTypeName.IndexOf("System.") == 0 ? clrTypeName.Substring(7) : clrTypeName;
            return clrTypeName == null ? typeName : clrTypeName;
        }
 void CreateLiteralMessage(Message message, MessageBinding messageBinding, XmlMembersMapping members, bool wrapped, bool rpc) {
     if (members.Count == 1 && members[0].Any && members[0].ElementName.Length == 0 && !wrapped) {
         string typeName = SchemaExporter.ExportAnyType(members[0].Namespace);
         MessagePart part = new MessagePart();
         part.Name = members[0].MemberName;
         part.Type = new XmlQualifiedName(typeName, members[0].Namespace);
         message.Parts.Add(part);
     }
     else {
         SchemaExporter.ExportMembersMapping(members, !rpc);
         if (wrapped) {
             MessagePart part = new MessagePart();
             part.Name = "parameters";
             part.Element = new XmlQualifiedName(members.XsdElementName, members.Namespace);
             message.Parts.Add(part);
         }
         else {
             for (int i = 0; i < members.Count; i++) {
                 XmlMemberMapping member = members[i];
                 MessagePart part = new MessagePart();
                 if (rpc) {
                     // Generate massage part with the type attribute
                     if (member.TypeName == null || member.TypeName.Length == 0) {
                         throw new InvalidOperationException(Res.GetString(Res.WsdlGenRpcLitAnonimousType, Method.DeclaringType.Name, Method.Name, member.MemberName));
                     }
                     part.Name = member.XsdElementName;
                     part.Type = new XmlQualifiedName(member.TypeName, member.TypeNamespace);
                 }
                 else {
                     part.Name = XmlConvert.EncodeLocalName(member.MemberName);
                     part.Element = new XmlQualifiedName(member.XsdElementName, member.Namespace);
                 }
                 message.Parts.Add(part);
             }
         }
     }
     messageBinding.Extensions.Add(CreateSoapBodyBinding(SoapBindingUse.Literal, rpc ? members.Namespace : null));
 }
Example #45
0
        /// <summary>
        /// Given a Wsdl Message part element returns the type refered to by the message part.
        /// </summary>
        /// <param name="message">A Wsdl Message element.</param>
        /// <returns>The name of the type used by the message element.</returns>
        internal static string GetMessageTypeName(ServiceDescription svcDesc, Message message)
        {

            // If there are no message part(s) the message is void so return null
            if (message.Parts.Count == 0)
                return null;

            // If the message contains a type reference instead of an element reference find the schema type
            XmlSchemaType type = null;
            string typeName = null;
            string elementName = null;
            if (message.Parts[0].Element == null || message.Parts[0].Element.IsEmpty)
            {
                type = FindSchemaType(svcDesc, message.Parts[0].Type.Name, message.Parts[0].Type.Namespace);
                if (type == null || type.TypeCode == XmlTypeCode.None)
                    return message.Parts[0].Type.Name;
                typeName = message.Parts[0].Type.Name;
            }
            else
            {
                XmlSchemaElement element = FindSchemaElement(svcDesc, message.Parts[0].Element.Name, message.Parts[0].Element.Namespace);
                if (element == null || element.SchemaTypeName == null || element.SchemaTypeName.Name == "")
                    return message.Parts[0].Element.Name;

                elementName = element.QualifiedName.Name;
                type = element.ElementSchemaType;
                typeName = element.SchemaTypeName.Name;
            }

            // If this is a complex type return the element type name
            if (type is XmlSchemaComplexType)
                return elementName == null ? type.Name : elementName;

            bool IsEnum = false;
            if (type.DerivedBy == XmlSchemaDerivationMethod.Restriction)
            {
                XmlSchemaSimpleTypeRestriction restriction = (XmlSchemaSimpleTypeRestriction)((XmlSchemaSimpleType)type).Content;
                foreach (XmlSchemaFacet facet in restriction.Facets)
                {
                    if (facet is XmlSchemaEnumerationFacet)
                    {
                        IsEnum = true;
                        break;
                    }
                }
            }

            // If this is a simple type with enumeration restrictions, return the type name.
            // Else return the clr type name if this is a native type or the simple type name if this is not a native type.
            if (IsEnum == true)
                return typeName;
            else
            {
                string clrTypeName = CodeGenUtils.GetClrType(type.TypeCode);
                clrTypeName = clrTypeName != null && clrTypeName.IndexOf("System.") == 0 ? clrTypeName.Substring(7) : clrTypeName;
                if (clrTypeName == null)
                    return typeName;
                else if (type.Datatype.ValueType.IsArray)
                {
                    string typeSuffix = (clrTypeName.Length > 2 && clrTypeName.Substring(clrTypeName.Length - 2) == "[]") ? "" : "[]";
                    return clrTypeName + typeSuffix;
                }
                else
                    return clrTypeName;
            }
        }
        void ExportFault(FaultDescription fault)
        {
            WsdlNS.Message faultMessage = new WsdlNS.Message();
            faultMessage.Name = GetFaultMessageName(fault.Name);

            XmlQualifiedName elementName = ExportFaultElement(fault);
            this.contractContext.WsdlPortType.ServiceDescription.Messages.Add(faultMessage);
            AddMessagePart(faultMessage, "detail", elementName, null);

            // create a wsdl:fault to put inside the wsdl:portType/wsdl:operation
            WsdlNS.OperationFault operationFault = contractContext.GetOperationFault(fault);
            WsdlExporter.WSAddressingHelper.AddActionAttribute(fault.Action, operationFault, this.exporter.PolicyVersion);
            operationFault.Message = new XmlQualifiedName(faultMessage.Name, faultMessage.ServiceDescription.TargetNamespace);
        }
		void resolveMessage (Message msg, MessageBodyDescription body, List<MessagePartDescription> parts)
		{
			foreach (MessagePart part in msg.Parts) {
				if (part.Name == "parameters") {
					if (!part.Element.IsEmpty) {
						body.WrapperName = part.Element.Name;
						ImportPartsBySchemaElement (part.Element, parts, msg, part);
					} else {
						body.WrapperName = part.Type.Name;
						ResolveType (part.Type, parts, body.WrapperNamespace);
					}
				}
				else
					throw new InvalidOperationException ("Only 'parameters' element in message part is supported"); // this should have been rejected by CanImportOperation().
			}
		}
Example #48
0
		bool ImportBindingContent (ServiceDescription desc, TypeStubInfo typeInfo, string url, BindingInfo binfo)
		{
			serviceDescription = desc;
			
			// Look for an unused name
			
			int n=0;
			string name = binfo.Name;
			bool found;
			do
			{
				found = false;
				foreach (Binding bi in desc.Bindings)
					if (bi.Name == name) { found = true; n++; name = binfo.Name+n; break; }
			}
			while (found);
			
			// Create the binding
			
			binding = new Binding ();
			binding.Name = name;
			binding.Type = new XmlQualifiedName (binding.Name, binfo.Namespace);
			if (binfo.WebServiceBindingAttribute != null && binfo.WebServiceBindingAttribute.EmitConformanceClaims) {
				XmlDocument doc = new XmlDocument ();
				XmlElement docElement = doc.CreateElement ("wsdl", "documentation", "http://schemas.xmlsoap.org/wsdl/");
				XmlElement claimsElement = doc.CreateElement ("wsi", "Claim", "http://ws-i.org/schemas/conformanceClaim/");
				claimsElement.Attributes.Append (doc.CreateAttribute ("conformsTo")).Value = "http://ws-i.org/profiles/basic/1.1";
				docElement.AppendChild (claimsElement);
				binding.DocumentationElement = docElement;
			}
			
			portType = new PortType ();
			portType.Name = binding.Name;

			BeginClass ();

			foreach (SoapExtensionReflector reflector in extensionReflectors)
			{
				reflector.ReflectionContext = this;
				reflector.ReflectDescription ();
			}

			foreach (MethodStubInfo method in typeInfo.Methods)
			{
				methodStubInfo = method;
				
				string metBinding = ReflectMethodBinding ();
				if (typeInfo.GetBinding (metBinding) != binfo) continue;
				
				operation = new Operation ();
				operation.Name = method.OperationName;
				operation.Documentation = method.MethodAttribute.Description;

				// FIXME: SOAP 1.1 and SOAP 1.2 should share
				// the same message definitions.

				inputMessage = new Message ();
				inputMessage.Name = method.Name + ProtocolName + "In";
				ServiceDescription.Messages.Add (inputMessage);
				
				outputMessage = new Message ();
				outputMessage.Name = method.Name + ProtocolName + "Out";
				ServiceDescription.Messages.Add (outputMessage);

				OperationInput inOp = new OperationInput ();
				if (method.Name != method.OperationName) inOp.Name = method.Name;
				Operation.Messages.Add (inOp);
				inOp.Message = new XmlQualifiedName (inputMessage.Name, ServiceDescription.TargetNamespace);
				
				OperationOutput outOp = new OperationOutput ();
				if (method.Name != method.OperationName) outOp.Name = method.Name;
				Operation.Messages.Add (outOp);
				outOp.Message = new XmlQualifiedName (outputMessage.Name, ServiceDescription.TargetNamespace);
			
				portType.Operations.Add (operation);
				ImportOperationBinding ();
				
				if (!ReflectMethod ()) {
					// (It is somewhat hacky) If we don't
					// add input/output Messages, update
					// portType/input/@message and
					// porttype/output/@message.
					Message dupIn = Parent.MappedMessagesIn [method.MethodInfo];
					ServiceDescription.Messages.Remove (inputMessage);
					inOp.Message = new XmlQualifiedName (dupIn.Name, ServiceDescription.TargetNamespace);
					Message dupOut = Parent.MappedMessagesOut [method.MethodInfo];
					ServiceDescription.Messages.Remove (outputMessage);
					outOp.Message = new XmlQualifiedName (dupOut.Name, ServiceDescription.TargetNamespace);
				}

				foreach (SoapExtensionReflector reflector in extensionReflectors)
				{
					reflector.ReflectionContext = this;
					reflector.ReflectMethod ();
				}
			}
			
			EndClass ();
			
			if (portType.Operations.Count > 0)
			{
				desc.Bindings.Add (binding);
				desc.PortTypes.Add (portType);
				return true;
			}
			else
				return false;
		}
        protected bool CreateMessage(MessageDescription message, int messageIndex, out WsdlNS.Message wsdlMessage)
        {
            wsdlMessage = null;
            bool isNewMessage = true;

            if (ExportedMessages.WsdlMessages.ContainsKey(new MessageDescriptionDictionaryKey(contractContext.Contract, message)))
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.GetString(SR.MultipleCallsToExportContractWithSameContract)));

            TypedMessageKey typedMessageKey = null;
            OperationMessageKey messageKey = null;
            if (message.IsTypedMessage)
            {
                typedMessageKey = new TypedMessageKey(message.MessageType, operation.DeclaringContract.Namespace, this.GetExtensionData());
                if (ExportedMessages.TypedMessages.TryGetValue(typedMessageKey, out wsdlMessage))
                    isNewMessage = false;
            }
            else if (operation.OperationMethod != null)
            {
                messageKey = new OperationMessageKey(operation, messageIndex);
                if (ExportedMessages.ParameterMessages.TryGetValue(messageKey, out wsdlMessage))
                    isNewMessage = false;
            }

            WsdlNS.ServiceDescription wsdl = contractContext.WsdlPortType.ServiceDescription;
            if (isNewMessage)
            {
                wsdlMessage = new WsdlNS.Message();
                wsdlMessage.Name = GetMessageName(message);
                wsdl.Messages.Add(wsdlMessage);
                if (message.IsTypedMessage)
                    ExportedMessages.TypedMessages.Add(typedMessageKey, wsdlMessage);
                else if (messageKey != null)
                    ExportedMessages.ParameterMessages.Add(messageKey, wsdlMessage);
            }

            //Add Name to OperationMessage
            WsdlNS.OperationMessage wsdlOperationMessage = contractContext.GetOperationMessage(message);
            wsdlOperationMessage.Message = new XmlQualifiedName(wsdlMessage.Name, wsdlMessage.ServiceDescription.TargetNamespace);
            this.ExportedMessages.WsdlMessages.Add(new MessageDescriptionDictionaryKey(contractContext.Contract, message), wsdlMessage);

            return isNewMessage;
        }