2011-06-22 10 views
0

私は1日前にこれをグーグルで探していて、答えを見つけられないようです。誰かがこのことを明らかにすることを願っています。私は、クライアント側とサーバー側の両方でコンソールアプリケーションを使用して、単純なWCFクライアント - サーバーコールバックを実装しようとしています。サーバー上で操作が実行され、クライアント上でコールバックが実行されない点を除いて、すべて正常に動作しているようです。私。それは "コールバックコール!!!"と決して書き込まれず、コールバックに置かれたブレークポイントは決してトリップしません。クライアントは単に「完了」と書いています。ユーザーの入力を待ちます。WCFコールバックが実行されていません

私はそれが何か簡単だと確信しています。どんな助けでも大歓迎です。ありがとう!

//SERVER CODE: 
namespace NodeServiceLib 
{ 
    public interface ISomeCallbackContract 
    { 
     [OperationContract] 
     void OnCallback(); 
    } 

    [ServiceContract(CallbackContract = typeof(ISomeCallbackContract))] 
    public interface IMyContract 
    { 
     [OperationContract] 
     void DoSomething(); 
    } 

    public class NodeService : IMyContract 
    { 
     public void DoSomething() 
     { 
      Console.WriteLine("I'm doing something!!!"); 
     } 
    } 
} 

<configuration> 
    <system.web> 
    <compilation debug="true"/> 
    </system.web> 
    <!-- When deploying the service library project, the content of the config file must be added to the host's 
    app.config file. System.Configuration does not support config files for libraries. --> 
    <system.serviceModel> 
    <bindings/> 
    <services> 
     <service name="NodeServiceLib.NodeService" behaviorConfiguration="MEX"> 
     <host> 
      <baseAddresses> 
      <add baseAddress="http://localhost:8000/Node" /> 
      <add baseAddress="net.tcp://localhost:8001/Node" /> 
      </baseAddresses> 
     </host> 
     <endpoint 
      address="MyContract" 
      binding="netTcpBinding" 
      contract="NodeServiceLib.IMyContract" 
     /> 
     <endpoint 
      address="MEX" 
      binding="mexHttpBinding" 
      contract="IMetadataExchange" 
     /> 
     </service> 
    </services> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior name="MEXGET"> 
      <!-- 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> 
     <behavior name="MEX"> 
      <serviceMetadata/> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    </system.serviceModel> 

<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup</configuration> 



//CLIENT CODE: 
namespace TestConsole 
{ 
    [CallbackBehavior(ConcurrencyMode = ConcurrencyMode.Reentrant)] 
    class Callback : NodeServices.IMyContractCallback 
    { 
     public void OnCallback() 
     { 
      Console.WriteLine("Callback called!!!"); 
     } 
    } 

    class Program 
    { 
     static void Main(string[] args) 
     { 
      System.Threading.Thread.Sleep(5000); // Give server time to spin up 

      Console.WriteLine("=== CLIENT ==="); 

      InstanceContext context = new InstanceContext(new Callback()); 
      NodeServices.MyContractClient proxy = new NodeServices.MyContractClient(context); 
      proxy.DoSomething(); 
      Console.WriteLine("Done."); 
      Console.ReadLine(); 
     } 
    } 
} 

答えて

2

サーバーのDoSomethingメソッドでコールバックメソッドを呼び出すべきではありませんか?

+0

ええ、それは明らかだと思いますが、私が行っている例では、並行モードを無効にしない限り、WCFによって自動的に行われたように見えます。振り返ってみると、solu5tionは簡単だった:サービス定義に [ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Reentrant)] を加え、次いで ます。public void doSomethingの(){ Console.WriteLineを( "私は何かをやっています!!! "); ISomeCallbackContractコールバック= OperationContext.Current.GetCallbackChannel (); callback.OnCallback(); } ありがとうございます。 – hdt

関連する問題