How to create a proxy class without a WSDL document?

A

Attila

Hello,

I'm new to web services, so please forgive my ignorance. I need to
create an interface with a third party Web Service. From what I
understand about Web Services, I need to create a proxy class that
will let me call the Web Methods that are expose by the third party's
Web Service. However, the third party doesn't provide a WSDL document.
What they do provide in their documentation is the names of the
available "transactions" (which I assume is their word for Web
Methods), and also DTD's that are used by the transactions.
If I'm correct in that I need to create a proxy class, how would I
be able to do this without a WSDL document? Should I be able to do
this with just the method names, and the DTDs?
Any help would be much appreciated.

Thanks,
Attila
 
D

Dino Chiesa [Microsoft]

Hey Attila,
What's the third party?
What is the web services stack they use?
Can you show us the documentation?

All current, compliant web services stacks do WSDL. It is one of the
primary interop standards for web services.

Could it be that this third party does not actually expose web services at
all, but instead exposes a REST-ful XML interface ? In which case you
wouldn't need to use a WSDL and a generated proxy, but you'd need to send
XML docs of a well known format (Defined by the DTDs) to corresponding HTTP
endpoints. ? Or could it be XML-RPC ? In which case you'd need an XML-RPC
stack for .NET (there is at least one 3rd party implementation).

If not, then you could try to reverse-engineer the service and independently
construct your own WSDL, which would correspond to the wsdl-less service you
have, then generate a proxy from it. Start by converting the DTDs to XML
schema. Then, to zero in on the WSDL you may need to iterate over WSDL
designs and the messages each version generates. You can use wsdl /server
to generate a server stub corresponding to a given wsdl - this will give you
something to invoke against while iterating. Also check out proxytrace,
which will let you examine your xml messages on the wire.

-Dino
 
A

Attila

Thank you for your response. I recently contacted the third parties
technical support, and their response was "our interface is not a .NET
web service." Their documentation states "The XML Gateway supports
HTTPS post transactions using the XML -based file types." Originally,
I thought that sending XML over HTTP was considered a Web Service,
although this appears to not be the case.
Given that, I'm not sure how to proceed. Any there any MSDN
articles that you think would be helpful?

Thanks,
Attila
 
D

Dino Chiesa [Microsoft]

Attila, I would agree, XML over HTTP is not web services. But still a
useful mechanism. REST-ful.

If you want to programmatically make an HTTP Post from within an app, then
try something like

private static string PostURI(string URI, string Parameters)
{
string CommandURI = URI;
WebRequest myWebRequest = WebRequest.Create(CommandURI);

//needed only if outbound traffic must go through a proxy server
//WebProxy proxyObject = new WebProxy("http://proxyserver:80/",true);
//myWebRequest.Proxy = proxyObject;

myWebRequest.ContentType = "application/x-www-form-urlencoded";
myWebRequest.Method = "POST";
byte [] bytes = System.Text.Encoding.ASCII.GetBytes(Parameters);
myWebRequest.ContentLength = bytes.Length;
Stream OutputStream = myWebRequest.GetRequestStream ();
OutputStream.Write (bytes, 0, bytes.Length);
OutputStream.Close ();
WebResponse MyWebResponse = myWebRequest.GetResponse();
Stream MyStream = MyWebResponse.GetResponseStream();
StreamReader MyStreamReader = new StreamReader(MyStream);
return MyStreamReader.ReadToEnd().Trim();
}

and call it like so:
String result= PostURI("https://server/whatever",
"arg1=7&arg2=42&arg3=Dino");


This approach (XML over HTTP) doesn't give you webservices goodness, like a
WSDL file that defines the interface, a tool that translates the interface
into platform-specific type definitions and request proxy classes (eg,
wsdl.exe). In other words, it's up to your app to make sure you are
sending the right request and parsing the response properly. There are
some pieces of .NET that may help, for example xsd.exe and the xml
serialization classes.

If you know the schema of the response you can generate a type corresponding
to that schema like so:
xsd.exe /c schema.xsd

Then you can instantiate that generated type from the returned string, by
using XML serialization and a StringReader. Like so:

System.Xml.Serialization.XmlSerializer s = new
System.Xml.Serialization.XmlSerializer(typeof(MyGeneratedType));
System.IO.StringReader sr = new
System.IO.StringReader(returnedString);
MyGeneratedType instance = s.Deserialize(sr);


-D
 
A

Attila

I must be missing something. The request that I send to the third
party is also supposed to be XML. I'm not sure that I can send the
parameters as you suggest.

I did create a class file, based on the request DTD, using the xsd.exe
tool. However, while I was able to create an object based on the
class, none of the properties (XML elements) were available to me.
When I view the class in the object browser it shows the properties,
but I get a compilation error when I try to access the properties in
my code. I'm not sure what the problem is.

Attila
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top