我们在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的引用。示例代码如下:
this.Url = "http://localhost/Services/SimpleBlogService.asmx";
我们只要增加一个带有参数的构造函数,参数就是我们要引用的Web Service的url, 就可以实现动态添加对Web Service的引用。示例代码如下:
Your satisfaction is necessary to our success. Our goal is to provide you with the best level of customer service, and we welcome your comments and suggestions
1
public class SBSSimpleBlogService : System.Web.Services.Protocols.SoapHttpClientProtocol
2
{
3
/// <remarks/>
4
public SBSSimpleBlogService()
5
{
6
this.Url = "http://localhost/Services/SimpleBlogService.asmx";
7
}
8
9
public SBSSimpleBlogService(string url)
10
{
11
this.Url = url;
12
}
13
}
public class SBSSimpleBlogService : System.Web.Services.Protocols.SoapHttpClientProtocol 2
{3
/// <remarks/>4
public SBSSimpleBlogService()5
{6
this.Url = "http://localhost/Services/SimpleBlogService.asmx";7
}8

9
public SBSSimpleBlogService(string url)10
{11
this.Url = url;12
}13
}


浙公网安备 33010602011771号