Click here to Skip to main content
15,891,513 members
Articles / Programming Languages / C#

UDDI Explorer: Tool for Searching Web Services

Rate me:
Please Sign up or sign in to vote.
4.93/5 (49 votes)
20 Dec 200517 min read 222.5K   3.2K   109  
Tool for searching web service(s) and viewing their WSDL information
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Xml;
using System.Web.Services.Description;

namespace UDDI_Explorer
{
    class WSDLRetrieval
    {
        public static bool RetrieveWSDLFile(UDDIService serviceInfo, bool online)
        {
            if (serviceInfo.LocationFile != null && serviceInfo.LocationFile.LastIndexOf(@":\") == -1)
            {
                string strPath = Application.ExecutablePath;
                int i = strPath.LastIndexOf(@"\");
                string strDir = strPath.Substring(0, i + 1) + @"WSDLCache";
                strPath = strDir + "\\" + serviceInfo.LocationFile;
                
                if (!Directory.Exists(strDir))
                {
                    Directory.CreateDirectory (strDir);
                    if (!Directory.Exists(strDir))
                    {
                        throw new Exception("Could not create the WSDLCache folder at the location : " + strDir);
                    }
                }
                serviceInfo.LocationFile = strPath;
            };
            
            if (online)
            {
                try
                {
                    XmlTextReader reader = new XmlTextReader(serviceInfo.Url);
                    ServiceDescription tmpService =
                        ServiceDescription.Read(reader);
                    tmpService.Name = serviceInfo.Url;
                    tmpService.RetrievalUrl = serviceInfo.Url;
                    tmpService.Write(serviceInfo.LocationFile);

                    if (!File.Exists(serviceInfo.LocationFile))
                    {
                        throw new Exception("Could not write the wsdl at the location :" + serviceInfo.LocationFile);
                    };
                }
                catch (Exception)
                {
                    throw new Exception("Could not retrieve the wsdl from the url: " + serviceInfo.Url);
                }


            }
            else
                if (!File.Exists(serviceInfo.LocationFile))
                {
                    throw new Exception("File does not exist");
                };

            return true;
        }

        public static TreeNode WSDLToNode(UDDIService serviceInfo, bool online)
        {
            try
            {
                if (RetrieveWSDLFile(serviceInfo, online))
                {
                    ServiceDescription myService =
                        ServiceDescription.Read(serviceInfo.LocationFile);

                    if (myService.Name == string.Empty || myService.Name == null)
                    {
                        myService.Name = serviceInfo.Url;
                    };
                    if (myService.Name != string.Empty && serviceInfo.Url == string.Empty)
                        serviceInfo.Url = myService.Name;

                    serviceInfo.Descriptions = myService.Documentation;

                    WSDLParser.WSDLParser parse = new WSDLParser.WSDLParser(myService);
                    TreeNode node = new TreeNode();
                    node = parse.ServiceNode;
                    return node;
                }

            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message.ToString());
            }
            finally
            {

            };

            return null;

        }

    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.


Written By
Software Developer
Vietnam Vietnam
I'm still alive...but temporarily moved to work on mobile & web stuffs(j2me/brew/php/flash...something not M$). things have just been very busy, and probably will continue...so don't have chance to maintain & respond. Hope will have time to try to write again, because many ideas with WPF &silver light are waiting. wish me luck Smile | :)

FYI:
- MESHSimPack project(c# library for measuring similarity among concepts of the MESH ontology):
http://sourceforge.net/projects/meshsimpack.

Comments and Discussions