静观己心,厚积薄发

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: :: 管理 ::

静态修改方式 ------------------------------------ 这个问题其实并没有我想像的那个复杂,我们都知道怎么直接修改吧,那就是修改WebConfig文件的配置节 具体的方法看下面图片

这个相信很多人都知道,直接修改就行了 动态修改方式 ---------------------------------------------------------- 那么怎么动态修改呢? 我想可能很多人都会这样讲,修改WebConfig文件,有专用的帮助类,也可以自己写因为WebConfig是可以Xml的形来编辑的,对的这种方法确实是可行的 那么我告诉你们,你们错了,有更简单而且更适合的方法 方法如下 大家使用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");

 

问题解决了,我们只要动态配置一下这个参数就行了,具体方法相信大家都会了,存储在数据库或者别的地方都是可以的。 不要再傻者去搞配置文件了,webservice本身就有修改的方式

posted on 2013-01-30 14:53  猎人杰  阅读(12576)  评论(3编辑  收藏  举报