Win7 + VS 2010 + .NET4: служба, использующая NetTcpBinding: исключение net.tcp не поддерживается - PullRequest
1 голос
/ 04 января 2011

Я хочу разработать очень маленькую службу в WCF4 с обратными вызовами для предоставления информации о присутствии (пользователи, логины, выходы из системы и т. Д.) С использованием NetTcpBinding.

Моя машина для разработки - Windows 7 64 Es с Visual Studio 2010, 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>

Затем я нажал кнопку «играть», и сервер разработки ASP.NET на порту 57920 запустился, но было выдано это исключение:

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

Мой конфигурационный файл неверен?

Можно ли отладить службу с помощью NetTcpBinding с сервером разработки ASP.NET?

Необходимо ли использовать NetTcpBinding для использования CallBacks?

PS: я пытаюсь следовать этому примеру: http://www.codeproject.com/KB/WCF/WCFWPFChat.aspx

Edit: Контракт:

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

1 Ответ

4 голосов
/ 04 января 2011

Ваша трассировка стека содержит ссылку на «HostedAspNetEnvironment», которая указывает на то, что это веб-проект, который будет размещаться в IIS или на встроенном сервере разработки. Это ограничит вас HTTP / HTTPS. Вы захотите взглянуть на один из следующих вариантов:

  • Самостоятельный хостинг - написание автономной консоли или приложения WinForms, которое создаст ServiceHost для размещения вашей службы WCF.
  • Служба Windows - то же самое, что и собственный хостинг, но работает внутри управляемой службы Windows. Это выгодно, поскольку вы можете запустить службу на сервере, где никто не вошел в систему, и воспользоваться преимуществами функции автоматического перезапуска сервера Windows.
  • Служба активации процессов Windows (WAS) - у меня нет особого опыта в этом, но, похоже, это урезанная версия IIS без ограничения, что службы должны использовать HTTP / HTTPS.

См. Обзор ваших вариантов здесь: http://msdn.microsoft.com/en-us/library/ms730158.aspx

...