asp.net (C #) dynamically modifying WebService addresses and ports (dynamically modifying Profiles) _ Practical Tips

Source: Internet
Author: User

The problem is not as complicated as I imagined, and we all know how to modify it directly, which is to modify the configuration section of the Webconfig file.
The specific way to look at the picture below

I believe a lot of people know that the direct modification on the line
Dynamic Modification Method
----------------------------------------------------------
So how do you change it dynamically?
I think a lot of people would say that, modify the Webconfig file, have a dedicated help class, or write your own because the webconfig is editable in the form of XML, this method is indeed feasible.
So I tell you, you're wrong, there's a simpler and more appropriate way.
Methods are as follows
The first step in using WebService should be to create objects.
Is this the case, look at the following code

Web Service object Webreference.service1soapclient objservice = new Webreference.service1soapclient ();
If you're more careful, just build this construct and look at the go to definition try

This is the top five methods that go to the definition. Let's take a look.

Yes, there are five methods that are automatically generated.

Copy Code code 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 explain.
Copy Code code as follows:

Endpointconfigurationname the name of the configuration section, remoteaddress the configuration section object
Public Service1soapclient (String endpointconfigurationname, EndpointAddress remoteaddress);
Endpointconfigurationname the name of the configuration section, remoteaddress the configuration section URL
Public Service1soapclient (String endpointconfigurationname, string remoteaddress); Set other parameters

Yes, that's the two methods, we just need to change the fifth one.
Use the following methods
Web Service objects
Copy Code code as follows:

Webreference.service1soapclient objservice = new Webreference.service1soapclient ("Service1Soap", "You want to modify the URL for example: http:/ /www.cckan.net/webservices.asmx ");

The problem is solved, we only need to dynamically configure this parameter on the line, the specific way to believe that everyone will be stored in the database or other places can be.
Don't fool around with the configuration file, WebService itself has a way of modifying

This is from: http://www.cckan.net Author: Su Fei

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.