Click here to Skip to main content
12,251,264 members (41,046 online)
Click here to Skip to main content

Stats

171.4K views
2.7K downloads
109 bookmarked
Posted

UDDI Explorer: Tool for searching web services

, 20 Dec 2005
Tool for searching web service(s) and viewing their WSDL information.
UDDIExplorer_demo
WSDLParser.dll
microsoft.uddi.sdk.dll
ServiceRanking.dll
UDDI Explorer.exe
WSDLCache
Weather data from the National Digital Forecast Database NOAA's NWS.wsdl
UDDIExplorer_src
ServiceRanking
ServiceRanking.csproj.user
UDDI Explorer
microsoft.uddi.sdk.dll
UDDI Explorer.csproj.user
UDDI Explorer.resharperoptions
WSDLParser
App.ico
WSDLParser.csproj.user
//Author contact: Thanh.Dao@gmx.net
using System.Web.Services.Description;
using System.Windows.Forms;
using System.Xml;
using System.Xml.Serialization;
using Binding = System.Web.Services.Description.Binding;
using Message = System.Web.Services.Description.Message;

namespace WSDLParser
{

	public class WSDLParser 
	{		
		public TreeNode ServiceNode;								
		private XmlSchemas _schemas;
		private ServiceDescriptionCollection _services=new ServiceDescriptionCollection() ;		
		
		public WSDLParser(ServiceDescription service)
		{						
			_services.Add(service) ;
			_schemas=service.Types.Schemas ;

			if (service.Name == string.Empty) service.Name=service.RetrievalUrl;
			if (service.Name == string.Empty) service.Name=service.TargetNamespace;

			ServiceNode=new TreeNode(service.Name);		
			ServiceNode.Tag=service.Documentation ;
			ServiceNode.ImageIndex=6;
			ServiceNode.SelectedImageIndex=6;

			Parse();
			
			ServiceNode.Expand ();			
		}

		private string GetProtocol (Binding binding)
		{
			if (binding.Extensions.Find (typeof(SoapBinding)) != null) return "Soap";
			HttpBinding hb = (HttpBinding) binding.Extensions.Find (typeof(HttpBinding));						
			if (hb == null) return "";
			if (hb.Verb == "POST") return "HttpPost";
			if (hb.Verb == "GET") return "HttpGet";
			return "";
		}
		
	


	private void GetOperationFormat(OperationBinding obin, Operation oper, out SoapBindingStyle style,out SoapBindingUse inputUse, out SoapBindingUse outputUse, out string requestMessage, out string responseMessage, out TreeNode requestNode,out TreeNode responseNode)
		{
			style=SoapBindingStyle.Document;
			outputUse=SoapBindingUse.Literal;
			inputUse=SoapBindingUse.Literal;
			requestMessage=string.Empty;
			responseMessage=string.Empty;
			requestNode=null;			
			responseNode=null;
			SoapBindingStyle pStyle;
			SoapBindingUse pInputUse, pOutputUse;

			GetOperationFormat (obin, out pStyle, out pInputUse, out pOutputUse  );
			if (oper.Messages.Input != null)
			{

                XmlQualifiedName name = oper.Messages.Input.Message;
                requestNode = MessageToTreeNode(name, pInputUse);
			}			
			if (oper.Messages.Output != null)
			{
                XmlQualifiedName name = oper.Messages.Output.Message;
                responseNode = MessageToTreeNode(name, pOutputUse);
			}
												
			style=pStyle;
			outputUse=pOutputUse;
			inputUse=pInputUse;
		}

		
		void GetOperationFormat (OperationBinding obin, out SoapBindingStyle style, out SoapBindingUse inputUse, out SoapBindingUse outputUse)
		{		
			style=SoapBindingStyle.Document;
			inputUse=SoapBindingUse.Literal;
			outputUse=SoapBindingUse.Literal;
			if (obin.Extensions != null)
			{
				SoapOperationBinding sob=obin.Extensions.Find (typeof(SoapOperationBinding)) as SoapOperationBinding;
				if (sob != null) 
				{
					style = sob.Style;
					if (obin.Input != null)
					{
						SoapBodyBinding sbb0 = obin.Input.Extensions.Find (typeof(SoapBodyBinding)) as SoapBodyBinding;
						if (sbb0 != null) 
							inputUse = sbb0.Use;
					}

					if (obin.Output != null)
					{
						SoapBodyBinding sbb1 = obin.Output.Extensions.Find (typeof(SoapBodyBinding)) as SoapBodyBinding;
						if (sbb1 != null)
							outputUse = sbb1.Use;
					}
				}
			}
		}

        private Message GetMessage(XmlQualifiedName msgName)
        {
            return _services.GetMessage(msgName);
        }

		private TreeNode MessageToTreeNode(XmlQualifiedName msgName, SoapBindingUse use)
		{
            Message msg = GetMessage (msgName);
			
			TreeNode node=new TreeNode() ;
			SchemaParser somParser=new SchemaParser(_schemas);

			somParser.BindingUse=use;

			foreach (MessagePart part in msg.Parts)
			{
                TreeNode partNode = new TreeNode();

				if (part.Element == XmlQualifiedName.Empty)
				{
                    if (SchemaHelper.IsSimple(part.Type.Name))
                        partNode.Tag = part.Type.Name;
                    else
                    {
                        partNode = somParser.Translate(part.Type);
                        if (partNode.Nodes.Count > 0)
                            partNode.Nodes[0].Text = part.Name;					                        
                    }
				}
				else
				{
					partNode=somParser.Translate(part.Element);
				}

                partNode.ImageIndex = 13;
                partNode.SelectedImageIndex = 13;
                partNode.Text = part.Name;
                node.Nodes.Add(partNode);

			}

			return node;			
		}



		public TreeNode TranslateOperation(Port port, OperationBinding obin, Operation oper, string protocol)
		{
			TreeNode tnOperation=new TreeNode (oper.Name, 8 , 8);
			SoapBindingStyle style=new SoapBindingStyle() ;
			SoapBindingUse inputUse=new SoapBindingUse() ;
			SoapBindingUse outputUse=new SoapBindingUse() ;

			string requestmsg=string.Empty;
			string responsemsg=string.Empty;
			TreeNode tnInput=new TreeNode ();
			TreeNode tnOutput=new TreeNode ();			
			TreeNode tnFault=new TreeNode ("Faults");									
			
			GetOperationFormat (obin, oper, out style,out inputUse,out outputUse, out requestmsg, out responsemsg,out tnInput, out tnOutput);
 
			string operDesc=string.Empty;
			operDesc +=oper.Documentation + "\n";
			operDesc +="Style: " + style.ToString() + "\n" ;

			tnOperation.Tag=operDesc;
			

			MessageCollection messages=_services[0].Messages;			
			if (oper.Messages.Input != null)
			{
				Message messageIn=messages[oper.Messages.Input.Message.Name] ;			
				if (messageIn != null )
				{					
					
					if (tnInput == null) tnInput=new TreeNode() ;			
					tnInput.Tag=requestmsg;	
					tnInput.ImageIndex=10;
					tnInput.SelectedImageIndex=10;

					if (oper.Messages.Input.Name != null && oper.Messages.Input.Name != string.Empty)
					{
						tnInput.Text="Input: " + oper.Messages.Input.Name ;
					}
					else
						tnInput.Text="Input: " + oper.Messages.Input.Message.Name ;

					
					if (tnInput != null) tnOperation.Nodes.Add  (tnInput );
				};
			};

			if (oper.Messages.Output != null)
			{
				Message messageOut=messages[oper.Messages.Output.Message.Name] ;
				if (messageOut != null )
				{				

					if (tnOutput == null) tnOutput=new TreeNode() ;	
					tnOutput.Tag=responsemsg;
					tnOutput.ImageIndex=10;
					tnOutput.SelectedImageIndex=10;

					if (oper.Messages.Output.Name != null && oper.Messages.Output.Name != string.Empty)
					{
						tnOutput.Text="Output: " + oper.Messages.Output.Name ;
					}
					else
						tnOutput.Text="Output: " + oper.Messages.Output.Message.Name ;
					
					if (tnOutput != null) tnOperation.Nodes.Add  (tnOutput );
				};

			};
		
			foreach (OperationFault faultOp in  oper.Faults)
			{
                XmlQualifiedName faultName=faultOp.Message;
				if ( !faultName.IsEmpty )				
				{					
					TreeNode tnFaultBody=MessageToTreeNode (faultName, SoapBindingUse.Default ) ;			

					tnFault.ImageIndex=14;
					tnFault.SelectedImageIndex=14;
					if (tnFault != null)
						tnFault.Nodes.Add (tnFaultBody);
				};

			};

			if (tnFault.Nodes.Count > 0 ) tnOperation.Nodes.Add  (tnFault);

			return tnOperation;			
			
		}
		
		public void Parse()
		{			
			foreach (Service service in _services[0].Services )
			{
				TreeNode tnService=new TreeNode(service.Name) ;
				tnService.ImageIndex=12;
				tnService.SelectedImageIndex=12;
                tnService.Tag = service.ToString();

				foreach (Port port in service.Ports)
				{
					XmlQualifiedName bindName=port.Binding ;
					Binding bind=_services.GetBinding(bindName);				
					PortType portType=_services.GetPortType(bind.Type) ;

					TreeNode tnPort=new TreeNode (port.Name);
					tnPort.ImageIndex=9;
					tnPort.SelectedImageIndex=9;

					string protocol=GetProtocol (bind);
					string portDesc= port.ToString() + "\n Protocol: " + protocol + "\n";

					switch (protocol) 
					{
						case "Soap":
							{
								SoapAddressBinding ad=(SoapAddressBinding)port.Extensions.Find(typeof(SoapAddressBinding));
								portDesc += "Location: " + ad.Location + "\n";
								break;
							}
						case "HttpGet":
							{
								HttpAddressBinding ad=(HttpAddressBinding)port.Extensions.Find(typeof(HttpAddressBinding));
								portDesc += "Location: " + ad.Location + "\n";
								break;
							}
						case "HttpPost":
							{
								HttpAddressBinding ad=(HttpAddressBinding)port.Extensions.Find(typeof(HttpAddressBinding));
								portDesc += "Location: "   + ad.Location + "\n";
								break;
							}
					}
					
					tnPort.Tag=portDesc;
					foreach (OperationBinding obin in bind.Operations)					
					{							 								
						foreach (Operation oper in portType.Operations)
						if (obin.Name.Equals(oper.Name) )
						{
							TreeNode tnOper=TranslateOperation (port, obin, oper, protocol);										
							tnOper.ImageIndex=8;
							tnOper.SelectedImageIndex=8;
                            tnOper.Tag = oper.ToString();
							if (tnOper != null)
							{
								tnPort.Nodes.Add (tnOper);						
							};
						}																			
					}
			
					tnPort.Expand ();					
					tnService.Nodes.Add(tnPort) ;
				}

				ServiceNode.Nodes.Add (tnService);										
			}
		}		
	}
}

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.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Thanh Dao
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.

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.160426.1 | Last Updated 21 Dec 2005
Article Copyright 2005 by Thanh Dao
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid