Bug 4676 - Compiling errors when adding a web reference that publishes a method called Invoke
Summary: Compiling errors when adding a web reference that publishes a method called I...
Alias: None
Product: Class Libraries
Classification: Mono
Component: System.Web.Services ()
Version: unspecified
Hardware: PC Windows
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2012-04-26 16:20 UTC by danielc
Modified: 2017-11-14 04:24 UTC (History)
5 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description danielc 2012-04-26 16:20:40 UTC
Description of Problem:
When we add a web reference to a web service with a method called Invoke (in MonoDevelop), the generated code in Reference.cs does not compile.
The generated code was valid when creating a WPF app in VS2008 and when addin the web reference in VS2010.

Steps to reproduce the problem:
1. Create a web service with a method named: "Invoke"
2. Create a Android or ios project in MonoDevelop on mac or windows
3. Add a web reference to the created web service
4. Compile...

        [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://url.com/WebServices/Invoke", RequestNamespace="http://url.com/WebServices/", ResponseNamespace="http://url.com/WebServices/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
public MyResponse Invoke(string sessionId, string entityId, string command)
   object[] results = this.Invoke("Invoke", new object[] {
            return ((MyResponse)(results[0]));

*** ERRORS ***
public CMFAResponse EndInvoke(System.IAsyncResult asyncResult) {
   object[] results = this.EndInvoke(asyncResult);
   return ((CMFAResponse)(results[0]));

Actual Results:
Multiple build errors in the Reference.cs generated class. The BeginInvoke and EndInvoke methods are problematic.

Expected Results:
Successful build with generated code ok like when adding from visual studio

How often does this happen? 

Additional Information:
Comment 1 Brendan Zagaeski (Xamarin Team, assistant) 2017-11-14 00:26:56 UTC
## Old bug cleanup

Thank you for taking the time to submit this report!  I attempted to reproduce this issue based on the bug description with the latest Visual Studio for Mac and Mono versions.  I found a separate issue related to the generation of Reference.cs, and I created a new report for that:

[1] https://developercommunity.visualstudio.com/content/problem/149772/webservicediscoveryresultgeneratefiles-passes-inva.html

Apart from that issue with the `Namespace` attribute, the generated code works OK now.  In my tests with the latest versions, using `Invoke` for the web service method name did not cause any particular trouble.  I will accordingly mark this bug as "not reproducible" (no longer reproducible) at this time.  If by chance the original reporter of this bug from Comment 0 comes back to this old bug in the future and notices something missing from the testing steps described below, feel free to add a comment and set the bug status to REOPENED for further investigation.  If any other user sees a similar issue in the future, please open a new bug report with your environment information and any additional details about how to reproduce the issue.  Thanks!

## Steps followed to test

1. Download and unzip the sample web service code attached to my new report [1].

2. Rename the `HelloWorld()` method to `Invoke()` in App_Code/WebService1.cs.

3. Deploy the web service as described on [1].

4. Regenerate the Reference.cs file in Visual Studio for Mac, and re-apply the `Namespace = "http://tempuri.org/"` workaround described on [1].

5. Modify the console C# app on Windows to call the `BeginInvoke()` and `EndInvoke()` methods:

public static void Main(string[] args)
    var binding = new BasicHttpBinding();
    var endpoint = new EndpointAddress("http://contoso.azurewebsites.net/WebService1.asmx");
    var channel = new ChannelFactory<WebService1Soap>(binding, endpoint).CreateChannel();
    channel.BeginInvoke(OnMethodCompleted, channel);
    Console.WriteLine("Sent request...");

private static void OnMethodCompleted(IAsyncResult asyncResult)
    string response = ((WebService1Soap)asyncResult.AsyncState).EndInvoke(asyncResult);
    Console.WriteLine($"Response: {response}");

## GOOD Results

The request to the web service succeeds, and the application outputs the expected result:

> Sent request...
> Response: Hello World

## Testing environment info (brief)

Visual Studio 2017 for Mac ( e627d44)
Mono (2017-06/e66d9abbb27) (64-bit)

macOS 10.12.6
Comment 2 Brendan Zagaeski (Xamarin Team, assistant) 2017-11-14 04:24:57 UTC
## Correction to Comment 1

After a little additional consideration, I realized that my attempted steps to reproduce this issue in Comment 1 were not quite correct because I was using the default "Framework > Windows Communication Foundation (WCF)" setting in the "Add Web Reference" dialog in Visual Studio for Mac.  This generates a Reference.cs file that uses System.ServiceModel rather than System.Web.Services.

Despite that inaccuracy in Comment 1, this bug can still safely be considered "no longer reproducible" for 2 reasons:

1. The "Framework > .NET 2.0 Web Service" option in the "Add Web Reference" dialog no longer generates `BeginInvoke()` and `EndInvoke()` methods at all.  Instead it generates an `InvokeAsync()` method and an `InvokeCompleted` event handler to take advantage of the event-driven programming model in .NET 2.0.  I verified that this event-based code behaved correctly for a test web service with a method named `Invoke()`.

2. Since 2015 (after the open sourcing of the corresponding .NET implementation), the "Framework > .NET 2.0 Web Service" code path now uses the upstream .NET version of ServiceDescriptionImporter.cs rather than the original Mono implementation.