How to call a web service with a custom url

I wrote a web service. I wrote a website. I want the website BLL code to call the web service.

I have a configuration table with this service url. I am embedding the web service url in the calling code. Which web client or socket in C # should I use that can receive a dynamic web service URL?

I thought to use:

WebClient webClient = new WebClient(); UTF8Encoding response = new UTF8Encoding(); string originalStr = response.GetString(webClient.DownloadData(BLLConfig.Current); 

But maybe there is a more elegant way?

I load configurations at runtime from a DB table.

This is how I tried using the web link in Visual Studio:

 using (var client = new GetTemplateParamSoapClient("GetTemplateParamSoap")) { TemplateParamsKeyValue[] responsArray = client.GetTemplatesParamsPerId(CtId, tempalteIds.ToArray()); foreach (var pair in responsArray) { string value = FetchTemplateValue(pair.Key, pair.Value); TemplateComponentsData.Add(pair.Key, value); } } 
0
source share
2 answers

You can add the web service URL as a web link in Visual Studio, and then set the Service.URL property from the configuration

+1
source

.NET has a lot of built-in support for using web services ... after adding a service link to your project, it generates the necessary code ... which you can use as it is - if you need to configure the URL, the client class created has the property URL that you can set appropriately ... for an excellent walkthrough, see http://johnwsaunders3.wordpress.com/2009/05/17/how-to-consume-a-web-service/ and see SOAP- xml client - using Visual Studio 2010 C # - how?

0
source

All Articles