Linux下用CLI编译holidayclient.cs遇CS0246错误及相关问题咨询
Fixing the CS0246 Error ("Cannot find type or namespace 'HolidayService2'")
This error pops up because your compiler has no idea what HolidayService2 is—you're missing the auto-generated proxy class that communicates with the remote ASMX web service. Here's how to fix it:
- Generate the web service proxy using Mono's
wsdltool. This tool fetches the service's WSDL definition and creates a C# class file with all the necessary types and methods to interact with the service:
This will output a file (usually namedwsdl http://holidaywebservice.com/HolidayService_v2/HolidayService2.asmx?WSDLHolidayService2.cs) that contains theHolidayService2type and its related classes.
Linux CLI Compilation & Execution Steps
Since you prefer using the CLI over MonoDevelop, follow these step-by-step instructions:
1. Prepare Your Client Code
Create your holidayclient.cs file. You'll need to:
- Add a
usingstatement for the namespace defined in the generated proxy file (check the top ofHolidayService2.cs—it’s likelyHolidayService2). - You can wrap your client code in its own namespace (good practice, but not strictly required).
Example holidayclient.cs:
using System; using HolidayService2; // Import the namespace from the generated proxy namespace HolidayClient { class Program { static void Main(string[] args) { // Initialize the service client var holidayService = new HolidayService2SoapClient(); // Example: Fetch New Year's Day 2024 for the US var holidayDate = holidayService.GetHolidayDate("NewYearsDay", 2024, "UnitedStates"); Console.WriteLine($"New Year's Day 2024 (US): {holidayDate.ToShortDateString()}"); } } }
2. Compile the Code
Use Mono's mcs compiler to compile both the proxy file and your client file together. You’ll need to reference the System.Web.Services.dll assembly, which handles web service communication:
mcs /r:System.Web.Services.dll HolidayService2.cs holidayclient.cs
This will generate an executable file named holidayclient.exe.
3. Run the Executable
Execute the compiled program using Mono:
mono holidayclient.exe
Quick Note on Namespaces
- The generated proxy will have its own namespace (e.g.,
HolidayService2), so your client code must either use that namespace withusingor fully qualify the type (likeHolidayService2.HolidayService2SoapClient). - Adding your own namespace to the client code helps organize your code, but it’s not mandatory for the program to run.
Content of this question originates from Stack Exchange, asked by Thufir

