Showing posts with label runtime. Show all posts
Showing posts with label runtime. Show all posts

Wednesday, March 28, 2012

Web Service (Dynamic URL)

Hi,

Is there a way to connect to a Web Service dynamically at runtime (Web
Reference URL)? I have always used Visual Studio to create a Web Reference
and then used it in my code. However, that always requires the URL to the
Web Service to be the same on the staging site and the production site. Now
I have two instances of the same application running (Staging site and
Production) and want to store the URL in a file instead. Is there a way to
do this?

ex. Web.Config AppSetting <add key="WebServiceURL"
Value=http://...webserv.asmx
Thank you
Maz.You can dynamically set the URI of a web service using web.config but you
need to edit the proxy class to do it. You can get to the proxy class
through the object browser (or you can open it directly by navigating through
the web references folder structure). Once in the proxy class, just look for
the URI and replace it with a read from your web.config.

One drawback to this is that if you need to regenerate your proxy class,
you'll need to update the URI again.

HTH
--
http://www.davefancher.com
Maziar Aflatoun wrote:
> Hi,
> Is there a way to connect to a Web Service dynamically at runtime (Web
> Reference URL)? I have always used Visual Studio to create a Web Reference
> and then used it in my code. However, that always requires the URL to the
> Web Service to be the same on the staging site and the production site. Now
> I have two instances of the same application running (Staging site and
> Production) and want to store the URL in a file instead. Is there a way to
> do this?
> ex. Web.Config AppSetting <add key="WebServiceURL"
> Value=http://...webserv.asmx>
> Thank you
> Maz.

I just have a web.config setting (in appSettings) like this:

<add key="MyApp.localhost.MyService"
value="http://10.10.10.1/VirDir/MyService.asmx"/
I have a Web Reference to my service on localhost that I use for testing
and development. If I want to point to somewhere else this entry
redirects to another location without having to modify anything else.

HTH!

Matt

Thursday, March 22, 2012

Web Service Ref.

Afternoon,

I have a ObjectDataSources tied to a xyz.service at design time by adding webRef.

At runtime is it possible to change the URL of xyz.service.

I have SAME service running on multiple servers, and transactions are site specific so based on transaction type I have to switch the URL of the WebRef added at the desgin time or initially added on web.config.

Any other alternate or help would be appreciated.

Regards,

ZEB

qzeb:

Afternoon,

I have a ObjectDataSources tied to a xyz.service at design time by adding webRef.

At runtime is it possible to change the URL of xyz.service.

I have SAME service running on multiple servers, and transactions are site specific so based on transaction type I have to switch the URL of the WebRef added at the desgin time or initially added on web.config.

Any other alternate or help would be appreciated.

Regards,

ZEB

qzeb --

Here is an alternate design that might solve your design problem.

For such a design, one could probably use just one web service as a TrafficRouter. All web service consumers call the same service, the TrafficRouter, passing in a parameter that is TransactionType. Have the TrafficRouter run the switching logic and route to the correct URL (or ClassLibrary code) based on the given TransactionType. One could manage the set of URLs in the TrafficRouter's web.config file, (provided the list of URLs is not too long) or one could keep the URLs in a database and have the TrafficRouter lookup the correct URL based on the given TransactionType key. And so on.

This pattern has the added advantage of minimizing surface area exposure, which is a generally desirable design goal. All one has to do is expose one web service, the TrafficRouter. The others services can live securely behind a firewall on the friendly site of the physical architechture.

HTH.

Thank you.

-- Mark Kamoski


Thanks for quick response; I had thought about it; but its kind of late & worth to Explore around.

Regards,

ZEB