Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Web Services / October 2005

Tip: Looking for answers? Try searching our database.

Idiomatic way to change web service endpoint at runtime.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Andy - 07 Oct 2005 14:44 GMT
If I use Visual Studio.Net 2003 to generate "web references" for clients
using either sproxy.exe (for C++) client or wsdl.exe (for C#) clients, the
web service endpoint gets "baked" into the generated code, making it
difficult, if not impossible, to change the server that the client connects
to at runtime.

e.g. sproxy.exe generated code that looks like this ...

static const _soapmap __CCluProvider_GetCertificate_atlsoapheader_map =
{
 0xF0E178D2,
 "GetCertificate",
 L"GetCertificateResponse",
 sizeof("GetCertificate")-1,
 sizeof("GetCertificateResponse")-1,
 SOAPMAP_HEADER,
 __CCluProvider_GetCertificate_atlsoapheader_entries,
 0,
 0,
 -1,
 SOAPFLAG_NONE | SOAPFLAG_PID | SOAPFLAG_DOCUMENT | SOAPFLAG_LITERAL,
 0x2C42131A,
 "http://localhost/CluServer/",
 L"http://localhost/CluServer/",
 sizeof("http://localhost/CluServer/")-1
};

and wsdl.exe generate code like this ...

   /// <remarks/>
   [System.Diagnostics.DebuggerStepThroughAttribute()]
   [System.ComponentModel.DesignerCategoryAttribute("code")]
   [System.Web.Services.WebServiceBindingAttribute(Name="CluProviderSoap",
Namespace="http://localhost/CluServer/")]
   public class CluProvider :
System.Web.Services.Protocols.SoapHttpClientProtocol {

       /// <remarks/>
       public CluProvider() {
           this.Url = "http://localhost/CluServer/CluProvider.asmx";
       }

       /// <remarks/>

[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://localhost
/CluServer/CanConnect", RequestNamespace="http://localhost/CluServer/",
ResponseNamespace="http://localhost/CluServer/",
Use=System.Web.Services.Description.SoapBindingUse.Literal,
ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
       public bool CanConnect() {
           object[] results = this.Invoke("CanConnect", new object[0]);
           return ((bool)(results[0]));
       }

Is there an elegent, idiomatic technique for changing the server endpoint at
runtime with these "generated" proxies or is it necessary to 'hand craft'
your own proxy code if you want to change the server at runtime?

Changing the server endpoint at runtime seems like a reasonable thing to
want to do, or have I missed something?

Andy
Nathan Craddock - 07 Oct 2005 15:05 GMT
You can either set the type to dynamic in the web reference in VS.Net, or
you can use the publicly accessible "Url" property on the generated class to
change the url at runtime prior to executing web methods on it.

I.E:

MyClientClass o = new MyClientClass();
o.Url = "http://MyServer/MyWebService.asmx";
o.MyWebMethod();

> If I use Visual Studio.Net 2003 to generate "web references" for clients
> using either sproxy.exe (for C++) client or wsdl.exe (for C#) clients, the
[quoted text clipped - 60 lines]
>
> Andy
Andy - 07 Oct 2005 16:02 GMT
> You can either set the type to dynamic in the web reference in VS.Net, or

I will try that and see what the generated code looks like.

> you can use the publicly accessible "Url" property on the generated class to

Hmmm.  Does that really work?
I thought about that but when I saw all of the string literals 'baked in' to
the proxy code I thought it would be unlikely to work.

Andy

> You can either set the type to dynamic in the web reference in VS.Net, or
> you can use the publicly accessible "Url" property on the generated class to
[quoted text clipped - 39 lines]
> >    [System.Diagnostics.DebuggerStepThroughAttribute()]
> >    [System.ComponentModel.DesignerCategoryAttribute("code")]

[System.Web.Services.WebServiceBindingAttribute(Name="CluProviderSoap",
> > Namespace="http://localhost/CluServer/")]
> >    public class CluProvider :
[quoted text clipped - 6 lines]
> >
> >        /// <remarks/>

[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://localhost
> > /CluServer/CanConnect", RequestNamespace="http://localhost/CluServer/",
> > ResponseNamespace="http://localhost/CluServer/",
> > Use=System.Web.Services.Description.SoapBindingUse.Literal,

ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
> >        public bool CanConnect() {
> >            object[] results = this.Invoke("CanConnect", new object[0]);
[quoted text clipped - 10 lines]
> >
> > Andy
Nathan Craddock - 07 Oct 2005 17:10 GMT
The VS.Net web reference thing is pretty much just a placeholder for
settings so it can run WSDL when you do "Update Web Reference".

Also, if you notice in the generated class for C#, the literals in the
constructor are actually being applied to "this.Url" which is the same
publicly accessible property I was suggesting you set. Setting that Url
property immediately after instantiating the object is pretty standard, I
think. It's how I've always done it, and it's never given me any problems.

>> You can either set the type to dynamic in the web reference in VS.Net, or
>
[quoted text clipped - 92 lines]
>> >
>> > Andy

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.