private void MoveToOperation(System.Web.Services.Description.Operation operation) { this.operation = operation; this.operationBinding = null; foreach (System.Web.Services.Description.OperationBinding binding in this.binding.Operations) { if (operation.IsBoundBy(binding)) { if (this.operationBinding != null) { throw this.OperationSyntaxException(System.Web.Services.Res.GetString("DuplicateInputOutputNames0")); } this.operationBinding = binding; } } if (this.operationBinding == null) { throw this.OperationSyntaxException(System.Web.Services.Res.GetString("MissingBinding0")); } if ((operation.Messages.Input != null) && (this.operationBinding.Input == null)) { throw this.OperationSyntaxException(System.Web.Services.Res.GetString("MissingInputBinding0")); } if ((operation.Messages.Output != null) && (this.operationBinding.Output == null)) { throw this.OperationSyntaxException(System.Web.Services.Res.GetString("MissingOutputBinding0")); } this.inputMessage = (operation.Messages.Input == null) ? null : this.ServiceDescriptions.GetMessage(operation.Messages.Input.Message); this.outputMessage = (operation.Messages.Output == null) ? null : this.ServiceDescriptions.GetMessage(operation.Messages.Output.Message); }
internal void SetParent(System.Web.Services.Description.Operation parent) { this.parent = parent; }
private void ReflectBinding(ReflectedBinding reflectedBinding) { string identifier = XmlConvert.EncodeLocalName(reflectedBinding.bindingAttr.Name); string ns = reflectedBinding.bindingAttr.Namespace; if (identifier.Length == 0) { identifier = this.Service.Name + this.ProtocolName; } if (ns.Length == 0) { ns = this.ServiceDescription.TargetNamespace; } WsiProfiles none = WsiProfiles.None; if (reflectedBinding.bindingAttr.Location.Length > 0) { this.portType = null; this.binding = null; } else { this.bindingServiceDescription = this.GetServiceDescription(ns); CodeIdentifiers identifiers = new CodeIdentifiers(); foreach (System.Web.Services.Description.Binding binding in this.bindingServiceDescription.Bindings) { identifiers.AddReserved(binding.Name); } identifier = identifiers.AddUnique(identifier, this.binding); this.portType = new System.Web.Services.Description.PortType(); this.binding = new System.Web.Services.Description.Binding(); this.portType.Name = identifier; this.binding.Name = identifier; this.binding.Type = new XmlQualifiedName(this.portType.Name, ns); none = reflectedBinding.bindingAttr.ConformsTo & this.ConformsTo; if (reflectedBinding.bindingAttr.EmitConformanceClaims && (none != WsiProfiles.None)) { System.Web.Services.Description.ServiceDescription.AddConformanceClaims(this.binding.GetDocumentationElement(), none); } this.bindingServiceDescription.Bindings.Add(this.binding); this.bindingServiceDescription.PortTypes.Add(this.portType); } if (this.portNames == null) { this.portNames = new CodeIdentifiers(); foreach (System.Web.Services.Description.Port port in this.Service.Ports) { this.portNames.AddReserved(port.Name); } } this.port = new System.Web.Services.Description.Port(); this.port.Binding = new XmlQualifiedName(identifier, ns); this.port.Name = this.portNames.AddUnique(identifier, this.port); this.Service.Ports.Add(this.port); this.BeginClass(); if ((reflectedBinding.methodList != null) && (reflectedBinding.methodList.Count > 0)) { foreach (LogicalMethodInfo info in reflectedBinding.methodList) { this.MoveToMethod(info); this.operation = new System.Web.Services.Description.Operation(); this.operation.Name = XmlConvert.EncodeLocalName(info.Name); if ((this.methodAttr.Description != null) && (this.methodAttr.Description.Length > 0)) { this.operation.Documentation = this.methodAttr.Description; } this.operationBinding = new System.Web.Services.Description.OperationBinding(); this.operationBinding.Name = this.operation.Name; this.inputMessage = null; this.outputMessage = null; this.headerMessages = null; if (this.ReflectMethod()) { if (this.inputMessage != null) { this.bindingServiceDescription.Messages.Add(this.inputMessage); } if (this.outputMessage != null) { this.bindingServiceDescription.Messages.Add(this.outputMessage); } if (this.headerMessages != null) { foreach (Message message in this.headerMessages) { this.bindingServiceDescription.Messages.Add(message); } } this.binding.Operations.Add(this.operationBinding); this.portType.Operations.Add(this.operation); } } } if (((this.binding != null) && (none == WsiProfiles.BasicProfile1_1)) && (this.ProtocolName == "Soap")) { BasicProfileViolationCollection violations = new BasicProfileViolationCollection(); WebServicesInteroperability.AnalyzeBinding(this.binding, this.bindingServiceDescription, this.ServiceDescriptions, violations); if (violations.Count > 0) { throw new InvalidOperationException(System.Web.Services.Res.GetString("WebWsiViolation", new object[] { this.ServiceType.FullName, violations.ToString() })); } } this.EndClass(); }
private string GenerateSOAP(string stringNodeName, string url) { XmlTextReader xmlr = null; string returnval = null; string headerval = null; int indexOfOp = -1; int indexOfPort = -1; System.Web.Services.Description.ServiceDescription servdesc = null; System.Xml.Serialization.XmlSchemas schemas = null; XmlGenerator xmlGen = new XmlGenerator(); try { //xmlr = new XmlTextReader(urltext.Text); xmlr = new XmlTextReader(url); xmlr.WhitespaceHandling = WhitespaceHandling.None; servdesc = System.Web.Services.Description.ServiceDescription.Read(xmlr); schemas = servdesc.Types.Schemas; //Find operation matching the selected row for (int i = 0; i < servdesc.PortTypes.Count && indexOfPort == -1 && indexOfOp == -1; i++) { for (int j = 0; j < servdesc.PortTypes[i].Operations.Count && indexOfPort == -1 && indexOfOp == -1; j++) { if (servdesc.PortTypes[i].Operations[j].Name == stringNodeName) { indexOfOp = j; indexOfPort = i; } } } System.Web.Services.Description.Operation SelectedOp = null; if (indexOfPort != -1 && indexOfOp != -1) { SelectedOp = servdesc.PortTypes[indexOfPort].Operations[indexOfOp]; } else { Logger.Text += " Element not found in selected Operations \r\n"; return(""); } //Get the URL for the particular method int serviceno = -1; int portno = -1; int extno = -1; string urltosend = null; System.Web.Services.Description.Port SelectedPort = null; System.Web.Services.Description.ServiceCollection serviceColl = servdesc.Services; Logger.Text += "\r\nSelected port index: " + portlist.SelectedNode.Index + "\r\n"; bool found = false; for (int i = 0; i < serviceColl.Count && !found; i++) { for (int j = 0; j < serviceColl[i].Ports.Count && !found; j++) { if (serviceColl[i].Ports[j].Name == portlist.SelectedNode.Text) { found = true; serviceno = i; portno = j; } } } if (serviceno != -1 && portno != -1) { SelectedPort = serviceColl[serviceno].Ports[portno]; for (int k = 0; k < SelectedPort.Extensions.Count; k++) { System.Web.Services.Description.Binding basebinding = SelectedPort.Extensions[k] as System.Web.Services.Description.Binding; System.Web.Services.Description.SoapAddressBinding sab = SelectedPort.Extensions[k] as System.Web.Services.Description.SoapAddressBinding; System.Web.Services.Description.Soap12AddressBinding s12ab = SelectedPort.Extensions[k] as System.Web.Services.Description.Soap12AddressBinding; System.Web.Services.Description.HttpAddressBinding hab = SelectedPort.Extensions[k] as System.Web.Services.Description.HttpAddressBinding; if (sab != null) { urltosend = sab.Location; //Logger.Text += urltosend; } else if (s12ab != null) { urltosend = s12ab.Location; //Logger.Text += urltosend; } else { urltosend = hab.Location; //Logger.Text += urltosend; } } int bindingno = -1; int opno = -1; found = false; for (int i = 0; i < servdesc.Bindings.Count && !found; i++) { for (int j = 0; j < servdesc.Bindings[i].Operations.Count && !found; j++) { if (servdesc.Bindings[i].Operations[j].Name == stringNodeName) { bindingno = i; opno = j; found = true; } } } if (bindingno != -1 && opno != -1) { for (int k = 0; k < servdesc.Bindings[bindingno].Operations[opno].Extensions.Count; k++) { System.Web.Services.Description.Binding basebinding = servdesc.Bindings[bindingno].Operations[opno].Extensions[k] as System.Web.Services.Description.Binding; System.Web.Services.Description.SoapOperationBinding sob = servdesc.Bindings[bindingno].Operations[opno].Extensions[k] as System.Web.Services.Description.SoapOperationBinding; System.Web.Services.Description.Soap12OperationBinding s12ob = servdesc.Bindings[bindingno].Operations[opno].Extensions[k] as System.Web.Services.Description.Soap12OperationBinding; System.Web.Services.Description.HttpOperationBinding hob = servdesc.Bindings[bindingno].Operations[opno].Extensions[k] as System.Web.Services.Description.HttpOperationBinding; if (sob != null) { //urltosend += sob.SoapAction; ListViewItem item = new ListViewItem(); item.Text = "SoapAction: \"" + sob.SoapAction + "\""; httpheaderlist.Items.Add(item); for (int index = 0; index < servdesc.Bindings[bindingno].Operations[opno].Input.Extensions.Count; index++) { System.Web.Services.Description.SoapHeaderBinding shb = servdesc.Bindings[bindingno].Operations[opno].Input.Extensions[index] as System.Web.Services.Description.SoapHeaderBinding; if (shb != null) { //SoapHeader is defined //returnval += SchemaSearching(servdesc.Types.Schemas[0], shb.Message.Name); Logger.Text += "Name of header " + shb.Message.Name + "\r\n"; string headerType; //returnval += SchemaSearching(servdesc.Types.Schemas[0], servdesc.Messages[shb.Message.Name].Parts[0].Element.Name); if (servdesc.Messages[shb.Message.Name].Parts[0].Type.IsEmpty) { headerType = servdesc.Messages[shb.Message.Name].Parts[0].Element.Name; headerval += SchemaSearching(servdesc.Types.Schemas[0], headerType); } else { //Currently takes care of only one part in each message if (shb.Message.Name != null) { headerval += '<' + shb.Message.Name + '>'; for (int i = 0; i < servdesc.Messages[shb.Message.Name].Parts.Count; i++) { headerType = servdesc.Messages[shb.Message.Name].Parts[i].Type.Name; headerval += '<' + servdesc.Messages[shb.Message.Name].Parts[i].Name + '>'; headerval += SchemaSearching(servdesc.Types.Schemas[0], headerType); headerval += "</" + servdesc.Messages[shb.Message.Name].Parts[i].Name + ">"; } headerval += "</" + shb.Message.Name + '>'; } } } } break; //Logger.Text += urltosend; } else if (s12ob != null) { ListViewItem item = new ListViewItem(); item.Text = "SoapAction: \"" + sob.SoapAction + "\""; httpheaderlist.Items.Add(item); for (int index = 0; index < servdesc.Bindings[bindingno].Operations[opno].Input.Extensions.Count; index++) { System.Web.Services.Description.Soap12HeaderBinding s12hb = servdesc.Bindings[bindingno].Operations[opno].Input.Extensions[index] as System.Web.Services.Description.Soap12HeaderBinding; if (s12hb != null) { //SoapHeader is defined //returnval += SchemaSearching(servdesc.Types.Schemas[0], shb.Message.Name); Logger.Text += "Name of header " + s12hb.Message.Name + "\r\n"; string headerType; //returnval += SchemaSearching(servdesc.Types.Schemas[0], servdesc.Messages[shb.Message.Name].Parts[0].Element.Name); if (servdesc.Messages[s12hb.Message.Name].Parts[0].Type.IsEmpty) { headerType = servdesc.Messages[s12hb.Message.Name].Parts[0].Element.Name; headerval += SchemaSearching(servdesc.Types.Schemas[0], headerType); } else { //Currently takes care of only one part in each message if (s12hb.Message.Name != null) { headerval += '<' + s12hb.Message.Name + '>'; for (int i = 0; i < servdesc.Messages[s12hb.Message.Name].Parts.Count; i++) { headerType = servdesc.Messages[s12hb.Message.Name].Parts[i].Type.Name; headerval += '<' + servdesc.Messages[s12hb.Message.Name].Parts[i].Name + '>'; headerval += SchemaSearching(servdesc.Types.Schemas[0], headerType); headerval += "</" + servdesc.Messages[s12hb.Message.Name].Parts[i].Name + ">"; } headerval += "</" + s12hb.Message.Name + '>'; } } } } urltosend += s12ob.SoapAction; break; //Logger.Text += urltosend; } else if (hob != null) { urltosend += hob.Location; break; //Logger.Text += urltosend; } } } //Find the right binding Logger.Text += urltosend; Logger.Text += "\r\n"; targeturl.Text = urltosend; } //Path to XML schema definition from Operation Name //portType -> Operation:Name -> input:message // input:message == Message:Name //Message:Name -> Part:element //Types -> Schema -> Element:Name //Part:Element == Element:Name Logger.Text += " searching for " + stringNodeName + "\r\n"; //Logger.Text += " ****** " + SelectedOp.Messages.Count + " ****** "; /*for (int i = 0; i < SelectedOp.PortType.Operations.Count; i++) * { * for (int j = 0; j < SelectedOp.PortType.Operations[i].Messages.Count; j++)// +", "; * { * Logger.Text += SelectedOp.PortType.Operations[i].Messages[j].GetType() + " == "; * Logger.Text += SelectedOp.PortType.Operations[i].Messages[j].Name + "\r\n"; * } * }*/ string inputParameterType = null; string inputMessageType = SelectedOp.Messages.Input.Message.Name; // TODO: What if there are more than one service descriptions? System.Xml.Schema.XmlSchema xmlSchema = servdesc.Types.Schemas[0]; //What if there are more than one Parts if (servdesc.Messages[SelectedOp.Messages.Input.Message.Name].Parts[0].Type.IsEmpty) { inputParameterType = servdesc.Messages[SelectedOp.Messages.Input.Message.Name].Parts[0].Element.Name; returnval += SchemaSearching(xmlSchema, inputParameterType); } else { //Currently takes care of only one part in each message if (SelectedOp.Messages.Input.Message.Name != null) { returnval += '<' + SelectedOp.Messages.Input.Message.Name + '>'; for (int i = 0; i < servdesc.Messages[SelectedOp.Messages.Input.Message.Name].Parts.Count; i++) { inputParameterType = servdesc.Messages[SelectedOp.Messages.Input.Message.Name].Parts[i].Type.Name; returnval += '<' + servdesc.Messages[SelectedOp.Messages.Input.Message.Name].Parts[i].Name + '>'; returnval += SchemaSearching(xmlSchema, inputParameterType); returnval += "</" + servdesc.Messages[SelectedOp.Messages.Input.Message.Name].Parts[i].Name + ">"; } returnval += "</" + SelectedOp.Messages.Input.Message.Name + '>'; } } Logger.Text += "Selected the method : " + inputMessageType + " that needs " + inputParameterType + " as the param\r\n"; //Logger.Text += servdesc.Messages[SelectedOp.Messages.Input.Message.Name].Parts[0].Type.Name + " as the param\r\n" ; //Logger.Text += "\r\n"; /* * System.Xml.Schema.XmlSchema xmlSchema = servdesc.Types.Schemas[0]; * * foreach (object item in xmlSchema.Items) * { * * System.Xml.Schema.XmlSchemaElement schemaElement = item as System.Xml.Schema.XmlSchemaElement; * //Logger.Text += "Ref name = " + schemaElement.RefName + "\r\n"; * //Logger.Text += " -------- " + item.GetType() + "\r\n"; * if (schemaElement != null) * { * //Logger.Text += "Ref name = " + schemaElement.RefName + "\r\n"; * if (schemaElement.Name == inputParameterType) * { * Logger.Text += "\r\n1. ******************\r\n"; * returnval = xmlGen.GenerateXmlString(schemaElement, xmlSchema); * Logger.Text += returnval+"\r\n"; * Logger.Text += "\r\n******************\r\n";*/ /*Logger.Text += "Schema Element Name : " + schemaElement.Name + "\r\n" ; * System.Xml.Schema.XmlSchemaType schemaType = schemaElement.SchemaType; * Logger.Text += "Type of " + schemaElement.Name + " is " + schemaElement.SchemaTypeName + "\r\n"; * System.Xml.Schema.XmlSchemaComplexType complexType = schemaType as System.Xml.Schema.XmlSchemaComplexType; * if (complexType != null) * { * System.Xml.Schema.XmlSchemaParticle particle = complexType.Particle; * Logger.Text += "Annot : " + particle.Annotation + "\r\n" ; * if (particle != null) * { //TraverseParticle(complexType.Particle); * Logger.Text += '<' + complexType.Name + '>' + xmlGen.GenerateXmlString(complexType.Particle) + "</" + complexType.Name + '>'; * } * } * else * { * //If it's not a Complex Type element * System.Xml.Schema.XmlSchemaSimpleType simpleType = schemaType as System.Xml.Schema.XmlSchemaSimpleType; * //simpleType. * }*//* * } * } * else * { //This is a complex Type * System.Xml.Schema.XmlSchemaComplexType complexType = item as System.Xml.Schema.XmlSchemaComplexType; * if (complexType != null) * { * //Logger.Text += "Name : " + complexType.Name + "\r\n" ; * if (complexType.Name == inputParameterType) * { * Logger.Text += "Complex Type Name : " + complexType.Name + "\r\n"; * System.Xml.Schema.XmlSchemaParticle particle = complexType.Particle; * System.Xml.Schema.XmlSchemaSequence sequence = particle as System.Xml.Schema.XmlSchemaSequence; * System.Xml.Schema.XmlSchemaAll schemaall = particle as System.Xml.Schema.XmlSchemaAll; * if (sequence != null) * { * foreach (System.Xml.Schema.XmlSchemaElement childElement in sequence.Items) * { * string parameterName = childElement.Name; * string parameterType = childElement.SchemaTypeName.Name; * Logger.Text += parameterName + " is a " + parameterType; * Logger.Text += "\r\n2. ************************************\r\n"; * returnval = '<' + complexType.Name + '>' + xmlGen.GenerateXmlString(childElement, xmlSchema) + "</" + complexType.Name + '>'; * Logger.Text += returnval; * Logger.Text += "\r\n************************************\r\n"; * } * } * else * { * if (schemaall != null) * { * Logger.Text += "\r\n3. ************************************\r\n"; * returnval = '<' + complexType.Name + '>' + xmlGen.GenerateXmlString(schemaall, xmlSchema) + "</" + complexType.Name + '>'; * Logger.Text += returnval; * Logger.Text += "\r\n************************************\r\n"; * //TraverseParticle(schemaall); * } * else * { * System.Xml.Schema.XmlSchemaComplexContent cmplxContent = null; * * if (cmplxContent != null) * { * Logger.Text += cmplxContent.GetType(); * Logger.Text += "\r\n4. ************************************\r\n"; * returnval = '<' + complexType.Name + '>' + xmlGen.GenerateXmlString(cmplxContent, xmlSchema) + "</" + complexType.Name + '>'; ; * Logger.Text += returnval; * Logger.Text += "\r\n************************************\r\n"; * } * } * } * } * } * else * { * System.Xml.Schema.XmlSchemaSimpleType simpleType = item as System.Xml.Schema.XmlSchemaSimpleType; * * } * } * }*/ returnval = Encapsulate("xmlns=\"" + servdesc.TargetNamespace + "\"", headerval, returnval); return(returnval); /* * for (int k = 0; k < schemas.Count; k++) * { * XmlSchemaObjectCollection xmlelem = schemas[k].Items; * XmlSchemaObjectEnumerator enumerator = xmlelem.GetEnumerator(); * while (enumerator.MoveNext()) * { * Logger.Text += " Type of " +enumerator.Current.GetType() + "\r\n" ; * * if (enumerator.Current is XmlSchemaElement) * { * XmlSchemaElement xse = (XmlSchemaElement)enumerator.Current; * Logger.Text += xse.Name + '=' + xse.SchemaType + ", "; * //if * TraverseParticle(xse); * } * else * { * if (enumerator.Current is XmlSchemaComplexType) * { * XmlSchemaComplexType xsct = (XmlSchemaComplexType)enumerator.Current; * Logger.Text += '\'' + xsct.Name + ": "; * TraverseParticle(xsct.Particle); * if (xsct.ContentModel is XmlSchemaSimpleContent) * { * Logger.Text += "Simple; "; * } * else * { * //XmlSchemaComplexContent complexContent = (XmlSchemaComplexContent)xsct.ContentModel; * if (xsct.ContentModel is XmlSchemaComplexContent) * { * Logger.Text += "Complex; "; * } * } * Logger.Text += "\',"; * } * } * } * Logger.Text += "\r\n"; * }*/ //Path to URL from Operation Name // Operation ^ Binding:Name //Service -> Port:Binding // Binding:Name == Port:Binding // Port:Name -> (Soapaddressbinding/HttpAddressBinding/Soap12AddressBinding).Location } catch (XmlException xe) { Logger.Text += xe.ToString(); } returnval = Encapsulate("xmlns=\"" + servdesc.TargetNamespace + "\"", headerval, returnval); return(returnval); }
public OperationDescription GetOperationDescription(System.Web.Services.Description.Operation operation) { return(default(OperationDescription)); }
public System.Web.Services.Description.Operation ReadObject_Operation (bool isNullable, bool checkType) { System.Web.Services.Description.Operation ob = null; if (isNullable && ReadNull()) return null; if (checkType) { System.Xml.XmlQualifiedName t = GetXsiType(); if (t != null) { if (t.Name != "Operation" || t.Namespace != "http://schemas.xmlsoap.org/wsdl/") throw CreateUnknownTypeException(t); } } ob = new System.Web.Services.Description.Operation (); Reader.MoveToElement(); while (Reader.MoveToNextAttribute()) { if (Reader.LocalName == "name" && Reader.NamespaceURI == "") { ob.Name = XmlConvert.DecodeName(Reader.Value); } else if (Reader.LocalName == "parameterOrder" && Reader.NamespaceURI == "") { ob.ParameterOrderString = Reader.Value; } else if (IsXmlnsAttribute (Reader.Name)) { } else { UnknownNode (ob); } } Reader.MoveToElement(); if (Reader.IsEmptyElement) { Reader.Skip (); return ob; } Reader.ReadStartElement(); Reader.MoveToContent(); bool b46=false, b47=false, b48=false; System.Web.Services.Description.OperationFaultCollection o50 = ob.Faults; System.Web.Services.Description.OperationMessageCollection o52 = ob.Messages; int n49=0, n51=0; while (Reader.NodeType != System.Xml.XmlNodeType.EndElement) { if (Reader.NodeType == System.Xml.XmlNodeType.Element) { if (Reader.LocalName == "input" && Reader.NamespaceURI == "http://schemas.xmlsoap.org/wsdl/" && !b47) { if (o52 == null) throw CreateReadOnlyCollectionException ("System.Web.Services.Description.OperationMessageCollection"); o52.Add (ReadObject_OperationInput (false, true)); n51++; } else if (Reader.LocalName == "fault" && Reader.NamespaceURI == "http://schemas.xmlsoap.org/wsdl/" && !b46) { if (o50 == null) throw CreateReadOnlyCollectionException ("System.Web.Services.Description.OperationFaultCollection"); o50.Add (ReadObject_OperationFault (false, true)); n49++; } else if (Reader.LocalName == "documentation" && Reader.NamespaceURI == "http://schemas.xmlsoap.org/wsdl/" && !b48) { b48 = true; ob.Documentation = Reader.ReadElementString (); } else if (Reader.LocalName == "output" && Reader.NamespaceURI == "http://schemas.xmlsoap.org/wsdl/" && !b47) { if (o52 == null) throw CreateReadOnlyCollectionException ("System.Web.Services.Description.OperationMessageCollection"); o52.Add (ReadObject_OperationOutput (false, true)); n51++; } else { UnknownNode (ob); } } else UnknownNode(ob); Reader.MoveToContent(); } ReadEndElement(); return ob; }