Web Service Proxy Code Generated by WSDL.exe Versus "Update Web Reference" - Should I Care?

Tom Winter picture Tom Winter · Jan 21, 2012 · Viewed 10.2k times · Source

Using Visual Studio 2010, we have a solution with several web sites (not web application projects) and command line and winforms projects. All target .Net 2.0. Many of the projects have web references to the ASMX web services in the web sites.

The web services change frequently, so when we compile everything, we have to manually go through all the projects and update the web service references. I have now succeeded in automating this using disco.exe and wsdl.exe. But I'm concerned about the differences in the code generated by wsdl.exe and a manual update of the web reference in VS.

wsdl.exe generates code like this:

public WebServiceName() {
    string urlSetting = System.Configuration.ConfigurationManager.AppSettings["WebServiceName"];
    if ((urlSetting != null)) {
        this.Url = urlSetting;
    }
    else {
        this.Url = "http://example/webservicename.asmx";
    }
}

While VS generates code like this:

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

Everything else is basically the same. Do I need to worry about this? It certainly means we'd have to change how the override URLs are stored in app.config and web.config files. wsdl.exe uses appSettings, VS uses configSections/applicationSettings.

P.S.: I know ASMX is old and WCF is new. I'm stuck with this.

UPDATE: Found this article that talks about the difference:

How to share dynamic URLs across multiple Web Application Projects

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

Answer

Tom Winter picture Tom Winter · Feb 10, 2012

Since no one has responded (yeah Tumbleweed!), I'll at least post what I found. If you really want to see how the VS code is generated, it's inside Microsoft.VSDesigner.dll. My machine has 8.0 and 9.0 versions. Here's the path. I don't know if this will match what's on your system:

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

If you open it with Reflector, look at the GenerateCode method in Microsoft.VSDesigner.CodeGenerator.DiscoCodeGenerator. This calls the ServiceDescriptionImporter.GenerateWebReferences method to generate the base code, as Wsdl.exe does, then it modifies the code to get the VS result.