adding methods/properties runtime for web services

  • Thread starter Thread starter manohar.shankar
  • Start date Start date
M

manohar.shankar

Hi,

I have been searching on this topic for quite sometime and didnt get
any answer.
Is there a way I can extend/add methods/properties to a C# class during
runtime.

eg.,
I have class:
public class MyClass {
private string identity;
}

So when running the program using this class I want to add a attribute
called "name" of type "string". Or say I want to make this class extend
some other class in runtime. Or add method called getIdentity() in
runtime.

Is any of the above possible? Or is it too much to ask?

To give you some background as to why I need this. We are using wsdl
tool to generate client proxy classes using .wsdl file. We need to add
some extra re-wiring to the classes generated in addition to the
relationships already in the schema which was part of wsdl file.

Or is it possible to override wsdl generation and catch the events
generated to add additional code during generation.

Any suggestion/documentation pointing to these aspects will be very
helpful.

Thanks in advance for all the help!!
 
You can create new types with new methods at runtime using
Reflection.Emit, but I really don't think that is what you want.

The WSDL proxy files do not have to be created at runtime (I'm not even
sure how to do that). They can be created at design time by adding a
reference to a web service using VS.NET, or using the WSDL.EXE tool.
Both solutions create a .cs class file, which you are free to edit
during design time to add whatever methods you need.
 
First of all thanks very much for the quick responses.

Joshua,
I am using the wsdl.exe to generate the .cs file. My problem is it only
generates properties for the elements in the schema. Its very difficult
to navigate to a different object if the element points to a identity
for a different class type in schema.

eg.,
if there is an employee having an element for job which is part of a
different projection. The schema will have employee-type having
job-type's identity as reference. But to access the job object once
this schema is generated into a client proxy .cs file, to access the
job object for this employee, you need to go through all the jobs and
compare the identities of those with the identity in the employee
object.

I just want to have method called getJob() on employee which will do
this plumbing. My plan is to some how catalog all the objects coming in
and out through soap requests, something like having hashmap with
identity, object mapping. Implement methods which go to this hashmap
and get objects.

I dont know how much of this made sense, but this definitely requires
adding additional methods to classes generated using wsdl.exe. Even if
I can override this tool to trigger some events which I can catch and
add my own methods is also fine.

Ash, thanks for the link, will try to go through it and see whether its
useful for me.
 
Back
Top