Search code examples
c#asp.netweb-servicesweb-reference

web service error CS0246: The type or namespace name could not be found VS2010


I've added both a Web Service and a Web Reference to my project and can consume neither (one of which I named emsBookings) appropriately because I get the following error:

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

I tried using:

using emsBookings;

But that did not resolve the issue - and instead the error pointed to that line when I added that code.

My code looks like this:

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();

        }
    }
}

Is there a specific way I need to reference the web-reference and/or web-service in order to use it in my code?

In Web.Config I find reference to emsBookings in the following:

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

I've tried:

  • rebuilding (no success)
  • cleaning / rebuilding (no success)
  • adding 'using emsBookings;' (no success)

Any other ideas on what to try?

I'm fairly limited in my access to the server, so digging through logs in the root C: drive or things like that I would like to try to avoid if possible.

This is not a duplicate as far as I can tell as I am targeting .NET 3.5 and in the Property Pages, the build Target Framework is .NET Framework 3.5; I cannot find any reference to a Client Profile anywhere which was the indicated issue in the other 'possible duplicate' question.

Here is a link to the VS2010 showing the service reference added to my application: https://i.sstatic.net/en0jQ.jpg

Here is a link showing that the service reference exists in the same namespace (object browser): https://i.sstatic.net/8e6Y7.jpg

Here is some of the Reference.cs:

//------------------------------------------------------------------------------
// <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);

Solution

  • I noticed from your screenshot that you have created a website and that is referenced in the solution?

    If you have, its better to create an ASP.NET Web Application and create the service reference again, as from what you have explained.

    I have performed my own suggestion the reference has worked as expected.