By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,680 Members | 1,666 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,680 IT Pros & Developers. It's quick & easy.

adding methods/properties runtime for web services

P: n/a
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!!

Jul 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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.
ma*************@gmail.com wrote:
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!!

Jul 21 '05 #2

P: n/a
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.

Jul 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.