WebServic dynamic url
How to make your Web Reference proxy URL dynamic
开发环境和部署环境,Webservice 的URL不同
需将url 配置到 web.config文件中。
Introduction
I have been asked before, how to make the URL property for a web reference to a web service in a project, configurable in a config file instead of compiled in the web reference proxy. This is most useful when you want to deploy a project with a web reference between different business environments (like between Test/QA and Production) without recompiling the project. There is a simple way to do this that requires no coding at all on the developer's part (provided you are using Visual Studio for .NET).
Getting Started
To follow this article, first you need to have a compiled web service to reference, and a project in which you wish to add a web reference. After you have added your web reference (which creates the proxy class with references to the web service for you automatically using VS .NET), you need to set your solution view to 'Show All':
This shows the Reference.cs file for the Reference.map. This is the proxy class file that VS.NET generates automatically for you when you add a web reference.
Open up this file and notice under the constructor for the proxy class that the URL is hard coded for you inside the constructor:
Changing the URL from Static to Dynamic
We are going to change the hard coded URL in the proxy class Reference.cs to a key in the web.config of the web service client project. An appSettings
section will be added automatically with the current URL, and code will be placed in theReference.cs proxy class constructor to look for the URL there. All this will be done by changing one property setting on the proxy reference.
If you look at the web reference properties (below):
you can see that there is a configuration setting called 'URL Behavior'. This setting is by default set to Static.
To make the URL in the Reference.cs map class code behind look for the web service URL in your web.config file, we need to change this setting to Dynamic:
Doing this in VS.NET does two things for you. It changes the Reference.cs file to have the code to look for the WSDL URL in the project's web.config file:
And it adds the URL as a key value to the projects web.config file under appSettings
:
Now you can set the URL to different servers for deployment in different environments, without having to change the code. You just change the URL in your config file for your project.
WebServic dynamic url的更多相关文章
- Feign Dynamic URL
原创转载请注明出处:https://www.cnblogs.com/agilestyle/p/11811932.html Project Directory Maven Dependency < ...
- Ionic 动态配置url路由的设置
随着Ionic App功能的不断增加,需要路由的url设置就越来越多,不喜欢在config函数中写一堆硬代码,一则不美,二则维护起来也麻烦,能不能把这些数据独立出来呢? 经过查找资料与各种实验,最终找 ...
- OkHttp,Retrofit 1.x - 2.x 基本使用
Square 为广大开发者奉献了OkHttp,Retrofit1.x,Retrofit2.x,运用比较广泛,这三个工具有很多相似之处,初学者可能会有一些使用迷惑.这里来总结一下它们的一些基本使用和一些 ...
- 项目二(业务GO)——跨域上传图片(请求接口)
之前,就听过“跨域上传”图片的问题,只是疏于研究,也就一再搁置,直至今天再次遇见这个不能避免的“坑”,才不得不思考一下,怎么“跨域上传”图片或者文件? 问题来源: 何为“跨域”? ——就是给你一个接口 ...
- dubbo框架揭秘之服务发布
通常情况下是通过Spring配置的方式去实现服务的发布,为了方便调试,我就不采用Spring配置的方式. DemoService demo = new DemoServiceImpl(); Appli ...
- Dubbo源码学习--服务发布(ServiceBean、ServiceConfig)
前面讲过Dubbo SPI拓展机制,通过ExtensionLoader实现可插拔加载拓展,本节将接着分析Dubbo的服务发布过程. 以源码中dubbo-demo模块作为切入口一步步走进Dubbo源码. ...
- Dubbo学习-源码学习
Dubbo概述 dubbo框架提供多协议远程调用,服务提供方可以是分布式部署.dubbo框架可以很简单的帮我们实现微服务. 此处援引官网上图片 dubbo分为客户端和服务提供方 服务方将服务注册到注册 ...
- RPC -dubbo 服务导出实现
在阅读此文章之前,我希望阅读者对Spring 扩展机制的有一定的了解,比如:自定义标签与Spring整合, InitializingBean 接口,ApplicationContextAware,Be ...
- dubbo源码分析14——DubboProtocol的export方法分析
走到了这一步也挺不容易的,把之前的暴露入口代码再列出来回顾一下: //配置为none不暴露 if (! Constants.SCOPE_NONE.toString().equalsIgnoreCase ...
随机推荐
- Idea 部署非Maven项目
参考:http://m.blog.csdn.net/z69183787/article/details/78030857 以前一直很好奇,在idea中运行tomcat,把项目部署到其中,运行起来,然后 ...
- 【poj3415-长度不小于k的公共子串个数】后缀数组+单调栈
这题曾经用sam打过,现在学sa再来做一遍. 基本思路:计算A所有的后缀和B所有后缀之间的最长公共前缀. 分组之后,假设现在是做B的后缀.前面的串能和当前的B后缀产生的公共前缀必定是从前往后单调递增的 ...
- bzoj4764: 弹飞大爷 link-cut-tree
题目传送门 这道题啊 调了一个晚上 因为写的是一个有根树和n个基环的写法 所以写得很奇怪..... 最后发现单独处理树的时候不能随意改变S(就是原来的根)不然size会出错.... #include& ...
- USACO月赛2005 january volume
2013-09-18 08:12 由题可知,ans=∑i ∑j(x[i]-x[j]) 最后整理完之后应该是不同系数的X[i]相加,所以这道题就成了求不同x[i]的系数 对于X[i],它需要减前面(i ...
- HDU1385 (Floyd记录路径)
Minimum Transport Cost Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/O ...
- (二十八)fopen与读写的标识r,r+,rb+,rt+,w+.....
fopen与读写的标识r,r+,rb+,rt+,w+..... 函数简介 函数功能: 打开一个文件 函数原型:FILE * fopen(const char * path,const char * m ...
- ApplicationCommands 应用程序常见命令
ApplicationCommands用于表示应用程序程序员经常遇到的常见命令,类似于ctrl+c 在WPF中,许多控件都自动集成了固有的命令集.比如文本框TextBox就提供了复制(Copy),粘贴 ...
- Selenium2+python自动化61-Chrome浏览器(chromedriver)【转载】
前言 selenium2启动Chrome浏览器是需要安装驱动包的,但是不同的Chrome浏览器版本号,对应的驱动文件版本号又不一样,如果版本号不匹配,是没法启动起来的. 一.Chrome遇到问题 1. ...
- Selenium2+python自动化40-cookie相关操作【转载】
前言 虽然cookie相关操作在平常ui自动化中用得少,偶尔也会用到,比如登录有图形验证码,可以通过绕过验证码方式,添加cookie方法登录. 登录后换账号登录时候,也可作为后置条件去删除cookie ...
- Photoshop CC 2015
1.Ctrl 加 + -号实现放大缩小2.Ctrl+T 自由变换3.Ctrl+D 取消选区,再选择处理完后想要选中别的区域的话要取消之前选中的区域,要不然之前的区域一直都是选中状态4.F12 将文件恢 ...