c#动态改变webservice的url访问地址
时间:2021-10-08 20:13:03
1、添加一个App.config配置文件。
2、配置服务http://Lenovo-PC:80/EvisaWS/WharfService?wsdl,那么在上面的文件中就会自动生成服务的配置:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="WharfWSBeanBinding" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://Lenovo-PC:80/EvisaWS/WharfService"
binding="basicHttpBinding" bindingConfiguration="WharfWSBeanBinding"
contract="WharfService.WharfWSBean" name="WharfService" />
</client>
</system.serviceModel>
</configuration>
3、动态添加新的地址,后面的?wsdl没有也可以:
WharfWSBeanClient c = new WharfWSBeanClient("WharfService", "新的地址例如:http://192.168.1.194/EvisaWS/WharfService?wsdl");
4、新服务器的地址可以存放到注册表或者环境变量里面,下面是新存放到注册表,然后再存放到环境变量里,访问的时候先从环境变量里面获取:
4.1 存到注册表:
RegistryKey key = Registry.LocalMachine.CreateSubKey(@"Software\Client");
key.SetValue("ip", "192.168.1.1");
4.2 从注册表获取值:
String ip =Environment.GetEnvironmentVariable("myconfigip");
if (ip == null || ip.Equals(""))
{
RegistryKey key = Registry.LocalMachine.OpenSubKey(@"Software\Client");
ip = key.GetValue("myip") as string;
Environment.SetEnvironmentVariable("myconfigip", ip);
}
上面是先从环境变量里面取,如果没有则从注册表取,之后又存放到环境变量里,以后在进程内访问时直接从环境变量里面取就可以了。
标签:c#,webservice,url
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
java读取cvs文件并导入数据库
2023-11-25 01:23:13
SPRING IOC注入方式过程解析
2023-10-11 12:59:13
![](https://img.aspxhome.com/file/2023/4/66944_0s.png)
SpringBoot应用jar包启动原理详解
2022-07-08 09:45:48
![](https://img.aspxhome.com/file/2023/2/69122_0s.png)
java分页工具类的使用方法
2023-08-17 02:00:14
java异常处理执行顺序详解try catch finally
2022-10-01 04:10:10
![](https://img.aspxhome.com/file/2023/2/62122_0s.png)
使用eclipse创建java项目的方法
2022-10-15 04:41:00
![](https://img.aspxhome.com/file/2023/0/64010_0s.jpg)
java导出数据库的全部表到excel
2023-11-25 09:38:33
Java读文件修改默认换行符的实现
2023-11-29 08:24:32
Spring如何在一个事务中开启另一个事务
2021-08-30 17:29:15
Mybatis-Spring源码分析图解
2023-07-18 13:35:07
![](https://img.aspxhome.com/file/2023/1/57601_0s.png)
解决nacos项目启动报错:Connection refused: no further informa问题
2023-08-16 16:55:41
![](https://img.aspxhome.com/file/2023/1/65201_0s.jpg)
如何在MyBatis中实现DataSource
2021-11-29 13:49:48
![](https://img.aspxhome.com/file/2023/0/68560_0s.png)
SpringBoot使用JWT实现登录验证的方法示例
2023-09-19 19:12:10
![](https://img.aspxhome.com/file/2023/9/63689_0s.png)
Spring注解之@Lazy注解使用解析
2023-08-28 23:12:23
SpringBoot JS-SDK自定义微信分享的实现
2023-11-10 05:08:28
![](https://img.aspxhome.com/file/2023/6/59256_0s.jpg)
移动开发Spring Boot外置tomcat教程及解决方法
2023-08-25 11:47:33
详解Java中的封装、继承、多态
2022-09-24 06:26:23
java中利用List的subList方法实现对List分页(简单易学)
2022-06-18 23:33:09
通过JDK源码学习InputStream详解
2022-09-10 19:50:29
Maven工程打包jar的多种方式
2022-12-15 06:54:46
![](https://img.aspxhome.com/file/2023/6/67686_0s.png)