Click here to Skip to main content
15,896,207 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 223.2K   3.2K   109  
Tool for searching web service(s) and viewing their WSDL information
#region header documentation
/****************************************************************************
*	(c) Copyright Dao Ngoc Thanh $ Email: thanh.dao@gmx.net, dnt_box@yahoo.com.au, 2005. All rights reserved.
*	
*****************************************************************************
*
*	File:	
*
*	Purpose:	 
*
*	 $Logfile: 
*	$Revision: 1 $
*	    
*	  $Author: Dao Ngoc Thanh
*
****************************************************************************/
#endregion

using System;
using System.Reflection;
using System.Windows.Forms;
using System.Net;
using System.Text.RegularExpressions;
using System.Threading;
using Microsoft.Uddi;
using Microsoft.Uddi.Business;
using Microsoft.Uddi.Service;
using Microsoft.Uddi.Binding;
using Microsoft.Uddi.ServiceType;
using Microsoft.Uddi.Api;
using WSDLParser;
using System.Collections;
using ServiceRanking;


namespace UDDI_Explorer
{
	/// <summary>
	/// Summary description for UDDIExplorerForm.
	/// </summary>
	/// 	

	internal class UDDIExplorerForm : System.Windows.Forms.Form
	{
		internal static UDDIServiceList SelectedServiceList;		
		#region data
		private System.ComponentModel.IContainer components;
		private System.Windows.Forms.Button btnAddSelect;
		private System.Windows.Forms.Button btnCancel;
		private ComboBox cboInquireUrl;
		private Regex regexURL;
		private Thread _thread;
		private ThreadStart _threadStart;

		private System.Windows.Forms.ImageList tvImageList;				
		private System.Windows.Forms.GroupBox groupBox2;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.GroupBox groupBox1;
		private System.Windows.Forms.CheckBox chkSensitive;
		private System.Windows.Forms.CheckBox chkExactMatch;
		private System.Windows.Forms.Button btnHelp;
		private System.Windows.Forms.Label label6;
		private System.Windows.Forms.TextBox txtTModelKeys;
		private System.Windows.Forms.Label label5;
		private System.Windows.Forms.TextBox txtBusinessKey;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.TextBox name;
		private System.Windows.Forms.Button searchButton;
		private System.Windows.Forms.TreeView tvwSearchResults;
		private System.Windows.Forms.Label label3;

		private NameCollection _keywords;
		private StringCollection _tModelKeys;
		private FindQualifierCollection _qualifiers;
        private ImageList imageList1;		
		private string _uddiServerURL;
        private Button btnPostFilter;
        private CheckBox chkORAllKeys;
        private ContextMenuStrip contextMenuStrip1;
        private ToolStripMenuItem toolStripMenuItem1;

        private ToolTip toolTip1; 

		#endregion

		/// <summary>
		/// 
		/// </summary>
		private void Save_Settings()
		{			
			if (cboInquireUrl.SelectedIndex != 0 && cboInquireUrl.SelectedItem != null )
			{
				string text=cboInquireUrl.SelectedItem.ToString() ;
				cboInquireUrl.Items.Remove(cboInquireUrl.SelectedItem) ;
				cboInquireUrl.Items.Insert(0, text) ;
				cboInquireUrl.SelectedIndex=0 ;
			}			
			
		}

		/// <summary>
		/// Load settings/data saved to the app config file
		/// </summary>
		private void Load_Settings()
		{
			
			//otherwise add default items
			if ( cboInquireUrl.Items.Count == 0)
			{
                cboInquireUrl.Items.Add("http://uddi.microsoft.com/inquire");
				cboInquireUrl.Items.Add("http://www.xmethods.net/inquire");
				cboInquireUrl.Items.Add("http://uddi.ibm.com/ubr/inquiryapi");							
				cboInquireUrl.Items.Add("http://uddi.ibm.com/testregistry/inquiryapi");
				cboInquireUrl.SelectedIndex=0;											
			};

		}


		private void MyInit()
		{
			
			SelectedServiceList=null;			
			tvwSearchResults.CheckBoxes=false;

            this.toolTip1 = new System.Windows.Forms.ToolTip();
            this.toolTip1.InitialDelay = 300; //half a second delay 
            this.toolTip1.ReshowDelay = 0; 

						
			cboInquireUrl=new ComboBox ();			
			this.cboInquireUrl.DropDownWidth=280;
			this.cboInquireUrl.Location=new System.Drawing.Point(16, 40);
			this.cboInquireUrl.Name="cboInquireUrl";
			this.cboInquireUrl.Size=new System.Drawing.Size(320, 21);
			this.cboInquireUrl.TabIndex=0;						
			
			
			cboInquireUrl.Visible=true;			
			this.groupBox2.Controls.Add (cboInquireUrl);

			Load_Settings();
					
			
			btnAddSelect.Enabled=false;
            btnPostFilter.Enabled=false;
			
			//@"^(http|ftp)://(www\.)?.+\.(com|net|org)$"
			regexURL=new Regex(@"^(http|ftp)://");
		}

			
		public UDDIExplorerForm()
		{
			InitializeComponent();
			MyInit();
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
            this.components = new System.ComponentModel.Container();
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(UDDIExplorerForm));
            this.tvImageList = new System.Windows.Forms.ImageList(this.components);
            this.btnCancel = new System.Windows.Forms.Button();
            this.btnAddSelect = new System.Windows.Forms.Button();
            this.groupBox2 = new System.Windows.Forms.GroupBox();
            this.label2 = new System.Windows.Forms.Label();
            this.groupBox1 = new System.Windows.Forms.GroupBox();
            this.chkORAllKeys = new System.Windows.Forms.CheckBox();
            this.btnPostFilter = new System.Windows.Forms.Button();
            this.chkSensitive = new System.Windows.Forms.CheckBox();
            this.chkExactMatch = new System.Windows.Forms.CheckBox();
            this.btnHelp = new System.Windows.Forms.Button();
            this.label6 = new System.Windows.Forms.Label();
            this.txtTModelKeys = new System.Windows.Forms.TextBox();
            this.label5 = new System.Windows.Forms.Label();
            this.txtBusinessKey = new System.Windows.Forms.TextBox();
            this.label1 = new System.Windows.Forms.Label();
            this.name = new System.Windows.Forms.TextBox();
            this.searchButton = new System.Windows.Forms.Button();
            this.tvwSearchResults = new System.Windows.Forms.TreeView();
            this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components);
            this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
            this.label3 = new System.Windows.Forms.Label();
            this.imageList1 = new System.Windows.Forms.ImageList(this.components);
            this.groupBox2.SuspendLayout();
            this.groupBox1.SuspendLayout();
            this.contextMenuStrip1.SuspendLayout();
            this.SuspendLayout();
            // 
            // tvImageList
            // 
            this.tvImageList.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("tvImageList.ImageStream")));
            this.tvImageList.TransparentColor = System.Drawing.Color.Transparent;
            this.tvImageList.Images.SetKeyName(0, "");
            this.tvImageList.Images.SetKeyName(1, "");
            this.tvImageList.Images.SetKeyName(2, "");
            this.tvImageList.Images.SetKeyName(3, "");
            this.tvImageList.Images.SetKeyName(4, "");
            this.tvImageList.Images.SetKeyName(5, "");
            this.tvImageList.Images.SetKeyName(6, "");
            this.tvImageList.Images.SetKeyName(7, "site_icon.gif");
            this.tvImageList.Images.SetKeyName(8, "");
            this.tvImageList.Images.SetKeyName(9, "");
            this.tvImageList.Images.SetKeyName(10, "");
            this.tvImageList.Images.SetKeyName(11, "");
            this.tvImageList.Images.SetKeyName(12, "");
            this.tvImageList.Images.SetKeyName(13, "");
            this.tvImageList.Images.SetKeyName(14, "");
            // 
            // btnCancel
            // 
            this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
            this.btnCancel.FlatStyle = System.Windows.Forms.FlatStyle.System;
            this.btnCancel.Location = new System.Drawing.Point(348, 538);
            this.btnCancel.Name = "btnCancel";
            this.btnCancel.Size = new System.Drawing.Size(104, 24);
            this.btnCancel.TabIndex = 2;
            this.btnCancel.Text = "Close";
            this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
            // 
            // btnAddSelect
            // 
            this.btnAddSelect.FlatStyle = System.Windows.Forms.FlatStyle.System;
            this.btnAddSelect.Location = new System.Drawing.Point(237, 538);
            this.btnAddSelect.Name = "btnAddSelect";
            this.btnAddSelect.Size = new System.Drawing.Size(104, 24);
            this.btnAddSelect.TabIndex = 1;
            this.btnAddSelect.Text = "Add Selection(s)";
            this.btnAddSelect.Visible = false;
            this.btnAddSelect.Click += new System.EventHandler(this.btnAddSelect_Click);
            // 
            // groupBox2
            // 
            this.groupBox2.Controls.Add(this.label2);
            this.groupBox2.ForeColor = System.Drawing.SystemColors.Highlight;
            this.groupBox2.Location = new System.Drawing.Point(5, 9);
            this.groupBox2.Name = "groupBox2";
            this.groupBox2.Size = new System.Drawing.Size(448, 80);
            this.groupBox2.TabIndex = 6;
            this.groupBox2.TabStop = false;
            this.groupBox2.Text = "UDDI Registry Location";
            // 
            // label2
            // 
            this.label2.ForeColor = System.Drawing.SystemColors.ControlText;
            this.label2.Location = new System.Drawing.Point(16, 24);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(280, 16);
            this.label2.TabIndex = 0;
            this.label2.Text = "URL:";
            // 
            // groupBox1
            // 
            this.groupBox1.Controls.Add(this.chkORAllKeys);
            this.groupBox1.Controls.Add(this.btnPostFilter);
            this.groupBox1.Controls.Add(this.chkSensitive);
            this.groupBox1.Controls.Add(this.chkExactMatch);
            this.groupBox1.Controls.Add(this.btnHelp);
            this.groupBox1.Controls.Add(this.label6);
            this.groupBox1.Controls.Add(this.txtTModelKeys);
            this.groupBox1.Controls.Add(this.label5);
            this.groupBox1.Controls.Add(this.txtBusinessKey);
            this.groupBox1.Controls.Add(this.label1);
            this.groupBox1.Controls.Add(this.name);
            this.groupBox1.Controls.Add(this.searchButton);
            this.groupBox1.ForeColor = System.Drawing.SystemColors.Highlight;
            this.groupBox1.Location = new System.Drawing.Point(5, 97);
            this.groupBox1.Name = "groupBox1";
            this.groupBox1.Size = new System.Drawing.Size(448, 168);
            this.groupBox1.TabIndex = 5;
            this.groupBox1.TabStop = false;
            this.groupBox1.Text = "Search Parameters";
            // 
            // chkORAllKeys
            // 
            this.chkORAllKeys.AutoSize = true;
            this.chkORAllKeys.Checked = true;
            this.chkORAllKeys.CheckState = System.Windows.Forms.CheckState.Checked;
            this.chkORAllKeys.Location = new System.Drawing.Point(259, 111);
            this.chkORAllKeys.Name = "chkORAllKeys";
            this.chkORAllKeys.Size = new System.Drawing.Size(106, 17);
            this.chkORAllKeys.TabIndex = 14;
            this.chkORAllKeys.Text = "OR all key words";
            this.chkORAllKeys.UseVisualStyleBackColor = true;
            // 
            // btnPostFilter
            // 
            this.btnPostFilter.FlatStyle = System.Windows.Forms.FlatStyle.System;
            this.btnPostFilter.Location = new System.Drawing.Point(16, 133);
            this.btnPostFilter.Name = "btnPostFilter";
            this.btnPostFilter.Size = new System.Drawing.Size(73, 24);
            this.btnPostFilter.TabIndex = 8;
            this.btnPostFilter.Text = "Filter";
            this.btnPostFilter.UseVisualStyleBackColor = true;
            this.btnPostFilter.Click += new System.EventHandler(this.btnPostFilter_Click);
            // 
            // chkSensitive
            // 
            this.chkSensitive.Location = new System.Drawing.Point(16, 112);
            this.chkSensitive.Name = "chkSensitive";
            this.chkSensitive.Size = new System.Drawing.Size(112, 16);
            this.chkSensitive.TabIndex = 13;
            this.chkSensitive.Text = "Case sensitive";
            // 
            // chkExactMatch
            // 
            this.chkExactMatch.Location = new System.Drawing.Point(136, 108);
            this.chkExactMatch.Name = "chkExactMatch";
            this.chkExactMatch.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.chkExactMatch.Size = new System.Drawing.Size(104, 24);
            this.chkExactMatch.TabIndex = 12;
            this.chkExactMatch.Text = "Exact match";
            // 
            // btnHelp
            // 
            this.btnHelp.FlatStyle = System.Windows.Forms.FlatStyle.System;
            this.btnHelp.ForeColor = System.Drawing.SystemColors.ControlText;
            this.btnHelp.Location = new System.Drawing.Point(360, 134);
            this.btnHelp.Name = "btnHelp";
            this.btnHelp.Size = new System.Drawing.Size(72, 24);
            this.btnHelp.TabIndex = 6;
            this.btnHelp.Text = "Help";
            this.btnHelp.Click += new System.EventHandler(this.btnHelp_Click);
            // 
            // label6
            // 
            this.label6.ForeColor = System.Drawing.SystemColors.ControlText;
            this.label6.Location = new System.Drawing.Point(256, 21);
            this.label6.Name = "label6";
            this.label6.Size = new System.Drawing.Size(144, 13);
            this.label6.TabIndex = 11;
            this.label6.Text = "Compliance TModel name :";
            // 
            // txtTModelKeys
            // 
            this.txtTModelKeys.Location = new System.Drawing.Point(256, 37);
            this.txtTModelKeys.Name = "txtTModelKeys";
            this.txtTModelKeys.Size = new System.Drawing.Size(176, 20);
            this.txtTModelKeys.TabIndex = 1;
            // 
            // label5
            // 
            this.label5.ForeColor = System.Drawing.SystemColors.ControlText;
            this.label5.Location = new System.Drawing.Point(16, 21);
            this.label5.Name = "label5";
            this.label5.Size = new System.Drawing.Size(136, 13);
            this.label5.TabIndex = 9;
            this.label5.Text = "Business provider name :";
            // 
            // txtBusinessKey
            // 
            this.txtBusinessKey.Location = new System.Drawing.Point(16, 37);
            this.txtBusinessKey.Name = "txtBusinessKey";
            this.txtBusinessKey.Size = new System.Drawing.Size(232, 20);
            this.txtBusinessKey.TabIndex = 0;
            // 
            // label1
            // 
            this.label1.ForeColor = System.Drawing.SystemColors.ControlText;
            this.label1.Location = new System.Drawing.Point(16, 69);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(272, 16);
            this.label1.TabIndex = 3;
            this.label1.Text = "Web service name :";
            // 
            // name
            // 
            this.name.Location = new System.Drawing.Point(16, 85);
            this.name.Name = "name";
            this.name.Size = new System.Drawing.Size(416, 20);
            this.name.TabIndex = 2;
            this.name.TextChanged += new System.EventHandler(this.name_TextChanged);
            this.name.KeyDown += new System.Windows.Forms.KeyEventHandler(this.name_KeyDown);
            // 
            // searchButton
            // 
            this.searchButton.FlatStyle = System.Windows.Forms.FlatStyle.System;
            this.searchButton.ForeColor = System.Drawing.SystemColors.ControlText;
            this.searchButton.Location = new System.Drawing.Point(282, 134);
            this.searchButton.Name = "searchButton";
            this.searchButton.Size = new System.Drawing.Size(72, 24);
            this.searchButton.TabIndex = 5;
            this.searchButton.Text = "&Search";
            this.searchButton.Click += new System.EventHandler(this.searchButton_Click);
            // 
            // tvwSearchResults
            // 
            this.tvwSearchResults.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(212)))), ((int)(((byte)(208)))), ((int)(((byte)(200)))));
            this.tvwSearchResults.ContextMenuStrip = this.contextMenuStrip1;
            this.tvwSearchResults.ForeColor = System.Drawing.SystemColors.Highlight;
            this.tvwSearchResults.ImageIndex = 0;
            this.tvwSearchResults.ImageList = this.tvImageList;
            this.tvwSearchResults.LabelEdit = true;
            this.tvwSearchResults.Location = new System.Drawing.Point(5, 289);
            this.tvwSearchResults.Name = "tvwSearchResults";
            this.tvwSearchResults.SelectedImageIndex = 0;
            this.tvwSearchResults.Size = new System.Drawing.Size(448, 231);
            this.tvwSearchResults.TabIndex = 4;
            this.tvwSearchResults.DoubleClick += new System.EventHandler(this.tvwSearchResults_DoubleClick);
            this.tvwSearchResults.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.tvwSearchResults_AfterSelect);
            this.tvwSearchResults.MouseUp += new System.Windows.Forms.MouseEventHandler(this.tvwSearchResults_MouseUp);
            this.tvwSearchResults.MouseMove += new System.Windows.Forms.MouseEventHandler(this.tvwSearchResults_MouseMove);
            this.tvwSearchResults.MouseDown += new System.Windows.Forms.MouseEventHandler(this.tvwSearchResults_MouseDown);
            this.tvwSearchResults.Click += new System.EventHandler(this.tvwSearchResults_Click);
            // 
            // contextMenuStrip1
            // 
            this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.toolStripMenuItem1});
            this.contextMenuStrip1.Name = "contextMenuStrip1";
            this.contextMenuStrip1.Size = new System.Drawing.Size(170, 26);
            this.contextMenuStrip1.Opening += new System.ComponentModel.CancelEventHandler(this.contextMenuStrip1_Opening);
            // 
            // toolStripMenuItem1
            // 
            this.toolStripMenuItem1.Name = "toolStripMenuItem1";
            this.toolStripMenuItem1.Size = new System.Drawing.Size(169, 22);
            this.toolStripMenuItem1.Text = "Copy to clipboard";
            this.toolStripMenuItem1.Click += new System.EventHandler(this.toolStripMenuItem1_Click);
            // 
            // label3
            // 
            this.label3.ForeColor = System.Drawing.Color.Blue;
            this.label3.Location = new System.Drawing.Point(13, 273);
            this.label3.Name = "label3";
            this.label3.Size = new System.Drawing.Size(280, 16);
            this.label3.TabIndex = 7;
            this.label3.Text = "Search Results:";
            // 
            // imageList1
            // 
            this.imageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList1.ImageStream")));
            this.imageList1.TransparentColor = System.Drawing.Color.Transparent;
            this.imageList1.Images.SetKeyName(0, "");
            this.imageList1.Images.SetKeyName(1, "");
            this.imageList1.Images.SetKeyName(2, "");
            this.imageList1.Images.SetKeyName(3, "");
            this.imageList1.Images.SetKeyName(4, "");
            this.imageList1.Images.SetKeyName(5, "");
            this.imageList1.Images.SetKeyName(6, "");
            this.imageList1.Images.SetKeyName(7, "");
            this.imageList1.Images.SetKeyName(8, "");
            this.imageList1.Images.SetKeyName(9, "");
            this.imageList1.Images.SetKeyName(10, "");
            this.imageList1.Images.SetKeyName(11, "");
            this.imageList1.Images.SetKeyName(12, "");
            this.imageList1.Images.SetKeyName(13, "");
            this.imageList1.Images.SetKeyName(14, "");
            this.imageList1.Images.SetKeyName(15, "");
            this.imageList1.Images.SetKeyName(16, "");
            // 
            // UDDIExplorerForm
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.CancelButton = this.btnCancel;
            this.ClientSize = new System.Drawing.Size(458, 567);
            this.Controls.Add(this.groupBox2);
            this.Controls.Add(this.groupBox1);
            this.Controls.Add(this.tvwSearchResults);
            this.Controls.Add(this.label3);
            this.Controls.Add(this.btnCancel);
            this.Controls.Add(this.btnAddSelect);
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.Name = "UDDIExplorerForm";
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "UDDI Explorer 1.01 ";
            this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.UDDIExplorerForm_KeyDown);
            this.Load += new System.EventHandler(this.UDDIExplorerForm_Load);
            this.groupBox2.ResumeLayout(false);
            this.groupBox1.ResumeLayout(false);
            this.groupBox1.PerformLayout();
            this.contextMenuStrip1.ResumeLayout(false);
            this.ResumeLayout(false);

		}
		#endregion

		static void Main() 
		{
			
			Application.Run( new UDDIExplorerForm() );
		}

		/// <summary>
		/// Pointer of TreeNodeCollection add method
		/// </summary>		 
		delegate int AddDelegate(TreeNode treeNode);		

		private void Add_SearchResultNode(TreeNode node,TreeNodeCollection  collection)
		{			
			AddDelegate addDelegate=new AddDelegate(collection.Add );		
			tvwSearchResults.Invoke(addDelegate, new object[] {node});
			
		}

		private void Invoker(object model, object data)
		{
			model.GetType().InvokeMember(    "Text",   
				BindingFlags.Default | BindingFlags.SetProperty ,    null, 
				model,    new object[]{data});
		}

		private void Get_ServiceDetail(TreeNode serviceNode )
		{						
			GetServiceDetail gsd=new GetServiceDetail();
			gsd.ServiceKeys.Add( serviceNode.Tag.ToString() );
			
			ServiceDetail sd=gsd.Send();			
			
			UDDIService s=new UDDIService ();
			s.Name=serviceNode.Text ;
			TreeNode tnInfor=new TreeNode("Registry Information", 0,0) ;
			serviceNode.Nodes.Add(tnInfor);			
			serviceNode.Nodes.Add(new TreeNode("WSDL Description") );			
			
			foreach( BusinessService service in sd.BusinessServices )
			{
				// Show service descriptions				
				TreeNode tn=new TreeNode( "Descriptions (" + service.Descriptions.Count + ")" );
				s.Descriptions =string.Empty;
				foreach( Description d in service.Descriptions )					
				{
					tn.Nodes.Add( d.Text );
					s.Descriptions=s.Descriptions + d.Text ;                    
				}
				
				tnInfor.Nodes.Add(tn) ;				
				
				// Show binding template information
				TreeNode tn1=new TreeNode();
				tn1.Text="Bindings (" + service.BindingTemplates.Count + ")";
				
				foreach( BindingTemplate bt in service.BindingTemplates )
				{
					TreeNode tn2=new TreeNode();
					foreach( Description desc in bt.Descriptions )
					{
						tn2.Text=desc.Text;
                        s.Descriptions += "\n" + desc.Text;

						if( null != bt.AccessPoint )
						{
							
							tn2.Nodes.Add( bt.AccessPoint.URLType.ToString() );
							
							string strUrl=bt.AccessPoint.Text.ToLower() ;
							strUrl=( strUrl.IndexOf ("?wsdl") != -1 || strUrl.IndexOf ("?WSDL") != -1 ? strUrl  : strUrl + "?wsdl");
							 
							tn2.Nodes[0].Nodes.Add(strUrl);
							
							//Check if this is an valid URL							
							MatchCollection mc=regexURL.Matches(bt.AccessPoint.Text);
							
							// Add a valid webservice to Result array							
							if (mc.Count >0)
							{									
								s.Url=strUrl;
								serviceNode.Tag=s;								
							};
						}

						if( 0 < bt.TModelInstanceDetail.TModelInstanceInfos.Count )
						{
							tn2.Nodes.Add( "Binding Signatures (" + bt.TModelInstanceDetail.TModelInstanceInfos.Count + ")" );
							foreach( TModelInstanceInfo tmii in bt.TModelInstanceDetail.TModelInstanceInfos )
							{
								tn2.Nodes[1].Nodes.Add( tmii.TModelKey );
							}							
						}
						if (0 < tn2.Nodes.Count )
							tn1.Nodes.Add( tn2 );
					}
				}

				if (tn1.GetNodeCount(false) > 0 ) tnInfor.Nodes.Add(tn1);									
			}
		}

		private void Explore_Business()
		{
			FindBusiness fb=new FindBusiness();
            fb.Names.Add(txtBusinessKey.Text.Trim());
            fb.FindQualifiers.Add(FindQualifier.OrAllKeys);

			try 
			{
				BusinessList bl=fb.Send();				

				if( 0 == bl.BusinessInfos.Count )
					return ;

				foreach( BusinessInfo bi in bl.BusinessInfos )
				{			
					if (bi.BusinessKey != null)
						Find_Service (bi.BusinessKey);
				}
			}
			catch( Exception e)
			{				
				MessageBox.Show(e.Message.ToString() ) ;
			}
			finally
			{
			}
			return ;
		}

        private string OrKeyWords(string query)
        {
            ServiceRanking.Tokeniser token = new Tokeniser();
            string[] toks=token.Partition(query);
            string newQuery=string.Empty;
            foreach (string s in toks)            
                newQuery += s + ";";            

            return newQuery;
        }

		
		private void Init_FindService()
		{			
			//create qualifiers
			_qualifiers=new FindQualifierCollection() ;						
			if (chkExactMatch.Checked) 
				_qualifiers.Add(FindQualifier.ExactNameMatch );
			if (chkSensitive.Checked)
                _qualifiers.Add(FindQualifier.CaseSensitiveMatch);

            string strKeyword= name.Text.Replace(" OR ", ";").Trim();
            strKeyword = name.Text.Replace(" or ", ";").Trim();
            if (chkORAllKeys.Checked)
                strKeyword = OrKeyWords(name.Text);                         

            _qualifiers.Capacity = 1000;

            _qualifiers.Add(FindQualifier.OrAllKeys);

            string delimiter = ";";
            char[] split = delimiter.ToCharArray();

            string[] strKeywords = strKeyword.Split(split);
			
            
			_keywords=new NameCollection ();
            foreach (string keyword in strKeywords)
            {
                if (keyword != string.Empty)
                    _keywords.Add(keyword);
            }

			//create Tmodels
			_tModelKeys=new StringCollection() ;

			if (txtTModelKeys.Text.Trim() != string.Empty  )
			{
				FindTModel ftm=new FindTModel();
                ftm.FindQualifiers.Add(FindQualifier.OrAllKeys);

				ftm.Name=txtTModelKeys.Text;			   
				try
				{
					TModelList tml=ftm.Send();
					if( 0 == tml.TModelInfos.Count )
						return;
					foreach( TModelInfo tmi in tml.TModelInfos )
					{
						_tModelKeys.Add(tmi.TModelKey);					
					}
				}
				catch( Exception  )
				{				
				}
				finally
				{				
				}
			}
			
		}
		
		private void Find_Service(string BusinessKey)
		{			
			FindService fs=new FindService();					
			if (BusinessKey != string.Empty)			
				fs.BusinessKey=BusinessKey;

			//enable qualifier
			fs.FindQualifiers=_qualifiers;

			//add multi-tmodels
			if (_tModelKeys.Count > 0)
				fs.TModelKeys=_tModelKeys;
			
			//multi keywords search
			if (_keywords.Count > 0 )			
				fs.Names=_keywords;
			else
                if (name.Text.Trim() != string.Empty)
                    fs.Names.Add(name.Text.Trim());

															
			
			try			
			{				
				// Perform search				
				ServiceList sl=fs.Send();								
				
				if (sl == null)
				{
					
					//MessageBox.Show (string.Empty,"UDDI Explorer", MessageBoxButtons.OK,MessageBoxIcon.Error );
					//return;

				};

				foreach( ServiceInfo si in sl.ServiceInfos )
				{	
					//action being performed					
					TreeNode tn=new TreeNode (si.Name );												
											
					//if (runFlag == false) return;
					tn.Tag=si.ServiceKey;					
					Get_ServiceDetail (tn);					
					if (tn.Tag is UDDIService) Add_SearchResultNode (tn ,tvwSearchResults.Nodes);																
					
				};


			}
			catch( Exception)
			{
				throw;				
			}

			finally
			{
			}

		}



		private void UDDISearch()
		{
			try
			{							
				// Set the URL of the UDDI Registry to search			
				btnAddSelect.Enabled=false;

				Inquire.Url=_uddiServerURL;							
				//Inquire.AuthenticationMode=AuthenticationMode.WindowsAuthentication;				
				Inquire.AuthenticationMode=AuthenticationMode.UddiAuthentication ;
				

				Init_FindService ();

				if (txtBusinessKey.Text.Trim()  != string.Empty)
					Explore_Business();
				else
					Find_Service(string.Empty);			
				if (tvwSearchResults.Nodes.Count == 0)
				{
					
					Add_SearchResultNode (new TreeNode( "No result matched the criteria"), tvwSearchResults.Nodes );
					
				}
				//else
					//tvwSearchResults.Enabled=true;

				//add this url if the search was successful
				
						
			
			} 
			catch (UddiException e)
			{
				string strErr=string.Empty;
				switch (e.Number)
				{
					case Microsoft.Uddi.UddiException.ErrorType.E_invalidKeyPassed:
						
						strErr="UDDI exception: Please check that the entered keyword is correct";
						break;
					case Microsoft.Uddi.UddiException.ErrorType.E_busy:
						strErr="UDDI exception: Server is currently busy, please try later.";
						
						break;
					default:						
						strErr="Unknown error occured: " + e.Message.ToString ();
						break;
				}				

				MessageBox.Show(strErr) ;
			}
			catch( ThreadAbortException )
			{				
				//throw e;
			}							
			catch( WebException e)
			{											
				MessageBox.Show(e.Message.ToString() ) ;			}	
			catch( TypeInitializationException  e)
			{								
				MessageBox.Show(e.Message.ToString() ) ;			
			}
			catch (Exception e )
			{				
				
				MessageBox.Show(e.Message.ToString() ) ;
			}			
			finally
			{
                SetText set=new SetText (ChangeStatus);
                searchButton.Invoke(set, "&Search");
				if (this.Cursor == Cursors.WaitCursor )
				{
					this.Cursor = Cursors.Default ;
				}

			}
		}
        
        delegate void SetText(string Text);
        private void ChangeStatus(string Text)
        {
            searchButton.Text = Text;
            label3.Text = "Search finished ";
            tvwSearchResults.Enabled = true;
            Add_uddiServerURL();
            if (tvwSearchResults.Nodes.Count > 1)
                btnPostFilter.Enabled = true;
        }

		private void Perform_Search()
		{			
			if (searchButton.Text.Trim () == "&Search")
			{
                btnPostFilter.Enabled = false;
				_uddiServerURL=cboInquireUrl.Text.Trim() ;
				MatchCollection mc=regexURL.Matches(_uddiServerURL);
				if (mc.Count <= 0)
				{					
										
					MessageBox.Show ("The entered URL is invalid.","UDDI Explorer", MessageBoxButtons.OK, MessageBoxIcon.Error);
					return;
				};
                tvwSearchResults.Nodes.Clear();

                tvwSearchResults.Enabled = false;
					
							
				_threadStart=new ThreadStart(UDDISearch);
				_thread=new Thread(_threadStart);				
				searchButton.Text="&Stop";
				label3.Text="Searching...";
				tvwSearchResults.Focus();
				
				_thread.Start();									
				
			} 
			else
			{
				//lock(this)
			{
				searchButton.Text="&Search";
				name.Focus() ;
				tvwSearchResults.Enabled=true;
					

				label3.Text="Stopping...";
				this.Cursor=Cursors.WaitCursor;
                if (_thread != null)
                    if (_thread.IsAlive)
                        _thread.Abort();				
				// Wait for the _thread to quite terminate							
				//_thread.Join (); 
				label3.Text="Search result";
				this.Cursor=Cursors.Default ;
				_thread=null;			
				_threadStart=null;
			};
			};

			tvwSearchResults.SelectedNode=null;
		}
		
	
		private void name_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if (e.KeyCode == Keys.Enter )
			{
				Perform_Search();
			};
		}
	


		private void searchButton_Click(object sender, System.EventArgs e)
		{			
			Perform_Search();								
		}
	
		private void tvwSearchResults_Click(object sender, System.EventArgs e)
		{						
		}

	
		private void btnAddSelect_Click(object sender, System.EventArgs e)
		{
			SelectedServiceList=new UDDIServiceList ();
			SelectedServiceList.Clear ();
			foreach (TreeNode n in tvwSearchResults.Nodes )
			{					
				if (n.Tag is UDDIService && n.Checked == true )
				{														 
					SelectedServiceList.Add ((UDDIService)n.Tag);
				};
			};
			
			Save_Settings ();

			if (SelectedServiceList.Count == 0 )
			{
				
			} 
			else this.Close ();			
		}

	
		private void btnCancel_Click(object sender, System.EventArgs e)
		{
			//lock(this)
		{				
			if (_thread != null)
			{
				this.Cursor= Cursors.WaitCursor;

                if (_thread.IsAlive)
				       _thread.Abort ();				
				// Wait for the _thread to quite terminate				
				_thread.Join (); 
				this.Cursor= Cursors.Default ;
			};
		}
			this.Close() ;		
		}

		private void tvwSearchResults_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
		{			
			TreeNode tn=this.tvwSearchResults.GetNodeAt(e.X, e.Y); 

			if (tn != null && (tn.Parent != null || !(tn.Tag is UDDIService)))				
				if (tn.Checked) tn.Checked=false;
								
			//just count those at first node level
			foreach (TreeNode node in tvwSearchResults.Nodes  )
			{
				if ( node.Checked )
				{
					btnAddSelect.Enabled=true;				
					return;
				}
			}
				
			btnAddSelect.Enabled=false;			
														
		}


		private void Add_uddiServerURL()
		{
			MatchCollection mc=regexURL.Matches(_uddiServerURL);
			
			// check if this is valid url			
			if (mc.Count >0 && cboInquireUrl.Text.IndexOf (",") == -1 )
			{
				bool ok=true;
				for (int i=0; i < cboInquireUrl.Items.Count ; i++ )
				{
					if (cboInquireUrl.Items[i].ToString().Trim() == _uddiServerURL )
					{
						ok=false;
						break;
					};
				};

				if ( ok )
				{
					cboInquireUrl.Items.Insert(0 ,cboInquireUrl.Text.Trim() );
					cboInquireUrl.SelectedIndex=0;
				};
				Save_Settings ();
			};
		}

		private void UDDIExplorerForm_Load(object sender, System.EventArgs e)
		{
		
		}

		private void UDDIExplorerForm_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if (e.KeyCode == Keys.Escape )
			{
				if (_thread != null)
				{
					this.Cursor=Cursors.WaitCursor;				
					_thread.Abort ();				
					// Wait for the _thread to completely terminate				
					_thread.Join (); 
					this.Cursor= Cursors.Default ;
				};
				this.Close() ;		
			};
		}
		
		private void View_WSDLDetail()
		{
			
			if (tvwSearchResults.SelectedNode == null) return;
			
			TreeNode tnUddi= tvwSearchResults.SelectedNode.Parent ;
			if (tnUddi != null && tnUddi.Tag is UDDIService  )
			{				
				try
				{
					this.Cursor= Cursors.WaitCursor;
					tvwSearchResults.BeginUpdate() ;
					UDDIService s =(UDDIService)tnUddi.Tag;		

					s.LocationFile=s.Name + ".wsdl";	
				    
					TreeNode node=WSDLRetrieval.WSDLToNode(s, true);

					if (node != null)
					{
						node.Text=node.Text;
						tvwSearchResults.SelectedNode.Nodes.Add(node);
					}
					else
					{

						tvwSearchResults.SelectedNode.Nodes.Add(new TreeNode("Can not get the wsdl from its url"));
						tnUddi.Tag=null;					
					}
					tvwSearchResults.SelectedNode.Expand() ;
					
					tvwSearchResults.EndUpdate() ;
					this.Cursor=Cursors.Default ;
				}
				finally
				{						
					tvwSearchResults.EndUpdate() ;
					if (this.Cursor == Cursors.WaitCursor )
					{
						this.Cursor = Cursors.Default ;
					}
				}
				
			};		
		}


		

		private void tvwSearchResults_DoubleClick(object sender, System.EventArgs e)
		{
			if (tvwSearchResults.SelectedNode != null && tvwSearchResults.SelectedNode.Text.Equals( "WSDL Description" )
				&& tvwSearchResults.SelectedNode.GetNodeCount(false)  == 0
				)
			{
				View_WSDLDetail ();
			}
		}


		private void name_TextChanged(object sender, System.EventArgs e)
		{
		
		}

        private string oldVariableCaption = string.Empty;

        private void tvwSearchResults_MouseMove(object sender, MouseEventArgs e)
        {
            TreeNode tn = this.tvwSearchResults.GetNodeAt(e.X, e.Y);
            if (tn == null) return;

            string description = string.Empty;
            if (tn != null)
            {
                if (tn.Tag is string)
                {
                    description= (string)tn.Tag;
                    
                }
                else
                    if (tn.Tag is SchemaParser.NodeData)
                    {
                        SchemaParser.NodeData data = tn.Tag as SchemaParser.NodeData;
                        description = data.baseObj.ToString() + "\n";
                        description += data.Namespace + "\n";
                        description += "DataTypeName: " + data.Type + "\n";                        
                        
                    }
            }


            if (WSDLParser.SchemaHelper.IsNotEmpty(description))
            {                
                if (oldVariableCaption != tn.Text)
                {
                    oldVariableCaption = tn.Text;
                    if (this.toolTip1 != null && this.toolTip1.Active)
                        this.toolTip1.Active = false;

                    this.toolTip1.SetToolTip(this.tvwSearchResults, description);
                    this.toolTip1.Active = true; 
                }
            }
            else
                if (this.toolTip1 != null && this.toolTip1.Active)
                    this.toolTip1.Active = false;

        }

        private void tvwSearchResults_MouseDown(object sender, MouseEventArgs e)
        {
            TreeNode tn = this.tvwSearchResults.GetNodeAt(e.X, e.Y);
            if (tn != null)
            {
                _copyText = tn.Text;
            }
            else
                if (tvwSearchResults.SelectedNode != null)
                    _copyText = tvwSearchResults.SelectedNode.Text;
        }

        private void btnHelp_Click(object sender, EventArgs e)
        {
            HelpForm help = new HelpForm();
            help.Show();
        }

        private void btnPostFilter_Click(object sender, EventArgs e)
        {
            ResultFilter filter = new ResultFilter();
            TreeNode[] newOrder = filter.Rank (tvwSearchResults.Nodes, name.Text);
            tvwSearchResults.Nodes.Clear();
            tvwSearchResults.Nodes.AddRange(newOrder);

            int aaa = 0;
        }

        private void contextMenuStrip1_Opening(object sender, System.ComponentModel.CancelEventArgs e)
        {

        }

        #region CopyURLToClipboard
        //Thanks Daryl 
        Thread th;
        private void toolStripMenuItem1_Click(object sender, EventArgs e)
        {
            try
            {
                if (th != null)
                    if (th.IsAlive)
                        th.Abort();

                th=new Thread(new ThreadStart(CopySTA));
                th.ApartmentState = ApartmentState.STA;
                th.Start();
            }
            catch (Exception ex)
            {
                int aaaa = 0;
            }
        }

        [STAThread]

        private void CopySTA()
        {
          
            Clipboard.SetDataObject(_copyText);
            th.Join();
            //Thread.CurrentThread.Join();
        }

        string _copyText = string.Empty;
        private void tvwSearchResults_AfterSelect(object sender, TreeViewEventArgs e)
        {
            if (tvwSearchResults.SelectedNode != null)
                _copyText = tvwSearchResults.SelectedNode.Text;
        }

        #endregion


    }
	
}

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