Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
See more:
Fellow Programmers, please help before I tear out my hair!

I'm dynamically creating a web service from a wsdl file that has input and output parameters. When those parameters are generic variables (i.e strings, integers, chars...) I can call the methods and get my information just fine. However the webservices that I have to call have output parameters that are custom classes (possibly casted from object arrays, I think). When I try to invoke a method on that web service it says that the method is not found. I know that it's because of an incorrect signature but I can't figure out how to call the method with the correct signature. I can get the type of the custom class (because I know what it should be) but when I try to create an instance of that type dynamically it still doesn't work. I've even tried using an object type with no success. Does this make sense? I can give more info if needed. Thank you in advance!
Posted
Comments
Manfred Rudolf Bihy 20-Jan-11 13:08pm    
Sounds very interesting to me! 5+
Since I don't have anything useful to contribute I'll just watch and see what the others come up with.

This may seem like a stupid question, but do you have those custom types defined in your own application? Essentially, you'd have to have an assembly with them in it on both sides of the connection.
 
Share this answer
 
v2
Using a generic object instance will not work. As you say, you need to instantiate an object of this custom type. Based on what you wrote, it seems you could not get that working. Please post some code so we know what you mean.

Creating the type dynamically may not be trivial depending on how complex the type is. So you may not be creating it properly.
 
Share this answer
 
@John Simmons
I don't have the custom type defined specifically because I'm creating the web service during runtime, which leads to me to my next statement:
@Nishant Sivakumar
I've tried instantiating the type like so:
Type type = invoker.webServiceAssembly.GetType("GetInventory_blocRow");
var instance = Activator.CreateInstance(type);

invoker.webServiceAssembly is the compiled assembly of type System.Reflection.Assembly. I'm creating as var because I don't know what to declare it as. Using instance as my argument still yields the same error :-(

It seems that creating the type this way does work though because I can see all of the fields of this class during a breakpoint, but the methods still doesn't like it.

Here is the signature of the compiled assembly using Reflector.Net
C#
public string GetInventory(string site, string part, string wolot, out GetInventory_blocRow[] bloc);
 
Share this answer
 
v2
Comments
Yusuf 20-Jan-11 16:02pm    
Please add your input as "Comment" to the answers, not as an answer. You can do that by clicking the "add comment" link below the answer on the bottom right hand side.
jay1_z 20-Jan-11 16:04pm    
Sorry, I've never posted on here before.
I found the answer! The problem was right in front of my face! :sigh:

Looking at the GetInventory() method signature:

public string GetInventory(string site, string part, string wolot, out GetInventory_blocRow[] bloc);


You'll see that the out parameter GetInventory_blocRow is an array because it'll be returning multiple rows of data. When I was creating my type, it was just a single instance variable. I needed to create an array of my types. Once I realized that (after some much needed sleep) I found this [^]link. The answer I got from there was, instead of creating my instance like this:
Type type = invoker.webServiceAssembly.GetType("GetInventory_blocRow");
var instance = Activator.CreateInstance(type);

I can create it like this:
Type type = invoker.webServiceAssembly.GetType("GetInventory_blocRow");
System.Collections.IList instance = Array.CreateInstance(type,10);

I can then use instance as my argument!

Thank you very much for your assistance you guys! I really appreciate your time!

Now I just need to figure out how to make the array dynamic since I won't know how many records I'll be getting back.
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900