使用 Visual Studio 2010,我们有一个包含多个网站(不是 Web 应用程序项目)以及命令行和 winforms 项目的解决方案。所有目标.Net 2.0。许多项目在网站中都有对 ASMX Web 服务的 Web 引用。
Web 服务经常更改,因此当我们编译所有内容时,我们必须手动浏览所有项目并更新 Web 服务引用。我现在已经成功地使用disco.exe和wsdl.exe自动化了这个。但我担心wsdl.exe生成的代码和VS中手动更新网页参考的差异。
wsdl.exe 生成如下代码:
public WebServiceName() {
string urlSetting = System.Configuration.ConfigurationManager.AppSettings["WebServiceName"];
if ((urlSetting != null)) {
this.Url = urlSetting;
}
else {
this.Url = "http://example/webservicename.asmx";
}
}
虽然 VS 生成这样的代码:
private bool useDefaultCredentialsSetExplicitly;
public WebServiceName() {
this.Url = global::ProjectName.Properties.Settings.Default.ProjectName_WebServiceNameWebService_WebServiceName;
if ((this.IsLocalFileSystemWebService(this.Url) == true)) {
this.UseDefaultCredentials = true;
this.useDefaultCredentialsSetExplicitly = false;
}
else {
this.useDefaultCredentialsSetExplicitly = true;
}
}
public new string Url {
get {
return base.Url;
}
set {
if ((((this.IsLocalFileSystemWebService(base.Url) == true)
&& (this.useDefaultCredentialsSetExplicitly == false))
&& (this.IsLocalFileSystemWebService(value) == false))) {
base.UseDefaultCredentials = false;
}
base.Url = value;
}
}
public new bool UseDefaultCredentials {
get {
return base.UseDefaultCredentials;
}
set {
base.UseDefaultCredentials = value;
this.useDefaultCredentialsSetExplicitly = true;
}
}
private bool IsLocalFileSystemWebService(string url) {
if (((url == null)
|| (url == string.Empty))) {
return false;
}
System.Uri wsUri = new System.Uri(url);
if (((wsUri.Port >= 1024)
&& (string.Compare(wsUri.Host, "localHost", System.StringComparison.OrdinalIgnoreCase) == 0))) {
return true;
}
return false;
}
其他一切基本相同。我需要担心这个吗?这当然意味着我们必须更改覆盖 URL 在 app.config 和 web.config 文件中的存储方式。wsdl.exe 使用 appSettings,VS 使用 configSections/applicationSettings。
PS:我知道 ASMX 是旧的,而 WCF 是新的。我被这个困住了。
更新:发现这篇文章讨论了差异:
如何跨多个 Web 应用程序项目共享动态 URL
http://weblogs.asp.net/bradleyb/archive/2006/05/04/445133.aspx