• .net webservice 动态更换地址


    //Web服务对象    WebReference.Service1SoapClient objService = new WebReference.Service1SoapClient();
    如果你细心一点的话,右建这个构造方法查看一下转到定义试试

    这是转到定义之后最上面的五个方法大家来看一下吧

    对就是有这样五个自动生成的方法

     代码如下:
    public Service1SoapClient();        
    public Service1SoapClient(string endpointConfigurationName);
    public Service1SoapClient(Binding binding, EndpointAddress remoteAddress);
    public Service1SoapClient(string endpointConfigurationName, EndpointAddress remoteAddress);
    public Service1SoapClient(string endpointConfigurationName, string remoteAddress);

    大家一起看一下第四个方法和第五个方法
    我解释一下

     代码如下:
    //endpointConfigurationName 配置节的名称,remoteAddress配置节对象
    public Service1SoapClient(string endpointConfigurationName, EndpointAddress remoteAddress);
    //endpointConfigurationName 配置节的名称,remoteAddress配置节URL        
    public Service1SoapClient(string endpointConfigurationName, string remoteAddress);        //设置其它参数

    对就是这两个方法,我们只要修改第五个就行了,
    使用方法如下
    //Web服务对象

    代码如下:
    WebReference.Service1SoapClient objService = new WebReference.Service1SoapClient("Service1Soap","你要修改的URL例如:http://www.cckan.net/webservices.asmx");

    问题解决了,我们只要动态配置一下这个参数就行了,具体方法相信大家都会了,存储在数据库或者别的地方都是可以的。

  • 相关阅读:
    将博客搬至CSDN
    Linux-进程管理&网络管理
    MySQL架构备份之双机热备
    Linux目录结构&文件管理
    markdown文件即 .md 的基本常用编写语法
    Nginx
    Java 面试题(收集整理...ing)
    CentOS7 VS CentOS8
    Linux 学习
    vi/vim 命令整理
  • 原文地址:https://www.cnblogs.com/MR---Zhang/p/8534364.html
Copyright © 2020-2023  润新知