簡體   English   中英

WSDL.exe生成的Web服務代理代碼與“更新Web引用” - 我應該關心嗎?

[英]Web Service Proxy Code Generated by WSDL.exe Versus “Update Web Reference” - Should I Care?

使用Visual Studio 2010,我們有一個包含多個網站(而不是Web應用程序項目)和命令行和winforms項目的解決方案。 所有目標.Net 2.0。 許多項目都在Web站點中提供了對ASMX Web服務的Web引用。

Web服務經常更改,因此當我們編譯所有內容時,我們必須手動完成所有項目並更新Web服務引用。 現在,我已經成功地自動執行此使用disco.exeWsdl.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。

PS:我知道ASMX很老,而WCF是新的。 我堅持這個。

更新:發現這篇文章談到了差異:

如何跨多個Web應用程序項目共享動態URL

http://weblogs.asp.net/bradleyb/archive/2006/05/04/445133.aspx

由於沒有人回應(是的Tumbleweed!),我至少會發布我發現的內容。 如果你真的想看看如何生成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結果。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM