1

NetTcpBinding を使用して、プレゼンス情報 (ユーザー、ログイン、ログアウトなど) を提供するコールバックを備えた非常に小さなサービスを WCF4 で開発したいと考えています。

私の開発マシンは、IIS がインストールされていない Visual Studio 2010 を搭載した Windows 7 64 Es です。

サービスを作成するために、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 開発サーバーが開始されましたが、次の例外がスローされました。

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 を使用してサービスをデバッグすることは可能ですか?

CallBacks を使用するには、NetTcpBinding を使用する必要がありますか?

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

1 に答える 1

4

スタック トレースには、「HostedAspNetEnvironment」への参照が含まれています。これは、これが IIS または組み込みの開発サーバーによってホストされる Web プロジェクトであることを示唆しています。これにより、HTTP/HTTPS に制限されます。次のオプションのいずれかを検討する必要があります。

  • 自己ホスティング - ServiceHost を構築して WCF サービスをホストするスタンドアロン コンソールまたは WinForms アプリケーションを作成します。
  • Windows サービス - セルフホスティングと同じですが、マネージド Windows サービス内で実行されます。これは、誰もログインしていないサーバーでサービスを実行し、Windows の自動サーバー再起動機能を利用できるため有利です。
  • Windows プロセス アクティベーション サービス (WAS) - これについてはあまり経験がありませんが、サービスが HTTP/HTTPS を使用しなければならないという制限がなく、IIS の簡易バージョンのようです。

ここでオプションの概要を参照してください: http://msdn.microsoft.com/en-us/library/ms730158.aspx

于 2011-01-04T14:43:50.533 に答える