locked
WSDL parsing with C# code

    Question

  •  

    I have a need to manually parse WSDL documents and after some research stumbled upon the ServiceDescription class which looks like it fit what I need to do.

     

    I can see that I can loop through the WSDL message tree to some degree, but there appear to be a few short comings.

     

    Thanks to some code I found I can see doing this:

     

    Code Snippet

    XmlTextReader reader = new XmlTextReader("http://localhost/foxcentral/foxcentral.asmx?WSDL");

    ServiceDescription wsdl =

    ServiceDescription.Read(reader);

    foreach (PortType pt in wsdl.PortTypes)

    {

    Console.WriteLine("PortType {0}", pt.Name);

    foreach (Operation op in pt.Operations)

    {

    Console.WriteLine("\tOperation: {0}\r\n\t", op.Name,op.Documentation );

    foreach (OperationMessage msg in op.Messages)

    {

    if (msg is OperationInput)

    {

    Console.WriteLine("\t\tInput Message: {0}", msg.Message);

    OperationInput oi = msg as OperationInput;

    }

    else if (msg is OperationOutput)

    Console.WriteLine("\t\tOutput Message: {0}", msg.Message);

    else

    Console.WriteLine("\t\tFault Message: {0}", msg.Message);

    }

    }

    }

     

    and while that gets me the name of the messages, I can't seem to figure out how to drill further down into the input and output messages to retrieve the parameter names and types. Along the same lines I also can't get any special message types for 'complex type' published by the service.

     

    I also noticed parsing through the service description that the documentation fields are all blank even though the service I'm working against publishes documenation.

     

    Anybody done something like this before? I know this must be possible given that WSDL.EXE basically uses this mechanism, but I can't seem to find the right objects to look at <s>...

     

    Any help or pointers appreciated...

     

    +++ Rick ---

     

    Saturday, May 26, 2007 10:53 PM

Answers

  • I think you've drilled down as far as you can for that portion of the ServiceDescription.  The ServiceDescription class also has a Messages collection and which will contain information about parts (parameter names and types) for that message.  At that point you should be able to correlate the name of the input/output message to the name of the message.

     

    Hope this helps.

    Tuesday, May 29, 2007 8:04 PM

All replies

  • I think you've drilled down as far as you can for that portion of the ServiceDescription.  The ServiceDescription class also has a Messages collection and which will contain information about parts (parameter names and types) for that message.  At that point you should be able to correlate the name of the input/output message to the name of the message.

     

    Hope this helps.

    Tuesday, May 29, 2007 8:04 PM
  • In order to help anyone who had the same problem: Mike Hadlow implemented a class named WebServiceInfo. This class simply encapsulates the ServiceDescription class. It´s perfect for people like me. I just needed a collection of WeMethods and its parameters.

     

    Please take a look at http://mikehadlow.blogspot.com/2006/06/simple-wsdl-object.html 

     

    Cheers,

    Marden Menezes

     

    Thursday, May 15, 2008 9:18 PM
  • Hi,

    Marden Menezes Post is helpful.

    Thanks.


    Frank Xu Lei--谦卑若愚,好学若饥
    专注于.NET平台下分布式应用系统开发和企业应用系统集成
    Focus on Distributed Applications Development and EAI based on .NET
     

    老徐的网站】:http://www.frankxulei.com/

    微软WCF中文技术论坛
    微软WCF英文技术论坛

    Windows Azure中文技术论坛

    Thursday, March 03, 2011 5:35 AM