我已经为我的项目添加了Web服务和Web引用,并且两者都没有使用(其中一个我命名为emsBookings),因为我收到以下错误:
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.Config中,我在下面找到对emsBookings的引用:
<configuration>
//Extra stuff removed for brevity
<appSettings>
<add key="emsBookings.Service" value="https://my.fully.qualified.server/THEAPI/Service.asmx"/>
我试过了:
关于尝试什么的任何其他想法?
我对服务器的访问权限相当有限,所以挖掘根C:驱动器中的日志,或者我希望尝试以避免可能的情况。
据我所知,这是不是重复,因为我的目标是.NET 3.5,而在Property Pages中,构建目标框架是.NET Framework 3.5;我无法在任何地方找到任何对“可能重复”问题中指出的问题的客户资料。
这是VS2010的链接,显示添加到我的应用程序的服务参考:http://imgur.com/hIOCqKJ
这是一个链接,显示服务引用存在于同一命名空间(对象浏览器)中:http://imgur.com/GcJ133p
以下是一些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);
答案 0 :(得分:0)
我从你的截图中注意到你创建了一个网站并在解决方案中引用了它?
如果有,最好再创建一个ASP.NET Web应用程序并再次创建服务引用,就像您所解释的那样。
我已经完成了我自己的建议,该引用按预期工作。