Пример #1
0
        //
        //  METHOD      : SeedUI
        //  DESCRIPTION : seeds the service combobox and reads the config file for all records
        //                stores a copy of each record in a list of ServiceRecord objects.
        //  PARAMETERS  : na
        //  RETURNS     : void
        //
        public void SeedUI()
        {
            int duplicateIndicator = 0;

            string[] elements;
            string[] parameters;

            //read the Service config file
            using (StreamReader reader = new StreamReader(@"..\..\ServiceRecordConfig.txt"))
            {
                string currentRecord;
                //read each line
                while ((currentRecord = reader.ReadLine()) != null)
                {
                    ServiceRecord serviceRecord = new ServiceRecord();
                    //split each line into individual values
                    //and store them into a object's property
                    elements = currentRecord.Split(',');
                    serviceRecord.HostHeader    = elements[0];
                    serviceRecord.MethodAddress = elements[1];
                    serviceRecord.MethodName    = elements[2];
                    serviceRecord.ServiceName   = elements[3];
                    Dictionary <string, string> myDictionary = new Dictionary <string, string>();
                    for (int i = 4; i < elements.Length; i++)
                    {
                        //Dictionary<string, string> myDictionary = new Dictionary<string, string>();
                        parameters = elements[i].Split('-');

                        myDictionary.Add(parameters[0], parameters[1]);
                    }
                    //store parameters
                    serviceRecord.SetParameters(myDictionary);

                    //add record to a list
                    serviceRecordList.Add(serviceRecord);
                }
            }

            foreach (ServiceRecord record in serviceRecordList)
            {
                if (!ServicesCombobox.Items.Contains(record.ServiceName))
                {
                    //and service names to combobox
                    ServicesCombobox.Items.Add(record.ServiceName);
                }
            }
        }
Пример #2
0
        //
        //  METHOD      : ParseWSDL
        //  DESCRIPTION : Read the WSDL's contents, parse out data used in building a SOAP request to the service.
        //  PARAMETERS  : n/a
        //  RETURNS     : Dictionary<string,string> parameters
        //
        public void ParseWSDL(string filepath)
        {
            string parameterName = "";
            string parameterType = "";

            bool methodResponse = false;

            Dictionary <string, string> parameterListBuffer = new Dictionary <string, string>();

            //load a wsdl
            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.Load(filepath);

            //find a parent node to all methods of the service
            XmlNodeList mySchema         = xmlDoc.GetElementsByTagName("s:schema");
            XmlNodeList schemaChildNodes = mySchema[0].ChildNodes;     //get childnodes of the schema tag

            foreach (XmlNode childnode in schemaChildNodes)            // iterate through each childnode
            {
                if (childnode.HasChildNodes)                           //check if this tag has children
                {
                    ServiceRecord serviceRecord = new ServiceRecord(); //create a storage object


                    XmlAttributeCollection myMethodAttributes = childnode.Attributes; //create a attribute collection so we can check attribute names of tags

                    foreach (XmlAttribute attribute in myMethodAttributes)            //iterate through each attribute
                    {
                        if (attribute.Name == "name")                                 //look for these specific tags and retrieve their values.
                        {
                            if (!attribute.Value.ToString().Contains("Response"))
                            {
                                methodResponse           = false;
                                serviceRecord.MethodName = attribute.Value.ToString();
                            }//find the value of the targetNamespace
                            else
                            {
                                methodResponse = true;
                            }
                        }
                    }
                    if (!methodResponse) //if we haven't got a response method.
                    {
                        //originally outside the record loop
                        XmlAttributeCollection targetNamespace = mySchema[0].Attributes;  //get attributes of schema
                        // THIS GETS OUR TARGET NAMESPACE
                        foreach (XmlAttribute attribute in targetNamespace)               //iterate through schema attributes
                        {
                            if (attribute.Name == "targetNamespace")                      //find the attribute targetNamespace
                            {
                                serviceRecord.MethodAddress = attribute.Value.ToString(); //find the value of the targetNamespace
                            }
                        }

                        //get our service
                        XmlNodeList            myService     = xmlDoc.GetElementsByTagName("wsdl:service");
                        XmlAttributeCollection myServiceName = myService[0].Attributes;
                        foreach (XmlAttribute serviceAttribute in myServiceName)
                        {
                            if (serviceAttribute.Name == "name")
                            {
                                serviceRecord.ServiceName = serviceAttribute.Value.ToString();
                            }
                        }
                        //get our soad address
                        XmlNodeList            myAddress           = xmlDoc.GetElementsByTagName("soap:address");
                        XmlAttributeCollection myAddressAttributes = myAddress[0].Attributes;
                        foreach (XmlAttribute attribute in myAddressAttributes)
                        {
                            if (attribute.Name == "location")
                            {
                                serviceRecord.HostHeader = attribute.Value.ToString();
                            }
                        }//end of outside

                        //this is for parameters
                        if (childnode.HasChildNodes)
                        {
                            if (childnode.ChildNodes[0].HasChildNodes)
                            {
                                XmlNodeList parameterNodes = childnode.ChildNodes[0].ChildNodes[0].ChildNodes;

                                foreach (XmlNode parameters in parameterNodes)
                                {
                                    XmlAttributeCollection myParameterAttributes = parameters.Attributes;
                                    foreach (XmlNode parameterAttributes in myParameterAttributes)
                                    {
                                        if (parameterAttributes.Name == "name")
                                        {
                                            parameterName = parameterAttributes.Value.ToString();
                                        }
                                        if (parameterAttributes.Name == "type")
                                        {
                                            parameterType = parameterAttributes.Value.ToString();
                                        }
                                        if ((parameterName.Length > 0) && (parameterType.Length > 0))
                                        {
                                            parameterListBuffer.Add(parameterName, parameterType);
                                            parameterName = "";
                                            parameterType = "";
                                            //add to service record and remove values from these variables
                                        }
                                    }
                                    //add the parameters to a dictionary
                                    serviceRecord.SetParameters(parameterListBuffer);
                                }
                                parameterListBuffer.Clear();
                            }
                            else
                            {
                                parameterListBuffer.Add("null", "null");
                                //add parameters to a record
                                serviceRecord.SetParameters(parameterListBuffer);
                                parameterListBuffer.Clear();
                            }
                        }
                        configRecords.Add(serviceRecord); //add record to a list
                    }
                }
            }
        }