views:

320

answers:

5

Hi.

I have a web based system where users should be able to fetch data from a web service by entering the URL and the necessary parameter values.

My problem is, somehow I need to find out the structure of the parameters required in the soap body, which is not necessarily just one or two strings, but could be a whole object tree.

Transmission is not a problem, since it's just plain XML.

How do I do this? Do I need to read the entire WSDL Schema and try to figure this out or is there some easier way? I know .NET can generate code for it, but can I easily find out what classes would have been generated without actually generating it and use reflection to find out what it did?

Does anyone have an idea?

A: 

I've never done it, but I believe .net allows you to generate proxies dynamically. You should then be able to reflect the generated classes. I can't see this working well for anything but simple interfaces.

JohnOpincar
I've already tried that. However that creates new assemblies that I have to load in order to reflect on them. Unfortunately those assemblies can not easily be unloaded (unless creating a new AppDomain) even if they will never be used again, which is why I'd like to find out the parameters without actually creating and loading an assembly.
janzi
+3  A: 

You can use the ServiceDescription Class, which gives you an object model representing your wsdl file.

If you want to try a useful wrapper, chick this post.

Gulzar
This could have solved my problem, if it were not for two things:1. The wrapper only gets the first level of parameters. If the parameter is of a complexType, I still don't get the definition for that complex type. However this can be easily solved with some modifications to the code.2. At least one of the test WSDL files I'm using has bindings for both Soap, HttpGet, and HttpPost. I can't seem to programmatically figure out which one is the Soap one. Any idea how I can do that using the ServiceDescription class?
janzi
A: 

Hi,

I see 3 options:

a) Contact the publisher of the web service and ask for documentation and code samples.

b) Use Visual Studio to generate the proxy classes. Then study the generated code to figure out how you could do it yourself without the generated code. You will need to understand how the XMLSerializer class works because this the class that is used to convert generated types to XML.

c) Read the WSDL description to understand the expected parameters and their format.

Hope this helps,

Sly

Sly
The problem is that I do not know which web services the system will communicate with in advance. If I knew that, I could as well add the Web Reference to it and use that instead. I'm basically trying to provide a way for my users to import data from other systems on demand.
janzi
janzi - I'm sorry; I did not understand that you needed to discover and invoke services at run time. You are basically going to rewrite the Add Web Service Reference logic to discover what the service is and how to invoke it. In that case, I don’t know any way other than parsing the WSDL.
Sly
A: 

Try using ChannelFactory. That will let you dynamically call a webservice at run time and create the proxy client. I saw your comment about loading and unloading assemblies. Use the client proxy with reflection and when your done just dispose it.

Joshua Belden
A: 

This problem is difficult to solve for the general case. What if one of the "parameters" of the service is an XML document? What if it's a complex type? How will you generate a UI to permit entry of such things?

You might also look into soapUI.

BTW, creating a new AppDomain to load assemblies into is not difficult. In fact, it's pretty easy.

John Saunders