Tom*_*ter 5 c# wsdl web-services asmx disco
使用 Visual Studio 2010,我们有一个包含多个网站(不是 Web 应用程序项目)以及命令行和 winforms 项目的解决方案。所有目标都是.Net 2.0。许多项目在网站中都有对 ASMX Web 服务的 Web 引用。
Web 服务经常变化,因此当我们编译所有内容时,我们必须手动遍历所有项目并更新 Web 服务引用。我现在已成功使用disco.exe和wsdl.exe自动化此操作。但我担心 wsdl.exe 生成的代码与 VS 中的 Web 参考的手动更新之间的差异。
wsdl.exe 生成如下代码:
public WebServiceName() {
string urlSetting = System.Configuration.ConfigurationManager.AppSettings["WebServiceName"];
if ((urlSetting != null)) {
this.Url = urlSetting;
}
else {
this.Url = "http://example/webservicename.asmx";
}
}
Run Code Online (Sandbox Code Playgroud)
而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;
}
Run Code Online (Sandbox Code Playgroud)
其他一切都基本相同。我需要担心这个吗?这当然意味着我们必须更改覆盖 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
由于没有人回复(是的,风滚草!),我至少会发布我发现的内容。如果您确实想了解 VS 代码是如何生成的,它位于 Microsoft.VSDesigner.dll 内部。我的机器有8.0和9.0版本。这是路径。我不知道这是否与您系统上的内容匹配:
C:\Windows\assembly\GAC_MSIL\Microsoft.VSDesigner\8.0.0.0__b03f5f7f11d50a3a\Microsoft.VSDesigner.dll
Run Code Online (Sandbox Code Playgroud)
如果你用Reflector打开它,看看GenerateCode中的方法Microsoft.VSDesigner.CodeGenerator.DiscoCodeGenerator。这会调用该ServiceDescriptionImporter.GenerateWebReferences方法来生成基本代码,就像 Wsdl.exe 所做的那样,然后修改代码以获取 VS 结果。
| 归档时间: |
|
| 查看次数: |
11062 次 |
| 最近记录: |