This problem is actually not as complicated as I think. We all know how to directly modify it, that is, modify the configuration section of the WebConfig file.
For more information, see the following figure.
I believe many people know this. Just modify it.
Dynamic Modification Method
----------------------------------------------------------
So how can we 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, this method is indeed feasible.
So I will tell you that you are wrong. There are simpler and more suitable methods.
The method is as follows:
The first step for using Webservice is to create an object.
Check 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.
Copy codeThe Code is as follows: 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.
Let me explainCopy codeThe Code is as follows: // endpointConfigurationName indicates the name of the configuration section and remoteAddress indicates the configuration section object.
Public Service1SoapClient (string endpointConfigurationName, EndpointAddress remoteAddress );
// EndpointConfigurationName indicates the name of the configuration section, and remoteAddress indicates the URL of the configuration section.
Public Service1SoapClient (string endpointConfigurationName, string remoteAddress); // set other parameters
That's the two methods. We only need to modify the fifth method,
The usage is as follows:
// Web service objectCopy codeThe Code is as follows: 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.
This article from: http://www.cckan.net Author: su Fei