c# - 由 WSDL.exe 生成的 Web 服务代理代码与 "Update Web Reference"- 我应该关心吗?

标签 c# web-services wsdl asmx disco

使用 Visual Studio 2010,我们有一个包含多个网站(不是 Web 应用程序项目)以及命令行和 winforms 项目的解决方案。所有目标.Net 2.0。许多项目在网站上都有对 ASMX 网络服务的网络引用。

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";
    }
}

当 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

最佳答案

由于没有人回应(是的风滚草!),我至少会发布我发现的内容。如果你真的想看看 VS 代码是如何生成的,它在 Microsoft.VSDesigner.dll 中。我的机器有8.0和9.0两个版本。这是路径。我不知道这是否与您系统上的匹配:

C:\Windows\assembly\GAC_MSIL\Microsoft.VSDesigner\8.0.0.0__b03f5f7f11d50a3a\Microsoft.VSDesigner.dll

如果你用Reflector打开它,看Microsoft.VSDesigner.CodeGenerator.DiscoCodeGenerator中的GenerateCode方法。这称为 ServiceDescriptionImporter.GenerateWebReferences方法生成基本代码,就像 Wsdl.exe 一样,然后它修改代码以获得 VS 结果。

关于c# - 由 WSDL.exe 生成的 Web 服务代理代码与 "Update Web Reference"- 我应该关心吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8949945/

相关文章:

c# - 如何从linq中获取int值

c# - C# 中具有复杂初始化的静态字符串变量

c# - 从 powershell 调用 api 时,空值来自 Post 方法(FromBody)

c# - VS2010 Framework 3.5 中的 Web 服务中的方法在本地运行时未显示

android - 使用 Xamarin 的 Paypal REST API

xml - 使用 XPath 从 WSDL 文件中导入的 ("xsd:import") 架构获取 XML 元素声明

c# - 核心库的异常架构

xml - 通过 Web 服务将文件作为字节数组发送时会产生多少额外开销?

python - 在哪里调用对模型具有依赖性的外部 API?

java - 让 JAX-WS 生成带有命名空间参数的代码?