问题
I want to develop a very tiny service in WCF4 with callbacks to provide presence information (users, logins, logouts, etc), using NetTcpBinding.
My development machine is a Windows 7 64 Es with Visual Studio 2010, no IIS installed.
In order to create the services I've created a WCF Service Application project type and edited its web.config is:
<?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>
Then I clicked "play" button, and a ASP.NET Development Server on port 57920 started, but this exception was thrown:
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
Is my config file incorrect?
Is it possible to debug a service using NetTcpBinding with the ASP.NET Development Server?
Is it necessary to use the NetTcpBinding to use CallBacks?
PS: I am trying to follow this example: http://www.codeproject.com/KB/WCF/WCFWPFChat.aspx
Edit: The Contract:
/// <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();
}
The callback
/// <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);
}
回答1:
Your stack trace contains a reference to "HostedAspNetEnvironment", which hints that this is a web project to be hosted by IIS or the built-in development server. This will restrict you to HTTP/HTTPS. You will want to look into one of the following options:
- Self-hosting - writing a standalone console or WinForms application that will construct a ServiceHost to host your WCF service.
- Windows service - same as self-hosting, but running inside of a managed Windows service. This is advantageous as you can run the service on a server with nobody logged in, and take advantage of Windows automatic server restart functionality.
- Windows Process Activation Service (WAS) - I don't have much experience with this, but it seems to be a stripped down version of IIS, without the restriction that services must use HTTP/HTTPS.
See an overview of your options here: http://msdn.microsoft.com/en-us/library/ms730158.aspx
来源:https://stackoverflow.com/questions/4594129/win7-vs-2010-net4-service-using-nettcpbinding-net-tcp-is-not-supported-ex