Static modification method---------------------------------- This problem is actually not as complicated as I think. We all know how to directly modify it, that is, to modify the configuration section of the WebConfig file. See the following picture.
I believe many people know this. Just modify it.Dynamic Modification Method------------------------------------------------------------ How to modify it dynamically? I think many people may say this in this way, modifying the WebConfig file has a dedicated help class, or you can write it yourself because WebConfig can be edited in Xml format, the correct method is indeed feasible, so I tell you, you are wrong, there are simpler and more suitable methods: the first step for using Webservice should be to create an object, right? See the following code.
// Web service object WebReference. Service1SoapClient objService = new WebReference. Service1SoapClient ();
If you are more careful, right-click the constructor to view the definition and try again.
This is the top five methods after definition. Let's take a look.
There are five automatic generation methods.
public Service1SoapClient(); public Service1SoapClient(string endpointConfigurationName); public Service1SoapClient(Binding binding, EndpointAddress remoteAddress); public Service1SoapClient(string endpointConfigurationName, EndpointAddress remoteAddress); public Service1SoapClient(string endpointConfigurationName, string remoteAddress);
Let's take a look at the fourth and fifth methods.
// EndpointConfigurationName: the name of the configuration section. The remoteAddress configuration section object is public Service1SoapClient (string endpointConfigurationName, EndpointAddress remoteAddress). // The Name Of The endpointConfigurationName configuration section, string remoteAddress); // set other parameters
For the two methods, we only need to modify the fifth method. The method is as follows:
// Web service object webreference. service1soapclient objservice = new webreference. service1soapclient ("service1soap", "the URL you want to modify, such as: http://www.cckan.net/webservices.asmx ");
After the problem is solved, we only need to dynamically configure this parameter. The specific method will be fine for everyone. It can be stored in the database or somewhere else. Do not be stupid enough to get the configuration file. The WebService itself has a way to modify it.