我收到以下错误:
The type 'Drive_Service.DriveSessionsController', provided as the Service attribute value in the ServiceHost directive, or provided in the configuration element system.serviceModel/serviceHostingEnvironment/serviceActivations could not be found.
据我所知,如果服务名称和命名空间不一样,可能会引发这种情况,但我已经检查了大概50次,看起来和我一样。我不确定为什么我会收到此错误。
的Web.config
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0"/>
<pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/>
</system.web>
<system.serviceModel>
<protocolMapping>
<add scheme="http" binding="wsDualHttpBinding"/>
</protocolMapping>
<services>
<service name="Drive_Service.DriveSessionsController">
<endpoint address="DriveSessionsController" binding="wsDualHttpBinding" contract="Drive_Service.ISessionController"/>
<host>
<baseAddresses>
<add baseAddress="http://localhost:55534"/>
</baseAddresses>
</host>
</service>
<service name="Drive_Service.ServiceWithCallback">
<endpoint address="ServiceWithCallback" binding="wsDualHttpBinding" contract="Drive_Service.IServiceWithCallback"/>
<host>
<baseAddresses>
<add baseAddress="http://localhost:55534"/>
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
SVC标记
<%@ ServiceHost Language="C#" Debug="true" Service="Drive_Service.DriveSessionsController" CodeBehind="DriveSessionsController.svc.cs" %>
SVC代码
namespace Drive_Service
{
[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple, InstanceContextMode = InstanceContextMode.Single)]
public class DriveSessionsController : ISessionController
{
#region Fields
private Object syncRoot = new Object();
private Timer timer = new Timer();
#endregion
#region Properties
/// <summary>
/// Gets and sets the flag indicating to use the .NET 2 runtime in conjunction
/// with the assembly .NET runtime.
/// </summary>
public static bool LegacyV2RuntimeEnabledSuccessfully { get; private set; }
#endregion
#region Constructors
/// <summary>
/// Constructor.
/// </summary>
public DriveSessionsController()
{
ICLRRuntimeInfo clrRuntimeInfo = (ICLRRuntimeInfo)RuntimeEnvironment.GetRuntimeInterfaceAsObject(Guid.Empty, typeof(ICLRRuntimeInfo).GUID);
try
{
clrRuntimeInfo.BindAsLegacyV2Runtime();
LegacyV2RuntimeEnabledSuccessfully = true;
}
catch (COMException)
{
LegacyV2RuntimeEnabledSuccessfully = false;
}
timer.Elapsed += new ElapsedEventHandler(this.ProcessUpdate);
timer.Interval = 5000;
timer.Enabled = true;
timer.Start();
}
#endregion
#region Internal Members
/// <summary>
/// Interface to the common language runtime information.
/// </summary>
[ComImport]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
[Guid("BD39D1D2-BA2F-486A-89B0-B4B0CB466891")]
private interface ICLRRuntimeInfo
{
void xGetVersionString();
void xGetRuntimeDirectory();
void xIsLoaded();
void xIsLoadable();
void xLoadErrorString();
void xLoadLibrary();
void xGetProcAddress();
void xGetInterface();
void xSetDefaultStartupFlags();
void xGetDefaultStartupFlags();
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
void BindAsLegacyV2Runtime();
}
/// <summary>
/// Disconnect the client.
/// </summary>
/// <param name="sessionID">The session id.</param>
private void ClientDisconnect(string sessionID)
{
lock (syncRoot)
{
if (SessionManager.IsClientConnected(sessionID))
{
SessionManager.DeleteClient(sessionID);
}
}
}
/// <summary>
/// Generate the client data for the service.
/// </summary>
/// <returns></returns>
private ClientData GenerateClientData()
{
DataTranslator translator = new DataTranslator();
SystemData systemData = translator.GetSystemData;
ClientData data = new ClientData();
data.UpdatedData = new List<DataValue>();
data.DriveStatusExchange = DriveStatusExchange.ERROR;
foreach (DriveStatusExchange status in DriveStatusExchange.GetValues())
{
if (status.Value == systemData.Status.ToString())
{
data.DriveStatusExchange = status;
break;
}
}
data.UpdatedData.Add(new DataValue() { Symbol = data.DriveStatusExchange.Value, Value = 0 });
return data;
}
#endregion
#region External Members
/// <summary>
/// Executed when client is subscribed to notifications from server.
/// </summary>
/// <param name="clientGuid"></param>
public void SubscribeToNotifications(string clientGuid)
{
ISessionCallbackContract ch = OperationContext.Current.GetCallbackChannel<ISessionCallbackContract>();
lock (syncRoot)
{
SessionManager.BrowserValue = clientGuid;
if (!SessionManager.IsClientConnected(clientGuid))
{
SessionManager.AddCallbackChannel(clientGuid, ch);
OperationContext.Current.Channel.Closing += new EventHandler(Channel_Closing);
OperationContext.Current.Channel.Faulted += new EventHandler(Channel_Faulted);
}
}
}
/// <summary>
/// Executed when client is unsubscribed to notifications from server.
/// </summary>
public void UnsubscribeToNotifications()
{
ClientDisconnect(OperationContext.Current.Channel.SessionId);
}
#endregion
#region Events
/// <summary>
/// Process updating for each client.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ProcessUpdate(object sender, EventArgs e)
{
ClientData data = GenerateClientData();
if (SessionManager.GetCallbackChannels().Count() > 0)
{
lock (syncRoot)
{
IEnumerable<ISessionCallbackContract> allChannels = SessionManager.GetCallbackChannels();
allChannels.ToList().ForEach(c => c.SendNotificationToClients(data));
}
}
}
/// <summary>
/// Handle closing the channel.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Channel_Closing(object sender, EventArgs e)
{
IContextChannel channel = (IContextChannel)sender;
ClientDisconnect(channel.SessionId);
}
/// <summary>
/// Handle a faulted channel.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Channel_Faulted(object sender, EventArgs e)
{
IContextChannel channel = (IContextChannel)sender;
ClientDisconnect(channel.SessionId);
}
#endregion
}
}
有人看到我遗失的东西吗?
干杯。