2012-02-21 13 views
0

メトロアプリケーションでTcpTransportBindingElementとのデュプレックス通信が機能しない理由を教えてください。メトロアプリケーションでデュプレックスWCF通信が動作しない

thisドキュメント.Net FrameworkのメトロサブセットはTCPバインディングをサポートしています。

私はコンソールアプリケーションとしてWCFサーバーを書いていました。ここではソースコードは次のとおりです。

static void Main() 
{ 
    UiWcfSession.OnInitialize += ClientInitialize; 

    var baseAddresses = new Uri("net.tcp://localhost:9000/"); 

    var host = new ServiceHost(typeof(UiWcfSession), baseAddresses); 

    var reliableSession = new ReliableSessionBindingElement { Ordered = true, InactivityTimeout = TimeSpan.MaxValue }; 
    var binding = 
     new CustomBinding(reliableSession, new TcpTransportBindingElement()) { ReceiveTimeout = TimeSpan.MaxValue }; 

    host.AddServiceEndpoint(typeof(IClientFulfillmentPipeService), binding, ""); 

    var metadataBehavior = new ServiceMetadataBehavior(); 
    host.Description.Behaviors.Add(metadataBehavior); 
    var mexBinding = MetadataExchangeBindings.CreateMexTcpBinding(); 
    host.AddServiceEndpoint(typeof(IMetadataExchange), mexBinding, "mex"); 

    host.Open(); 

    Thread.CurrentThread.Join(); 
} 

private static void ClientInitialize(int uiprocessid, string key) 
{ 
    Debug.WriteLine("ClientInitialize"); 
} 

、ここでは、クライアントコードは、メトロアプリである:

partial class MainPage 
{ 
    public MainPage() 
    { 
     InitializeComponent(); 
    } 

    private void onclick(object sender, RoutedEventArgs e) 
    { 
     try 
     { 
      var ep = new EndpointAddress("net.tcp://localhost:9000/"); 
      var binding = new CustomBinding(new TcpTransportBindingElement()); 
      var ctx = new InstanceContext(new Wrapper()); 
      var pipeFactory = new DuplexChannelFactory<IClientFulfillmentPipeService>(ctx, binding, ep); 
      IClientFulfillmentPipeService commChannel = pipeFactory.CreateChannel(); 

      // open up the the comm channel with a reasonable timeout... 
      ((IChannel)commChannel).Open(); 

      commChannel.Initialize(1234, "Test"); 

      ((IChannel)commChannel).Close(); 
     } 
     catch (Exception ex) 
     { 
      Debug.WriteLine(ex.Message); 
     } 
    } 
} 

だから、ちょっと作品を。しかし、私がMetroアプリケーションのデバッガでステップバイステップで歩いていると、関数がハングして返ってくることはありませんcommChannel.Initialize

どうしてですか?私は何が欠けていますか?

答えて

0

私はMetroで同期クライアントを使用できません。私は非同期呼び出しを使用する必要があります。それがうまくいかない理由です。

関連する問題