【发布时间】:2012-01-21 01:24:46
【问题描述】:
使用 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。
P.S.:我知道 ASMX 是旧的,而 WCF 是新的。我被这个困住了。
更新: 发现这篇讨论差异的文章:
如何在多个 Web 应用程序项目之间共享动态 URL
http://weblogs.asp.net/bradleyb/archive/2006/05/04/445133.aspx
【问题讨论】:
-
哇! 1000 人查看了这个问题(获得了徽章!),但没有人发表评论或回答。我很想听听对此的一些想法。我想这样做是不是疯了?你找到别的方法了吗?等等。
标签: c# web-services wsdl asmx disco