Change web proxy method attribute at run time

J

Jeff User

Here is what I have and what I would like to do:
I am building a web client application.
I add a web reference to some web service server to my project so that
now I can call the web service.
A proxy class is generated for me. This is nice. It works!
Now, the method that is generated in the proxy class has an attribute
preceding it that, among other things, contains the web address of the
web service and the particular method at that service to be called
like this:
System.Web.Services.Protocols.SoapRpcMethodAttribute("http://some.machine/service/procedure",
, RequestNamespace="urn:querywsdl",
ResponseNamespace="urn:querywsdl")]

There will be more than one web service with the same interfaces
available for use. I will not know there names or locations at design
time. I would like to use this proxy class that I already have to
access the various different web services. Apparently the attribute
above controls where my call will go.

Is there some way to change this attribute value at run time? I tried
to create a variable and plug it in for the first value like this:

string MyParamater = "http://Set_this_machine_loc/at_run/time"
and then plug that in like this:
System.Web.Services.Protocols.SoapRpcMethodAttribute(MyParamater,
, RequestNamespace="urn:querywsdl",
ResponseNamespace="urn:querywsdl")]

which causes a compile error "An attribute argument must be a constant
expression, typeof expression or array creation expression"
OK, so I cant plug in a variable. Is there some way to reuse this
proxy code while changing the destination service address and
procedure name at run time?
Would I have to write my own proxy class at some lower level?
Is there a way to intercept this message before it is sent to make the
change?

Any suggestions, links, how to are much needed and appreciated.

Thanks in advance
Jeff
 
G

Guest

I may be misunderstanding all the meaning in your post, but the Service proxy
that you get from a WebReference contains a .Url property. This is all you
need to set prior to making a call to determine where the call is sent.
Peter
 
J

Jeff User

Peter
OK, I see that and it appears to work!

Then what is the meaning/purpose of the url in the attribute:
System.Web.Services.Protocols.SoapRpcMethodAttribute("http://some.machine/service/procedure",
, RequestNamespace="urn:querywsdl",
ResponseNamespace="urn:querywsdl")] ?

If I change "proxyClass.this.Url" to point to whatever service I want
to use, does the hard coded original service address (on the
attribute) affect anything? If not, can it be removed from that
attribute?

Thanks
Trying to learn all I can about this stuff
Jeff
 

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

Top