web服务错误CS0246:类型或命名空间名称无法找到VS2010

本文关键字:VS2010 命名空间 错误 服务 CS0246 类型 web | 更新日期: 2023-09-27 18:02:11

我已经在我的项目中添加了Web服务和Web引用,并且可以适当地使用它们(其中一个我命名为emsbooking),因为我得到以下错误:

Compiler Error Message: CS0246: The type or namespace name 'emsBookings' could not be found (are you missing a using directive or an assembly reference?)

我试着使用:

using emsBookings;

但这并没有解决问题-相反,当我添加该代码时,错误指向那一行。

我的代码是这样的:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication1
{
    public partial class _Default : System.Web.UI.Page
    {
        public string xmlRequest;
        protected void Page_Load(object sender, EventArgs e)
        {
            WebApplication1.emsBookings.GetAllBookingsRequestBody client = new WebApplication1.emsBookings.GetAllBookingsRequestBody();
            //inputs required for request
            string username = "theusername";
            string password = "thepassword";
            DateTime startDate = System.DateTime.Today;
            DateTime endDate = System.DateTime.Today;
            int buildingID = 36;
            bool viewCombo = false;
            client.UserName = username;
            client.Password = password;
            client.StartDate = startDate;
            client.EndDate = endDate;
            client.BuildingID = buildingID;
            client.ViewComboRoomComponents = viewCombo;
            emsBookings.GetAllBookingsRequest request = new emsBookings.GetAllBookingsRequest();
            request.Body = client;
            xmlRequest = request.Body.ToString();
        }
    }
}

是否有一个特定的方式,我需要引用web-引用和/或web-服务,以便在我的代码中使用它?

Web。配置我在下面找到了对emsbooking的引用:

<configuration>
    //Extra stuff removed for brevity
    <appSettings>
        <add key="emsBookings.Service" value="https://my.fully.qualified.server/THEAPI/Service.asmx"/>

我试过:

  • 重建(no success)
  • 清理/重建(no success)
  • 添加'using emsbooking;' (no success)

还有其他的想法吗?

我对服务器的访问相当有限,所以在根C:驱动器中挖掘日志或类似的东西,我想尽量避免

这是不是重复,据我所知,我的目标是。net 3.5和在属性页,构建目标框架是。net框架3.5;我找不到任何关于客户配置文件的引用,这是另一个"可能重复"问题中所指出的问题。

这里是一个链接到VS2010显示服务引用添加到我的应用程序:https://i.stack.imgur.com/en0jQ.jpg

这里是一个链接,显示服务引用存在于相同的命名空间(对象浏览器):https://i.stack.imgur.com/8e6Y7.jpg

下面是一些参考资料:

//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//     Runtime Version:4.0.30319.18444
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace WebApplication1.emsBookings {
    using System.Runtime.Serialization;
    using System;

    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0")]
    [System.Runtime.Serialization.CollectionDataContractAttribute(Name="ArrayOfInt", Namespace="http://DEA.EMS.API.Web.Service/", ItemName="int")]
    [System.SerializableAttribute()]
    public class ArrayOfInt : System.Collections.Generic.List<int> {
    }
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0")]
    [System.Runtime.Serialization.CollectionDataContractAttribute(Name="ArrayOfString", Namespace="http://DEA.EMS.API.Web.Service/", ItemName="string")]
    [System.SerializableAttribute()]
    public class ArrayOfString : System.Collections.Generic.List<string> {
    }
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
    [System.ServiceModel.ServiceContractAttribute(Namespace="http://DEA.EMS.API.Web.Service/", ConfigurationName="emsBookings.ServiceSoap")]
    public interface ServiceSoap {
        // CODEGEN: Generating message contract since element name GetAPIVersionResult from namespace http://DEA.EMS.API.Web.Service/ is not marked nillable
        [System.ServiceModel.OperationContractAttribute(Action="http://DEA.EMS.API.Web.Service/GetAPIVersion", ReplyAction="*")]
        WebApplication1.emsBookings.GetAPIVersionResponse GetAPIVersion(WebApplication1.emsBookings.GetAPIVersionRequest request);

web服务错误CS0246:类型或命名空间名称无法找到VS2010

我从你的屏幕截图中注意到你已经创建了一个网站,并在解决方案中引用?

如果有,最好创建一个ASP。NET Web应用程序并再次创建服务引用,正如您所解释的那样。

我已经执行了我自己的建议,参考文献已按预期工作。