468,272 Members | 2,073 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,272 developers. It's quick & easy.

ServiceDescription.Types: Getting Type Information From Wsdl

I'm currently working an .net application (I can use 1.1 or 2.0 if needed)
that needs to read a wsdl file and generate another piece of code that can
use it. I'm encountering a problem where I cannot extract all of the type
information from the wsdl using any standard tools. I'm using HttpGet style
webservices if that makes any difference, but I want to be able to use any
type.

1. I've tried the ServiceDescription.Types and I cannot get the information
that way.
2. I've also tried using wsdl.exe, compiling the proxy, and the reflecting
on it. However, I've discovered that wsdl.exe only generates objects
representing the return type not the input type.
3. I've also tried using ServiceDescription and ServiceDescriptionImporter,
so that I would be able to walk the CODEDom;however, when I try that I get an
error that says NoCodeGenerated, yet wsdl.exe can generate it just fine.

If anyone has any suggestions workarounds 3rd party api's I'm extremely
interested. I'll use beta software :)
Nov 23 '05 #1
2 7429

"Danny Gagne" <Danny Ga***@discussions.microsoft.com> wrote in message
news:D6**********************************@microsof t.com...
I'm currently working an .net application (I can use 1.1 or 2.0 if needed)
that needs to read a wsdl file and generate another piece of code that can
use it. I'm encountering a problem where I cannot extract all of the type
information from the wsdl using any standard tools. I'm using HttpGet
style
webservices if that makes any difference, but I want to be able to use any
type.

1. I've tried the ServiceDescription.Types and I cannot get the
information
that way.
2. I've also tried using wsdl.exe, compiling the proxy, and the
reflecting
on it. However, I've discovered that wsdl.exe only generates objects
representing the return type not the input type.
3. I've also tried using ServiceDescription and
ServiceDescriptionImporter,
so that I would be able to walk the CODEDom;however, when I try that I get
an
error that says NoCodeGenerated, yet wsdl.exe can generate it just fine.

If anyone has any suggestions workarounds 3rd party api's I'm extremely
interested. I'll use beta software :)


I think using the ServiceDescriptionImporter class is your best bet. As far
as I know wsdl.exe uses this same ServiceDescriptionImporter class
internally to generate code from WSDL, so it should be able to process the
WSDL. Can you show us the code you are using and the WSDL?

Regards,
Sami
Nov 23 '05 #2
I wrote up a quick example:

C# code:

using System;
using System.IO;
using System.Web.Services.Description;
using System.Xml;
using System.CodeDom;

namespace ServiceDescriptionTest
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class ServiceTest
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
Console.WriteLine ("Starting Test");

try
{
TextReader stringReader = new StreamReader ("test.wsdl");

Test (stringReader.ReadToEnd());
}
catch (Exception e)
{
Console.WriteLine ("Exception: " + e);
}

Console.WriteLine ("Test Over, press return");
Console.ReadLine ();
}

static void Test (string wsdl)
{
StringReader stream = new StringReader (wsdl);
XmlTextReader reader = new XmlTextReader (stream);

if (!ServiceDescription.CanRead (reader))
throw new Exception ("Unable to read the wsdl file: " +wsdl);

ServiceDescription service = ServiceDescription.Read (reader);
ServiceDescriptionImporter importer = new ServiceDescriptionImporter();

//possible protocols: SOAP (default), HttpGet, HttpPost
//importer.ProtocolName = "HttpGet"; -- commented out because it syas
it's not a valid protocol

importer.AddServiceDescription(service, "", "");

CodeNamespace @namespace = new CodeNamespace(ServiceDescription.Namespace);
CodeCompileUnit program = new CodeCompileUnit();

program.Namespaces.Add (@namespace);

ServiceDescriptionImportWarnings warnings = importer.Import(@namespace,
program);

Console.WriteLine("ServiceDescriptionImportWarning s value generated: " +
warnings.ToString());
}
}
}

WSDL:

<definitions xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:s="http://www.w3.org/2001/XMLSchema"
xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
xmlns:s0="http://mitre.org/"
targetNamespace="http://mitre.org/" name="MapQuestService">
<types>
<s:schema targetNamespace="http://mitre.org/">
<s:import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
<s:import namespace="http://schemas.xmlsoap.org/wsdl/"/>
<s:complexType name="AddressRequest">
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="address"
type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="zipcode"
type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="country"
type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="state"
type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="city"
type="s:string"/>
</s:sequence>
</s:complexType>
<s:element name="Map" type="s:string"/>
</s:schema>
</types>
<message name="GetMapRequestHttpGetIn">
<part name="GetMapRequest" type="s0:AddressRequest"/>
</message>
<message name="GetMapResponseHttpGetOut">
<part name="Body" element="s0:Map"/>
</message>
<portType name="MapQuestHttpGet">
<operation name="Get-Map">
<input message="s0:GetMapRequestHttpGetIn"/>
<output message="s0:GetMapResponseHttpGetOut"/>
</operation>
</portType>
<binding name="MapQuestHttpGet" type="s0:MapQuestHttpGet">
<http:binding verb="GET"/>
<operation name="Get-Map">
<http:operation location="homesubmit"/>
<input>
<http:urlEncoded/>
</input>
<output>
<mime:mimeXml part="Body"/>
</output>
</operation>
</binding>
<service name="MapQuestService">
<port name="MapQuestHttpGetPort" binding="s0:MapQuestHttpGet">
<http:address location="http://www.mapquest.com/maps/map.adp"/>
</port>
</service>
</definitions>
"Sami Vaaraniemi" wrote:

"Danny Gagne" <Danny Ga***@discussions.microsoft.com> wrote in message
news:D6**********************************@microsof t.com...
I'm currently working an .net application (I can use 1.1 or 2.0 if needed)
that needs to read a wsdl file and generate another piece of code that can
use it. I'm encountering a problem where I cannot extract all of the type
information from the wsdl using any standard tools. I'm using HttpGet
style
webservices if that makes any difference, but I want to be able to use any
type.

1. I've tried the ServiceDescription.Types and I cannot get the
information
that way.
2. I've also tried using wsdl.exe, compiling the proxy, and the
reflecting
on it. However, I've discovered that wsdl.exe only generates objects
representing the return type not the input type.
3. I've also tried using ServiceDescription and
ServiceDescriptionImporter,
so that I would be able to walk the CODEDom;however, when I try that I get
an
error that says NoCodeGenerated, yet wsdl.exe can generate it just fine.

If anyone has any suggestions workarounds 3rd party api's I'm extremely
interested. I'll use beta software :)


I think using the ServiceDescriptionImporter class is your best bet. As far
as I know wsdl.exe uses this same ServiceDescriptionImporter class
internally to generate code from WSDL, so it should be able to process the
WSDL. Can you show us the code you are using and the WSDL?

Regards,
Sami

Nov 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by David | last post: by
1 post views Thread by Marko | last post: by
7 posts views Thread by stephan querengaesser | last post: by
4 posts views Thread by Martin Ehrlich | last post: by
reply views Thread by Thomas.Koerfer | last post: by
reply views Thread by Steve | last post: by
reply views Thread by shaily | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by zattat | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.