4

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

Web 服务经常更改,因此当我们编译所有内容时,我们必须手动浏览所有项目并更新 Web 服务引用。我现在已经成功地使用disco.exewsdl.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

4

1 回答 1

4

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

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

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

于 2012-02-10T16:21:12.640 回答