动态添加对Web Service的引用

/* from:http://www.cnblogs.com/dudu/archive/2004/03/14/3119.html */

 我们在VS.NET中静态添加Web Service引用时,会生成一个Web References方件夹, 显示这个文件夹中的所有文件,我们会发现Reference.cs文件,打开这个文件,里面定义了一个从System.Web.Services.Protocols.SoapHttpClientProtocol继承的类,在它的构造函数中,有这样的初始化语句:
this.Url = "http://localhost/Services/SimpleBlogService.asmx";
我们只要增加一个带有参数的构造函数,参数就是我们要引用的Web Service的url, 就可以实现动态添加对Web Service的引用。示例代码如下:
public class SBSSimpleBlogService : System.Web.Services.Protocols.SoapHttpClientProtocol
{
        /// <remarks/>
         public SBSSimpleBlogService()
        {
           
this.Url = "http://localhost/Services/SimpleBlogService.asmx";
        }

         public SBSSimpleBlogService(string url)
       
{
        
  this.Url = url;
        }
}

参考文章: http://www.codeproject.com/cs/webservices/CallXMLWebServices.asp

原文地址:https://www.cnblogs.com/kofkyo/p/2297305.html