类型或命名空间名称`HolidayService2'无法找到。你错过了装配参考吗?

时间:2018-02-18 17:23:00

标签: dll namespaces mono .net-core monodevelop

在Linux上,如何编译和执行holidayclient.cs?当然,using导入为required。还是namespace

thufir@dur:~/wsdl$ 
thufir@dur:~/wsdl$ ls
thufir@dur:~/wsdl$ 
thufir@dur:~/wsdl$ wsdl http://api.google.com/GoogleSearch.wsdl
Web Services Description Language Utility
Mono Framework v4.0.30319.42000
Error: ThereWasAnErrorDownloading0
Stack:
   at System.Web.Services.Discovery.DiscoveryClientProtocol.Download (System.String& url, System.String& contentType) [0x000b1] in <df933ee897464fb99338a340b9d5761d>:0 
  at System.Web.Services.Discovery.DiscoveryClientProtocol.DiscoverAny (System.String url) [0x0000f] in <df933ee897464fb99338a340b9d5761d>:0 
  at (wrapper remoting-invoke-with-check) System.Web.Services.Discovery.DiscoveryClientProtocol:DiscoverAny (string)
  at Mono.WebServices.Driver.Run (System.String[] args) [0x000f5] in <24b8cb9db67d4a19a4db9642439f119f>:0 
thufir@dur:~/wsdl$ 
thufir@dur:~/wsdl$ wsdl http://holidaywebservice.com/HolidayService_v2/HolidayService2.asmx
Web Services Description Language Utility
Mono Framework v4.0.30319.42000
Writing file 'HolidayService2.cs'
thufir@dur:~/wsdl$ 
thufir@dur:~/wsdl$ mcs /target:library HolidayService2.cs -r:System.Web.Services
thufir@dur:~/wsdl$ 
thufir@dur:~/wsdl$ ls
HolidayService2.cs  HolidayService2.dll
thufir@dur:~/wsdl$ 
thufir@dur:~/wsdl$ nano holidayclient.cs
thufir@dur:~/wsdl$ 
thufir@dur:~/wsdl$ cat holidayclient.cs 
using System;

class HolidayClient
{
    public static void Main (string [] args)
    {
        HolidayService2 holiday = new HolidayService2 ();

        String response = holiday.foo ("hmm");

        Console.WriteLine(response);
    }
}
thufir@dur:~/wsdl$ 
thufir@dur:~/wsdl$ mcs holidayclient.cs 
holidayclient.cs(7,9): error CS0246: The type or namespace name `HolidayService2' could not be found. Are you missing an assembly reference?
holidayclient.cs(9,27): error CS0841: A local variable `holiday' cannot be used before it is declared
Compilation failed: 2 error(s), 0 warnings
thufir@dur:~/wsdl$ 

无法确定在MonoDevelop中点击哪些按钮,因此使用了CLI。

的引用:

http://www.mono-project.com/archived/consuming_a_webservice/

http://holidaywebservice.com/HolidayService_v2/HolidayService2.asmx?op=GetHolidayDate

https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-messages/cs0246

1 个答案:

答案 0 :(得分:1)

在MonoDevelop(MD)中,您需要创建一个您想要的类型的新项目(表单,控制台,Web等),并将HolidayClient.cs代码添加到其中。您需要确保代码中的命名空间与项目中的命名空间保持一致,以保持简单。使用MD添加对HolidayService.dll程序集的引用(右键单击Project / References并选择&#34; Edit References ...&#34;然后找到.NET Assembly选项卡并按照您的鼻子浏览它并加载参考资料)。完成此操作后,您应该能够在代码中调用服务客户端。