The Asp.net|web|web service uses the URL behavior properties of the ASP.net Web service proxy
Zhengzo 2005-4-6
When invoking the ASP.net Web service in vs.net, the URL behavior of the default generated proxy class is to use static values and, if the Web service is to be transferred, there is a possibility of inaccessible situations where a new proxy class needs to be generated for Web service references. This brings a lot of inconvenience to program deployment, the solution is to set the URL behavior using dynamic values, for many people do not pay attention so may not be aware of this feature, including my former colleagues, so wrote this article, some friends to provide some help, of course, the best explanation or through the example.
For example, the original Web service on 192.192.132.97, after the Web service was modified to deploy to another computer within the enterprise, IP 192.192.132.95.
Select the node under Web References in the solution that references the Web service (here Serverfilemanager is the folder name), listing the following properties:
Url:http://localhost/redmanager/web references/serverfilemanager/
URL behavior: Static
Web Reference url:http://192.192.132.97/redupload/uploadfileservice.asmx
Folder name: Serverfilemanager
It is necessary to recompile the original service correctly by modifying the new IP address 192.192.132.95.
See the constructor for the generation of the proxy class as follows:
Public Uploadfileservice ()
{
This. URL = "http://192.192.132.95/redupload/uploadfileservice.asmx";
}
That's where the problem lies, and it's all written dead in it.
Here's the solution.
Modify URL behavior value is dynamic, Web. Config, the following configuration information is added to the
<appSettings>
<add key= "RedManager.ServerFileManager.UpLoadFileService" value= "http://192.192.132.95/RedUpload/ Uploadfileservice.asmx "/>
</appSettings>
Let's see what happens to the constructor of the service proxy class.
Public Uploadfileservice ()
{
String urlsetting = system.configuration.configurationsettings.appsettings[" RedManager.ServerFileManager.UpLoadFileService "];
if ((urlsetting!= null))
{
This. URL = string. Concat (Urlsetting, "");
}
Else
{
This. URL = "http://192.192.132.95/redupload/uploadfileservice.asmx";
}
}
Since then, we can adjust the program by modifying the configuration information in the Web.config configuration file without recompiling the code.
If you use the command line, you can do this through the Web Service Description Language tool (Wsdl.exe).
Wsdl.exe/urlkey:redmanager.serverfilemanager.uploadfileservice "http://192.192.132.95/redupload/ Uploadfileservice.asmx
Or
Wsdl.exe/appsettingurlkey:redmanager.serverfilemanager.uploadfileservice "http://192.192.132.95/RedUpload/ Uploadfileservice.asmx
From the above, you can see that the <add key= "value="/> is added to the configuration file, and the way in which personal feeling is implemented better is to use a special element node to include this information. does not mix with other information under appsettings, like a database connection string in. NET framework2.0, has a specific setting. This article refers to the "Microsoft.NET Program Design Technology Insider."
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.