Ejemplo n.º 1
0
        void IWsdlExportExtension.ExportEndpoint(WsdlExporter exporter, WsdlEndpointConversionContext context)
        {
            var extension = new System.Web.Services.Description.SoapBinding {
                Transport = "http://schemas.xmlsoap.org/soap/http",
                Style     = System.Web.Services.Description.SoapBindingStyle.Document
            };

            context.WsdlBinding.Extensions.Add(extension);
            var binding2 = new System.Web.Services.Description.SoapAddressBinding {
                Location = context.Endpoint.Address.Uri.AbsoluteUri
            };

            context.WsdlPort.Extensions.Add(binding2);
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        private string GenerateSOAP()
        {
            XmlTextReader xmlr = null;

            try
            {
                xmlr = new XmlTextReader(urltext.Text);
            }
            catch (XmlException xe)
            {
                Logger.Text += xe.ToString();
            }
            System.Web.Services.Description.ServiceDescription servdesc = null;
            servdesc = System.Web.Services.Description.ServiceDescription.Read(xmlr);
            System.Web.Services.Description.ServiceCollection serviceColl = servdesc.Services;
            string returnurl = null;

            Logger.Text += "\r\n **** Service(s) Found : " + serviceColl.Count + " ****\r\n";
            //string returnurl = null;
            //How to select from more than one WSDL Ports???
            TreeNode root   = null;
            TreeNode porttn = null;

            for (int i = 0; i < serviceColl.Count; i++)
            {
                //Logger.Text += "For service : " + serviceColl[i].Name + " " + serviceColl[i].Ports.Count + " port(s) discovered: --> ";
                root = new TreeNode(serviceColl[i].Name);
                portlist.Nodes.Add(root);
                for (int j = 0; j < serviceColl[i].Ports.Count; j++)
                {
                    //Logger.Text += serviceColl[i].Ports[j].Name + ", ";
                    //if (serviceColl[i].Ports[j].Name == stringNodeName)
                    //{
                    //int j = 0; // temp
                    //serviceno = i;
                    //portno = j;
                    //}
                    porttn = new TreeNode(serviceColl[i].Ports[j].Name);
                    root.Nodes.Add(porttn);
                }
            }
            portlist.SelectedNode = portlist.Nodes[0];

            for (int i = 0; i < serviceColl.Count; i++)
            {
                Logger.Text += "For service : " + serviceColl[i].Name + " " + serviceColl[i].Ports.Count + " port(s) discovered: --> ";
                for (int j = 0; j < serviceColl[i].Ports.Count; j++)
                {
                    Logger.Text += serviceColl[i].Ports[j].Name + ", ";
                    for (int k = 0; k < serviceColl[i].Ports[j].Extensions.Count; k++)
                    {
                        System.Web.Services.Description.Binding              basebinding = serviceColl[i].Ports[j].Extensions[k] as System.Web.Services.Description.Binding;
                        System.Web.Services.Description.SoapAddressBinding   sab         = serviceColl[i].Ports[j].Extensions[k] as System.Web.Services.Description.SoapAddressBinding;
                        System.Web.Services.Description.Soap12AddressBinding s12ab       = serviceColl[i].Ports[j].Extensions[k] as System.Web.Services.Description.Soap12AddressBinding;
                        System.Web.Services.Description.HttpAddressBinding   hab         = serviceColl[i].Ports[j].Extensions[k] as System.Web.Services.Description.HttpAddressBinding;
                        if (sab != null)
                        {
                            returnurl      = sab.Location;
                            Logger.Text   += returnurl;
                            targeturl.Text = returnurl;
                        }
                        else if (s12ab != null)
                        {
                            returnurl      = s12ab.Location;
                            Logger.Text   += returnurl;
                            targeturl.Text = returnurl;
                        }
                        else
                        {
                            returnurl      = hab.Location;
                            Logger.Text   += returnurl;
                            targeturl.Text = returnurl;
                        }
                    }
                }
                Logger.Text += "\r\n";
            }
            return(returnurl);
        }