【问题标题】:The type or namespace name `HolidayService2' could not be found. Are you missing an assembly reference?找不到类型或命名空间名称“HolidayService2”。您是否缺少程序集参考?
【发布时间】:2018-02-20 05:36:45
【问题描述】:

在 Linux 上,如何编译和执行holidayclient.csusing 导入当然是 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

【问题讨论】:

  • 嘿,您能否提供一些关于您想要实现的目标的背景信息?是否要添加对 Web 服务的引用并调用它?
  • 添加对已编译 dll 的引用,这是一个 Web 服务,然后调用库上的方法。是的@muszeo。 CLI 或 monodevelop (Linux)。
  • 好的,我支持你。一旦您生成了服务客户端 dll (HolidayService2.dll),那么理论上您应该能够将其添加为 MonoDevelop 中项目的引用并调用它;这将通过 / References 右键单击​​ Edit References... 对话 .NET Assembly 选项卡。我会在下面写一个答案。

标签: dll namespaces mono .net-core monodevelop


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2015-10-08
    • 1970-01-01
    • 2011-12-23
    • 2014-03-28
    • 1970-01-01
    • 2013-08-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多