我想在WCF4中开发一个非常小的服务,使用NetTcpBinding来回调提供状态信息(用户,登录,注销等)。
我的开发机器是带有Visual Studio 2010的Windows 7 64 Es,没有安装IIS。
为了创建服务,我创建了一个WCF服务应用程序项目类型并编辑了它的web.config是:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="NewBinding0" portSharingEnabled="true">
<reliableSession enabled="true" />
<security mode="None" />
</binding>
</netTcpBinding>
<mexTcpBinding>
<binding name="NewBinding1" />
</mexTcpBinding>
</bindings>
<services>
<service name="JuguesServices.JuguesPresenceService">
<endpoint address="net.tcp://localhost:57920/JuguesServices/JuguesPresenceService"
binding="netTcpBinding" bindingConfiguration="NewBinding0" contract="JuguesServices.IJuguesPresenceService" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
然后我点击“播放”按钮,端口57920上的ASP.NET Development Server启动,但抛出了这个异常:
Server Error in '/' Application.
The protocol 'net.tcp' is not supported.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: The protocol 'net.tcp' is not supported.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[InvalidOperationException: The protocol 'net.tcp' is not supported.]
System.ServiceModel.Activation.HostedTransportConfigurationManager.InternalGetConfiguration(String scheme) +98456
System.ServiceModel.Activation.HostedAspNetEnvironment.GetBaseUri(String transportScheme, Uri listenUri) +24
System.ServiceModel.Channels.TransportChannelListener.OnOpening() +12082260
System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) +274
System.ServiceModel.Channels.ReliableChannelListenerBase`1.OnOpen(TimeSpan timeout) +110
System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) +318
System.ServiceModel.Dispatcher.ChannelDispatcher.OnOpen(TimeSpan timeout) +72
[InvalidOperationException: The ChannelDispatcher at 'net.tcp://localhost:57920/' with contract(s) '"IJuguesPresenceService"' is unable to open its IChannelListener.]
System.ServiceModel.Dispatcher.ChannelDispatcher.OnOpen(TimeSpan timeout) +118
System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) +318
System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan timeout) +111
System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) +318
System.ServiceModel.Channels.CommunicationObject.Open() +36
System.ServiceModel.HostingManager.ActivateService(String normalizedVirtualPath) +184
System.ServiceModel.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath) +615
[ServiceActivationException: The service '/JuguesPresenceService.svc' cannot be activated due to an exception during compilation. The exception message is: The ChannelDispatcher at 'net.tcp://localhost:57920/' with contract(s) '"IJuguesPresenceService"' is unable to open its IChannelListener..]
System.Runtime.AsyncResult.End(IAsyncResult result) +679246
System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result) +190
System.ServiceModel.Activation.HostedHttpRequestAsyncResult.ExecuteSynchronous(HttpApplication context, String routeServiceVirtualPath, Boolean flowContext, Boolean ensureWFService) +234
System.ServiceModel.Activation.HttpModule.ProcessRequest(Object sender, EventArgs e) +355
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +148
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1
我的配置文件不正确吗?
是否可以使用ASP.NET开发服务器使用NetTcpBinding调试服务?
是否有必要使用NetTcpBinding来使用CallBacks?
PS:我试图效仿这个例子:http://www.codeproject.com/KB/WCF/WCFWPFChat.aspx
编辑: 合同:
/// <summary>
/// The service specification
/// </summary>
[ServiceContract(SessionMode = SessionMode.Required, CallbackContract = typeof(IJuguesPresenceServiceCallback))]
interface IJuguesPresenceService
{
/// <summary>
/// Registers that an user is now logged in the system, and
/// notifyes it to its contacts.
/// </summary>
/// <param name="user_id">The user identificator who logs in.</param>
/// <returns>True if the login was successfull, false elsewhere.</returns>
[OperationContract(IsOneWay = false, IsInitiating = true, IsTerminating = false)]
bool UserLogin(string user_id);
/// <summary>
/// Registers that a user is no longer logged in the system, and
/// notifies it to its contact.
/// </summary>
[OperationContract(IsOneWay = true, IsInitiating = false, IsTerminating = true)]
void UserLogout();
/// <summary>
/// Returns the contact list of a logged in user.
/// </summary>
/// <returns>The list of contacts for the user.</returns>
/// <exception cref="InvalidOperationException">When tring to get the contacts without log in.</exception>
[OperationContract(IsOneWay = false, IsInitiating = false, IsTerminating = false)]
JuguesContact[] GetContacts();
}
回调
/// <summary>
/// The events for the server-to-client communication.
/// </summary>
interface IJuguesPresenceServiceCallback
{
/// <summary>
/// Ocurrs when a contact logs in in the system.
/// </summary>
/// <param name="user_id">The identificator of the user who logged in.</param>
[OperationContract(IsOneWay = true)]
void UserLoggedIn(string user_id);
/// <summary>
/// Occurs when a contact logs out of the system.
/// </summary>
/// <param name="user_id">The identificator of the user who logged out.</param>
[OperationContract(IsOneWay = true)]
void UserLoggedOut(string user_id);
}
答案 0 :(得分:4)
您的堆栈跟踪包含对“HostedAspNetEnvironment”的引用,该引用暗示这是由IIS或内置开发服务器托管的Web项目。这将限制您使用HTTP / HTTPS。您需要查看以下选项之一:
在此处查看您的选项概述:http://msdn.microsoft.com/en-us/library/ms730158.aspx